aspose file tools*
The moose likes Tomcat and the fly likes Servlet thread pool management with JMX Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Servlet thread pool management with JMX" Watch "Servlet thread pool management with JMX" New topic
Author

Servlet thread pool management with JMX

Joshua Fix
Ranch Hand

Joined: Sep 18, 2007
Posts: 57
Servlet containers let you set the maximum thread pool size for all servlets residing in them. I have serveral servlets running in a container, but I want to ensure that each servlet only gets a certain percentage of the maximum thread pool... in other words, if my servlet container has a thread pool of 600 and I have 3 servlets, I want to ensure that each servlet is only capable of grabbing 200 threads. Is it possible to use JMX to manage and even reallocate on the fly how many threads a single servlet in a container is allowed to have?


SCJP 5.0
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

There is nothing in the spec for this so it would be container specific.
Which one are you using?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Joshua Fix
Ranch Hand

Joined: Sep 18, 2007
Posts: 57
SJSAS 9.1 and Tomcat 5.5.

Each servlet represents a service. Each individual service is susceptible to sudden increases in traffic loads and I need the ability to dynamically limit the number of resources/threads that other services in the container are allowed to consume. The clients (commercial products that I have no control over) are also very prone to over-requesting, so it's currently possible for a single person to accidentally consume a very large number of threads. I'd like to ensure that if one service is suffering the equivalent of a denial of service attack, the other services in the container are not affected.

Are you saying that JMX is not capable of this?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Joshua Fix:

Are you saying that JMX is not capable of this?


I'm not.
I'm saying that there is nothing in the servlet spec about this.
I don't know if this type of control is exposed to JMX from within Tomcat but I'll move this thread to our Tomcat forum for you.
Someone there might.

-Ben
Joshua Fix
Ranch Hand

Joined: Sep 18, 2007
Posts: 57
Maybe this is going to require a little more craftiness on the container side than I imagined... I've come to learn that it's not possible and doesn't make sense to limit the number of threads allowed per servlet, so I'd like to re-define my problem.

Can JMX (or any other technology) help me manage the total number of sessions allowed per web application if I have multiple web applications running in a single container? It just so happens that in my situation, I will treat a single servlet as a complete web application.

All of the configuration and management options I see affect the entire container, but I really need to control how those resources that belong to the container are shared amongst the web apps that reside in the container.
[ May 14, 2008: Message edited by: Joshua Fix ]
Joshua Fix
Ranch Hand

Joined: Sep 18, 2007
Posts: 57
Here was the solution I implemented:

I specified the use of the org.apache.catalina.session.StandardManager in my context.xml file, which allows me to set an attribute for maxActiveSessions.

http://tomcat.apache.org/tomcat-6.0-doc/config/manager.html

I then use the http jmx interface for tomcat management to change the value at will for any specific web app on the server:

http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html

I wrote a JSP/servlet that will allow me to specify a server, username, and password, connect to the jmxproxy page, scrape the page for all of the web applications and associated attributes, then display them and provide forms to modify each attribute.

The only thing I still haven't resolved, which is very frustrating, is that the maxInactiveInterval attribute in the StandardManager has no effect when entered in the context.xml file. The session-timeout element in the web.xml file is what tomcat will use. The problem is that the value in web.xml is in minutes, with the lowest possible value of 1. I want to invalidate my sessions immediately after the request, so 1 minute is too long. The only way I can find to do this is a) programamtticaly through the HttpSession object which accepts a value in seconds and overrides the web.xml value, or b) through the JMX manager application that I just wrote.

Cheers
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet thread pool management with JMX