tomcat performance optimization

• -server: Enable the server version of jdk.
• -Xms: Minimum heap memory for virtual machine initialization.
• -Xmx: Maximum heap memory that the virtual machine can use. #-Xms and -Xmx are set to the same value to avoid JVM performance fluctuations due to frequent GC
• -XX:PermSize: Set the initial value of non-heap memory, the default is 1/64 of the physical memory.
• -XX:MaxNewSize: The maximum value of the entire heap memory for the new generation.
• -XX:MaxPermSize: Perm (commonly known as method area) occupies the maximum value of the entire heap memory, also known as the largest permanent reserved area of ​​memory.


1) Error message: java.lang.OutOfMemoryError: Java heap space   (heap) overflow

The default memory that Tomcat can use is 128MB. In larger application projects, this memory is not enough, which may cause the system to fail to run. The common problem is to report Tomcat memory overflow error and Outof Memory (insufficient system memory) exception, which causes the client to display a 500 error. Generally, adjusting Tomcat's -Xms and -Xmx can solve the problem, usually set -Xms and -Xmx In the same way, the maximum heap size is set to 80% of the maximum physical available memory.

set JAVA_OPTS=-Xms512m-Xmx512m

2) Error message: java.lang.OutOfMemoryError: PermGenspace   ----  PermGen space overflow. 

The full name of PermGenspace is Permanent Generationspace, which refers to the permanent storage area of ​​memory. This memory is mainly used by JVM to store Class and Meta information. When Class is loaded by Loader, it will be placed in PermGenspace, which is the same as the storage class instance (Instance) The Heap area is different, GC (Garbage Collection) will not clean up the PermGenspace during the main program runtime, so if your application has a lot of CLASS, it is likely to have a PermGen space error, which is common in the web server for JSP When doing precompile. If your WEB APP uses a large number of third-party jars, the size of which exceeds the default size of jvm (4M), then this error message will be generated. Solution:

Manually set the MaxPermSize size    setJAVA_OPTS=-XX:PermSize=128M

 

3.  java.lang.StackOverflowError    ---- The stack overflows
. The JVM still uses a stack-based virtual machine, which is the same as C and Pascal. The calling process of the function is reflected in the stack and pop-off stack.
There are so many "layers" of calling constructors that the stack overflows.
Generally speaking, the general stack area is much smaller than the heap area, because the function call process is often not more than a thousand layers, and even if each function call requires 1K space (this is approximately equivalent to declaring 256 in a C function). variable of type int), then the stack area only needs 1MB of space. Usually the stack size is 1-2MB.
Usually recursion should not have too many levels of recursion, it is easy to overflow.

Solution: Modify the program.

Reference article: https://blog.csdn.net/wh211212/article/details/52732920?locationNum=10

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325979137&siteId=291194637