Growing and Shrinking Tomcat Workers in the Cloud

Introduction
As part of our Cloud Apache Tomcat Series of articles, I have
put together a small tutorial to guide people on how to disable, enable, and stopped workers at run time.

What you need to know?
If you are an apache tomcat administrator or avid user, you will probably find this article useful. Also if you have setup tomcat as a load balancer with apache mod_jk module in the past this journal entry will be helpful.

Purpose
Basically the main topic here is how to change a worker variables at run time using the mod_jk status manager api.

Let’s see. In our previous post we show an example on how to setup an apache load balancer with three tomcat workers using mod_jk apache module. You can find this in our post here.

The first step is to make sure you have the jkmanager api enabled within apache load balancer. The apache load balancer is responsible on sending request to each tomcat worker, the ultimate goal is to tell the balancer device or devices that we are going to disable, enable or stop a worker. Enabling us to modify that worker in any way even restarting it or shuting down completely.

In order for us to enable the jkmanager module in the apache load balancer we need to have the following lines in our httpd.conf file:


JkMount jkstatus
 order deny,allow
 allow from your.ip.add.ress
 allow from 127.0.0.1
 deny from all
...
JkMount  /jkmanager/* jkstatus
...

The workers.properties file is the place where you tell the load balancer how is configured. The changes on the “workers.properties” file are:

worker.list=router,tomcat1,tomcat2,...,tomcatn,jkstatus
worker.jkstatus.type=status

Now that you have setup a worker called jkstatus mounted in httpd.conf file in jkmanager location when you hit via a browser the url http://your.web.server/jkmanager/ you should find a management console for your load balancer and all your workers. Now let’s get to business.

If you want to disable worker one at the load balancer you need to query the following url:

http://your.web.server/jkmanager/?cmd=update&w=router&opt=256&from=list&att=vwa&val0=1&val1=0&val2=0

If you want to enable all workers again to start accepting new requests you need to query the following url:

http://your.web.server/jkmanager/?cmd=update&w=router&opt=256&from=list&att=vwa&val0=0&val1=0&val2=0

In the mist of implementing this solution for my company, I posted a question in the StackOverflow forum that lead me to the answer. The following link is the answer posted by me to my question (kind of ironic) but this website is super helpful. A very helpful link to build more of the urls to execute actions in the load balancer is the tomcat reference official page.

What to do with this knowledge?
Now that you know how to automatically disable, enable, and stop workers, you are able to create an array of servers ready to use in Amazon EC2, GoGrid, or even in your private cloud. Disable or pause the servers that you don’t need immediately and bring execute the urls to enabled them with wget or any other command line execution web execution program.

If you have questions or you are not clear about something feel free to comment here or send me an email. Thanks for your continues support and happy clouding….

Tags: ,

5 Responses to “Growing and Shrinking Tomcat Workers in the Cloud”

  1. Mike March 9, 2011 at 5:19 pm #

    I will twist your idea a little and make my own application to handle this. Thanks for the seed. Mike

  2. Tom A April 18, 2011 at 10:13 am #

    Your disable and enable URLs have semicolons after the ampersands in the query string. Am i right to assume that’s a mistake?

  3. gkiragiannis April 19, 2011 at 6:16 pm #

    @Tom. You are right. Apparently when I transferred my blog from blogger, those were corrupted. Thanks for the catch.

    Geo

  4. mikaso July 8, 2011 at 6:13 am #

    Hi! I followed your instructions but something wiered is happening with JK Status Manager. I use Apache/2.2.3 (CentOS) Server, mod_jk 1.2.31 and Tomcat 7.0.11.

    For example I want disable tomcat1 for maintinance. I press E link, select radio button Disable (or Stop) and press Update worker and I stiil can reach tomcat1. If I reload JK Status Manager sometimes is status disabled (stopped) and sometimes status is active. Shortly said, JK Status Manager doesn’t work properly.

    With balancer-manager from mod_proxy everthing is fine.

    Sorry for my poor English and thanks for a excellent tutorial.

    M.

  5. gkiragiannis July 11, 2011 at 5:58 pm #

    Hi Mikaso,

    It’s hard to say with the information provided.

    My first guess will be that after you click disable tomcat1 still has sessions open so it is not disabled until all sessions have been off.

    My second guess will be to check the mode you have on your balancer,

    Check the following link: http://tomcat.apache.org/connectors-doc/reference/workers.html down in the section that is labeled: method

    Let me know if that works.

    Thanks, Geo

Leave a Reply