1. Memory Settings
In the Windows environment, modify the "%tomcat_home%\bin\catalina.bat" file to add the following settings at the beginning of the file:Set java_opts=-xms256m-xmx512m-xx:permsize=128m-xx:maxnewsize=256m-xx:maxpermsize=256m
-XMS Setting the initial memory size
-XMX setting the maximum memory that can be used
-XMN: Minimum memory value,-xmn128-256m is enough
The initial memory allocated by the JVM is specified by-XMS, the default is physical memory 1/64;JVM the maximum allocated memory is specified by-XMX, which defaults to 1/4 of the physical memory. When the default free heap memory is less than 40%, the JVM increases the heap until the maximum limit of-xmx, and when the free heap memory is greater than 70%, the JVM reduces the heap until the minimum limit of-XMS. So the server generally sets-xms,-xmx equal to avoid resizing the heap after each GC.
In larger application projects, the default memory is not sufficient and may cause the system to fail to run. A common problem is to report a Tomcat memory overflow error "Java.lang.OutOfMemoryError:Java Heap Space, which causes the client to display a 500 error.
-xx:permsize=128m
-xx:maxpermsize=256m, default is 32M
Permsize/maxpermsize: Defines the size of the perm segment, permsize the memory size perm when the JVM starts, and maxpermsize the maximum amount of perm memory that can be occupied.
PermGen space is the full name of permanent Generation space, refers to the memory of the permanent storage area, this block of memory is mainly stored by the JVM class and meta information, class is loader will be placed in PermGen Space, unlike the heap area where the class instance (Instance) is stored, the GC (garbage Collection) does not clean up permgen space during the main program run time, so if you have a class in your application, you are likely to appear "Java.lang.OutOfMemoryError:PermGen SpaceError
For Web projects, when the JVM loads classes, objects in the permanent domain increase dramatically, allowing the JVM to constantly adjust the permanent domain size, and to avoid adjustments, you can use more parameter configurations. If your web app uses a large number of third-party jars that are larger than the JVM's default size, this error message will be generated.
-xx:newsize, default is 2M, this value is set to large adjustable Da object area, reduce the number of full GC
-xx:maxnewsize,default is 16M
-xx:newratio, default is 8
-xx:survivorratio=newratiosize
-XX:USERPARNEWGC can be used to set up parallel collection "multi-CPU"
-xx:parallelgcthreads can be used to increase the degree of parallelism "multi-CPU"
-XXUSEPARALLELGC can be set to use parallel purge collector "multi-CPU"
Memory consists of Perm and Heap. which
Heap = {old + young = {Eden, from, to}}
-xx:newratio: Change the size ratio of the old and new space, the default value of this ratio is 8, meaning that the new space size is 1/8 of the old space.
-xx:survivorratio: Changing the size ratio of the Eden object space and the remaining space, the default value of this ratio is 10, meaning that the size of the Eden object space is survivorratio+2 times larger than the remaining space.
Example: The following command sets the entire heap to 128m, the new domain ratio is set to 3, that is, the new domain is proportional to the old domain 1:3, and the new domain is 1/4 or 32M of the heap:
Java–xms128m–xmx128m–xx:newratio =3
If you do not execute startup.bat to start Tomcat but use Windows system services to start the Tomcat service, the settings above will not take effect. Workaround:
Modify the registry Hkey_local_machine\software\apache software Foundation\procrun 2.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
Join-XMS256M-XMX512M, restart Tomcat service, set to take effect
The Linux environment modifies the "%tomcat_home%\bin\catalina.sh" file, adding the following settings at the beginning of the file: java_opts= '-xms256m-xmx512m '
2. Concurrency number setting
The default tomcat configuration, when concurrent testing, may be 30 user up on the machine.
Add to
<connector port= "protocol=" http/1.1 "
maxthreads= "600"
minsparethreads= "100"
Maxsparethreads= "500"
Acceptcount= "The "
connectiontimeout= "20000"
redirectport= "8443"/>
Description
maxthreads= "600"///maximum number of threads
minsparethreads= "100"///number of threads created when initializing
maxsparethreads= "500"///Once you create a thread that exceeds this value, Tomcat shuts down the socket thread that is no longer needed.
Acceptcount= "700"//Specifies the number of requests that can be placed in the processing queue when all the threads that can be used to process the request are used, and requests that exceed this number will not be processed
Maxthread too much, resulting in excessive switching and severe performance degradation. This quantity should be the load-carrying capacity of your individual machine and the result of the stress test. Do not increase arbitrarily. In general, 256-512 are already very high values.
Reference Documents
1. I am in the Linux system under the Web system. http://www.iteye.com/topic/299988
2.Tomcate boot memory settings. http://blog.csdn.net/peijunlin/archive/2009/06/05/4244401.aspx
3.tomcat6 Some tuning sets the number of memory and connections. http://mcncc.com/simple/?t25909.html
4.Java Virtual machine parameter-xx and other related parameters application. http://hi.baidu.com/charlesyy/blog/item/b89b5dee30cfdaf9b2fb95d5.html/cmtid/dda586260800bf1a8b82a173
Original address:
Http://blog.chinaunix.net/uid-122937-id-201606.html
TOMCAT6 Performance Optimization