This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
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.
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.
Joined: Sep 18, 2007
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 ]
Joined: Sep 18, 2007
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.
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.