Performance Tuning the JVM for Running Tomcat
First, Mikusa walks us through the key configuration options we need to understand while performance tuning the JVM:
- -Xms and ?Xmx. Used to define the size of the heap used by the JVM, -Xms sets the initial size of the heap and -Xmx sets the maximum size of the heap. Specific values depend on the application.For Tomcat, it is recommended that ?xms and ?xmx be set to the same value. Referred to as a fully committed heap, this will instruct the JVM to create a heap that is initially at its maximum size and prevent several full garbage collections from occurring as the heap expands to its maximum size. Remember, max heap equals 4 or 5 times the minimum heap.
- -XX:PermSize and -XX:MaxPermSize. Used to define the size of the permanent generation space,it is also recommended that these be set to the same value. This will instruct the JVM to create the permanent generation so that it is initially at its maximum size and prevent possible full garbage collections from occurring as the permanent generation expands to its maximum size.
- -Xss. Used to define the size of the stack for each thread in the JVM. The optimum value varies across applications however, in most cases, the default value used by the JVM is too large. Try lowering the value, starting with 128k, saving memory and increasing the number of threads that can be run on a system. Run Tomcat and look for a StackOverFlow exception in the logs. If you see the exception, then gradually increase the value and restart Tomcat. When the exceptions disappear, you have found the minimal value which works for your deployment.
- -server. Used to select the Java HotSpot Server VM when running 32-bit Windows. This will instruct the VM that it is running in a server environment and the default configurations will be changed accordingly. 32-bit Solaris and 32-bit Linux installations with two or more CPU's and 2GB or more of RAM will enable this option by default. In addition, all 64-bit OS's have this option enabled by default as there is no 64-bit client VM.