Like GlassFish, out of the box, Tomcat comes configured for use in a development environment. You will see many of the same limitations as Glassfish when considering production use:
- Tomcat will be running in development mode (which incurs an overhead in checking to see if code has changed)
- If you have more than 1 CPU, you will not be taking advantage of it
- Tomcat will only assign 512m of ram to the JVM (and ORDS), even if you have more available
- Logging will be set to FINE and INFO, adding a logging burden to Tomcat
- You are in danger of timing out on large file uploads
Setting the Scene
Configuration File: $CATALINA_HOME/conf/logging.properties
Change all occurrences of FINE and INFO to SEVERE
To pass JVM options to Tomcat on startup, you should create a new file called $CATALINA_HOME/bin/setenv.sh
Add the following values:
export CATALINA_OPTS="$CATALINA_OPTS -Xms1536m"
export CATALINA_OPTS="$CATALINA_OPTS -Xmx1536m"
export CATALINA_OPTS="$CATALINA_OPTS -server"
Note: If you are running JDK7, you can also set PermSize and MaxPermSize. Note: PermSize and MaxPermSize not applicable for Java 8.
export CATALINA_OPTS="$CATALINA_OPTS -XX:PermSize=256m"
export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=256m"
Main Tomcat Server Configurations
We are going to be configuring Tomcat on Port 8080.
Configuration File: $CATALINA_HOME/conf/server.xml
Add the following under the Catalina Service:
- acceptorThreadCount - The number of threads to be used to accept connections. Increase this value on a multi CPU Core machine.
- acceptCount - The 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. Set to 10 to protect server from getting overloaded.
- maxConnections - The maximum number of connections that the server will accept at any given time. When this number has been reached, the server will accept, but not process, one further connection. Connections are passed on to available threads to perform the actual work.
- maxThreads - The maximum number of request processing threads to be created by a connector, which therefore determines the maximum number of simultaneous requests that can be handled.
- minSpareThreads - The minimum number of threads always kept running waiting for new requests.
- connectionTimeout - The number of milliseconds a connector will wait, after accepting a connection, for the request URI line to be presented.
- disableUploadTimeout - Set to false and use the value in connectionUploadTimeout as the upload timeout.
- connectionUploadTimeout - Specifies the timeout, in milliseconds, to use while a data upload is in progress. This only takes effect ifdisableUploadTimeout is set to false.
Note: The threads described above do not impact JDBC connection pooling, which ORDS is handling for us. ORDS is protecting (or throttling) the JDBC connections Tomcat is organizing the web connections. If we assume the MaxLimit JDBC connection setting in ORDS is 50 then we have a healthy overhead of connections over to queue any users we have over 50.