Tomcat 7 request processing threading architecture and performance tuning
Tomcat has many parameters for performance tuning (see http://tomcat.apache.org/tomcat-7.0-doc/config/http.html), but for some attribute descriptions it is not a 100% clear how some properties affect each other.
A pretty good explanation regarding acceptCount and maxThreads can be found here: http://techblog.netflix.com/2015/07/tuning-tomcat-for-high-throughput-fail.html
But that article is missing a ... picture! That's what I tried to create here, with the numbers 1-5 indicating the steps described in the above article:
Just in case should the Netflix URL ever get lost and for easy reference, here's the 5 steps:
The Tomcat attribute maxThreads worked best in my case with value 50, as it won't saturate the machine/CPU. (due to too many workerthreads, many context-switches)
To set maxThreads when using Spring Boot + embedded Tomcat: http://stackoverflow.com/questions/31432514/how-to-modify-tomcat8-acceptcount-in-spring-boot
Other remarks
- Could not get acceptCount set via Spring Boot + embedded tomcat.... Tried by configuring my own embedded Tomcat container (e.g as in here and here):
connector.setAttribute("acceptCount", acceptCount); - This was for a pure Tomcat setup, no Apache webserver in front of it.
- Special care when providing your own executor, see a.o: https://www.packtpub.com/books/content/overview-tomcat-6-servlet-container-part-2
- Performance monitoring & profiling was done with tools like: JVisualVm, Java Mission Control (JMC + Java Flight Recorder), JProfiler.
Referenced material
- http://tomcat.10.x6.nabble.com/Tomcat-does-not-honor-acceptCount-configuration-variable-td2159508.html
- https://www.packtpub.com/books/content/overview-tomcat-6-servlet-container-part-1
- https://www.mulesoft.com/tcat/tomcat-connectors
- https://javamaster.wordpress.com/2013/03/13/apache-tomcat-tuning-guide/
- https://papweb.wordpress.com/2010/10/30/understanding-tomcat-executor-thread-pooling/
- Useful calculation that also shows just increasing maxThreads doesn't mean performance will get better: http://stackoverflow.com/questions/12600826/increase-number-of-concurrent-connections-in-tomcat-7
- Some more tuning tips: http://www.genericarticles.com/mediawiki/index.php?title=How_to_optimize_tomcat_performance_in_production
- Extra explanation of the attributes, also why certain NIO/BIO settings are recommended: http://stackoverflow.com/questions/25356703/tomcat-connector-architecture-thread-pools-and-async-servlets
- To disable/replace the default connector: http://stackoverflow.com/questions/28050354/spring-boot-replace-default-embedded-tomcat-connector
- Did not find the thread architecture at this obvious place, or any other search: http://tomcat.apache.org/tomcat-7.0-doc/architecture/requestProcess.html
- Similar diagram but for a webserver; none-the-less interesting diagram: http://www3.nd.edu/~dthain/courses/cse30341/spring2009/project4/pool.gif
1 comment:
This post was very useful. Thanks for posting.
PS: per my understanding, the worker thread sends the response to the client. Is that right? May be it is useful to show in the diagram as step 6 the response from worker thread to the client.
Post a Comment