Tomcat6 performance optimization

1. Memory settings

        Modify the "%TOMCAT_HOME%\bin\catalina.bat" file in Windows environment, and add the following settings at the beginning of the file:
set JAVA_OPTS=-Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:MaxPermSize=256m

quote
      -Xms sets the initial memory size
      -Xmx sets the maximum memory that can be used
      -Xmn: the minimum memory value, -Xmn128-256m is enough


        The memory initially allocated by the JVM is specified by -Xms, and the default is 1/64 of the physical memory; the maximum allocated memory by the JVM is specified by -Xmx, and the default is 1/4 of the physical memory. When the default free heap memory is less than 40%, the JVM will increase the heap until the maximum limit of -Xmx; when the free heap memory is greater than 70%, the JVM will reduce the heap until the minimum limit of -Xms. Therefore, the server generally sets -Xms, -Xmx equal to avoid adjusting the size of the heap after each GC.

        In larger application projects, the default memory is not enough, which may cause the system to fail. A common problem is that the Tomcat memory overflow error "java.lang.OutOfMemoryError: Java heap space" is reported, which causes the client to display a 500 error.
quote
      -XX:PermSize=128M
      -XX:MaxPermSize=256m//The default is 32M


        PermSize/MaxPermSize: Define the size of the Perm segment, PermSize is the memory size of the Perm when the JVM starts; MaxPermSize is the maximum occupied Perm memory size.

        The full name of PermGen space is Permanent Generation space, 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 PermGen space, which is the same as the storage class instance. The Heap area of ​​(Instance) is different, GC (Garbage Collection) will not clean up the PermGen space during the main program runtime, so if your application has a lot of CLASS, it is likely to appear "java.lang.OutOfMemoryError: PermGen space "mistake.

        For WEB projects, when jvm loads classes, the objects in the permanent domain increase sharply, so that the jvm continuously adjusts the size of the permanent domain, in order to avoid adjustment), you can use more parameter configuration. If your WEB APP uses a large number of third-party jars, the size of which exceeds the default size of jvm, then this error message will be generated.

quote
      -XX:NewSize, the default is 2M, this value can be set to a larger size and the new object area can be increased to reduce the number of Full GCs
      -XX:MaxNewSize, the default is 16M
      -XX:NewRatio, the default is 8
      -XX:SurvivorRatio=NewRatioSize
      -XX:userParNewGC Can be used to set parallel collection [multiple CPUs]
      -XX:ParallelGCThreads can be used to increase the degree of parallelism [multiple CPUs]
      -XXUseParallelGC After setting, you can use parallel clear collectors [multiple CPUs]


        Memory consists of Perm and Heap. Among them
quote
        Heap = {Old + young = { Eden , from, to } }
        -XX:NewRatio: Change the size ratio of the new and old spaces. The default value of this ratio is 8, which means that the size of the new space is 1/8 of the old space.
        -XX:SurvivorRatio: Change the size ratio of the Eden object space and the survivor space. The default value of this ratio is 10, which means that the size of the Eden object space is larger than the survivor space by survivorRatio+2 times.

        Example: The following command sets the entire heap to 128m, and the new domain ratio to 3, that is, the ratio of the new domain to the old domain is 1:3, and the new domain is 1/4 of the heap or 32M:
java –Xms128m –Xmx128m –XX:NewRatio =3


        If you do not execute startup.bat to start tomcat but use the windows system service to start the tomcat service, the above settings will not take effect. Solution:

        Modify the registry
HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Procrun2.0\Tomcat6\Parameters\JavaOptions

        The original value is
-Dcatalina.home=E:\Tomcat 6.0
-Dcatalina.base=E:\Tomcat 6.0
-Djava.endorsed.dirs=E:\Tomcat 6.0\common\endorsed
-Djava.io.tmpdir=E:\Tomcat 6.0\temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=E:\Tomcat 6.0\conf\logging.properties

        Add -Xms256m -Xmx512m, restart the tomcat service, and the settings will take effect

        . Modify the "%TOMCAT_HOME%\bin\catalina.sh" file in the Linux environment, and add the following settings at the beginning of the file: JAVA_OPTS='-Xms256m -Xmx512m'

2. Concurrency setting

        The default tomcat configuration, when testing concurrently, may crash when 30 USER goes up.
        Add to
   
<Connector port="80" protocol="HTTP/1.1"
             maxThreads="600"
             minSpareThreads="100"
             maxSpareThreads="500"
             acceptCount="700"
            connectionTimeout="20000"
            redirectPort="8443" />

        illustrate
quote
       maxThreads="600" ///Maximum number of threads
       minSpareThreads="100"///Number of threads created during initialization
       maxSpareThreads="500"///Once the number of threads created exceeds this value, Tomcat will close sockets that are no longer needed thread.
       acceptCount="700"//Specify the number of requests that can be placed in the processing queue when all available threads for processing requests are used, and requests that exceed this number will not be processed


         There are too many maxthreads, resulting in too many switching and serious performance degradation. This number should be the carrying capacity of your single machine, the result obtained under the stress test. It cannot be increased arbitrarily. Under normal circumstances, 256-512 are already very high values.

        Reprinted: http://blog.chinaunix.net/uid-122937-id-201606.html

Guess you like

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