Monday, September 2, 2013

Tomcat performance tuning

A tomcat with default configuration can handle max 300req/sec
I was unaware of that until I had to tweak the tomcat to improve the performance of my webapp.
In this blog I am going to list few of the tomcat connector parameters which helped us in improving the tomcat performance.



acceptCountThe maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full will be refused. The default value is 100.
acceptorThreadCountThe number of threads to be used to accept connections. Increase this value on a multi CPU machine, although you would never really need more than 2. Also, with a lot of non keep alive connections, you might want to increase this value as well. Default value is 1.
maxConnectionsThe maximum number of connections that the server will accept and process at any given time. When this number has been reached, the server will not accept any more connections until the number of connections falls below this value. The operating system may still accept connections based on the acceptCount setting. Default value is the value of maxThreads
maxThreadsThe maximum number of request processing threads to be created by this Connector, which therefore determines the maximum number of simultaneous requests that can be handled. If not specified, this attribute is set to 200. If an executor is associated with this connector, this attribute is ignored as the connector will execute tasks using the executor rather than an internal thread pool.
minSpareThreadsThe minimum number of threads always kept running. If not specified, the default of 10 is used.
processorCacheThe protocol handler caches Processor objects to speed up performance. This setting dictates how many of these objects get cached. -1 means unlimited, default is 200. If not using Servlet3.0 asynchronous processing, a good default is to use the same as the maxThreads setting. If using Servlet 3.0 asynchronous processing, a good default is to use the larger of maxThreads and the maximum number of expected concurrent requests (synchronous and asynchronous).
Out of these parameters maxThreads plays a very important role. The optimal value of it varies with the response time for single request. For our project it was around 75.

Few hit and trial can easily give you a value which performs better than the default one.

After tweaking the parameters the tomcat should be tested for different load ranges to ensure that it is working as expected.

Comparing it with tomcat having default configuration gives you a very good metric to calculate the performance gain.

Sample Config in server.xml
<Connector port="8090" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" maxConnections="500" maxThreads="75" acceptorThreadCount="2"/>

Reference :

Note : The parameters mentioned are valid for tomcat version 5, 6 and 7. Future versions can modify/remove the mentioned parameters.

No comments:

Post a Comment