Most of the time we want web servers to run as fast as they can. There is one time we don't want this to be true: when there are stability issues on a back end service. For example, we're using a web service or database that crashes under load and we can't either throttle the use of this service or improve its ability to accept load.
It's better to be up and slow than up and down. To solve this problem you can detune the connector configuration in Tomcat to reduce the number of threads processing requests.
- Edit
tomcat/conf/server.xml - Find the configuration for your connector. It will be in an element named
Connector - Set the
maxThreadsattribute to a smaller value. I used 50. This limits the number of requests that will be processed simultaneously and in turn reduces down stream load. - Add an attribute for
acceptCountif it is not already defined. I set this to 1000. This is the number of requests that we will allow to wait for a thread to free up. Tomcat will drop requests once this queue is full.
Connector configuration looked like this in the end:
<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="50" minSpareThreads="20" maxSpareThreads="40"
enableLookups="false" redirectPort="8443" acceptCount="1000"
connectionTimeout="20000" disableUploadTimeout="true"
compression="on" compressionMinSize="2048" noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript,application/x-javascript,application/javascript"/>