- Use the latest supported JVM version. In general, the latest version of the JVM performs better than previous versions. We recommend using only supported major versions.
- Run your JVM in server mode. The JVM server mode will take longer to start but performs better than client mode when it is running. Use server mode for production environments and client mode for development only.
- Adjust the JVM heap size.By default, the JVM is configured to use 64MB or 128MB memory. You may adjust the heap size of the JVM application server by making more memory accessible to it.
- -Xms specifies the initial Java heap size.
- -Xmx specifies the maximum Java heap size. For example:
- In 32-bit Linux, the JVM may only be able to use up to 2GB memory.
- Do not allocate too much memory to the JVM. Make sure there is enough memory for the operating system to create native threads. If there is not enough memory, you may see exceptions such as the following:
java.lang.OutOfMemoryError: unable to create new native thread
- Monitor JVM memory usage. You can use jstat, which is included with JVM 1.7, to monitor JVM memory usage. The monitoring interval can be in milliseconds (default) or seconds.
jstat -gc <jvm_process_id> <monitoring_interval>For example:
jstat -gc 1234 5000
- Optimize garbage collection. In JVM version 1.5 and later, several types of garbage collectors are available. On a multi-CPU server, our test results show that the concurrent low pause garbage collector offers slightly better performance under stress.