Detailed + Tomcat JVM virtual machine performance optimization

1.JVM(java virtual mechinal)

( . 1 ) the JVM sound hardware architecture, such as processors, stacks, registers as, also with the corresponding instruction. 

( 2 explained) when the main work of the JVM own instruction set (i.e., byte code), and mapped to a set of instructions cpu local or OS system call.

2.JVM virtual machine main heap, stack, native method stacks, consisting of area method

Note :( a data structure) is a kind of the heap and stack data items in sequence, only insert and delete data items at one end. 

  ( 2 ) in microcontroller applications, the stack is a special storage area, the main function is to temporarily store data and addresses, and an endpoint field is generally used to protect. 

  ( 3 ) stack, queue FIFO. 

  ( 4 ) stack, last out.

(1) Heap

1 ) All new new object by which the memory allocated in the heap, the heap size may be a multi-pass -Xmx and - the Xms controlled. 

2 ) heap is divided into a new generation and the old generation. 

3 ) the new generation has been further divided into Eden and Survivor areas. 

. 4 ) a Survivor To Space From Space and composition.
1 ) the new generation, the new objects are allocated by the new generation of memory. 

2 ) When Eden insufficient space, will be transferred to the survival of the object in Survivor. 

3 ) may be controlled by the size of the new generation -Xmn, it can also be used -XX: SurvivorRatio to control the ratio of Eden and Survivor.
1 ) the old generation, used to store objects in the new generation after several garbage collection is still alive.
1 ) with a persistent, (Permanent Space) implementation zone, the main storage of all loaded class information, the information method, the constant pools. 

2 ) by -XX: PermSize and - XX: with initial values to specify persistent and maximum MaxPermSize. 

3 ) Permanent Space is not the same method area, just Hostspot JVM with the Permanent Space to implement the method area only. 

4 ) Some virtual machine has no Permanent Space and to implement the method area by other mechanisms.
The -Xmx     # maximum heap memory 
-Xms     # initial memory heap 
-XX: MaxNewSize     # Young maximum memory area 
-XX: NewSize     # Young area of memory initially, usually Xmx 1/3 or 1/4. 
# = Eden + 2 new generation of two Survivor spaces. 
# Actual space available = Eden + 1 th Survivor, i.e. 90%.
-XX: MaxPermSize     # Maximum lasting memory with 
-XX: PermSize         # initially lasting memory with 
-XX: + PrintGCDetails     # GC print information 
-XX: NewRation      # year old ratio and the new generation 
# Example: -XX: NewRetio = 2, then 1/3 whole new generation of heap space, with the elderly accounting for 2/3; 
-XX: SurvivorRatio     # Eden with the new generation Survivor ratio. The default is 8, i.e., Eden space representing the new generation 8/10 1/10 half and two Survivor;

(2) Stack

1 ) When each thread of execution of each method will apply a stack frame on the stack. 

2 ) Each stack frame including local variables and operand stack, the method for storing temporary variable parameters and intermediate results during the call. 

3 ) -Xss: Set each thread stack capitalized .JDK1. 5 +, each thread stack uppercase to 1M, if the stack is not very deep, 1M is sufficient.

(3) native method stacks

1 ) Support for native execution method of storing the status of each native method call.

(4) Method region

1 ) class information is stored to be loaded, a static variable, final type of constants, properties and methods information. 

2 ) to bring the JVM with persistent storage zone method, by -XX: specify the minimum and maximum values MaxPermSize: PermSize and -XX.
1 ) an ordinary java object A new generation born in the district of Eden, Eden zone when newborn objects too, will be transferred to the object A Survivor areas. 

2 ) Survivor region divided from region to region and; 

3 ) from the object A may be in the region, sometimes to the region. 

4 ) After a certain time, the object will be transferred to the old A's. 

5 ) A target reaches a certain time, it will be recovered in old's java.

  3.tomcat Performance Optimization

1 ) optimize the Linux kernel 

2 ) optimize the allocation of server resources 

3 ) parameter optimization Tomcat 

4 ) optimize the allocation of cluster load
Profile parameter optimization 
( 1 ) turn off DNS queries, configure the maximum number of concurrent; 
( 2 ) maxThreads: The number of task maximum number of threads tomcat start of that process at the same time, the default is 200; 
( 3 ) acceptCount: When the number of threads started tomcat when the maximum number of queued request acceptance, the default is 100; 
( 4 ) these values are not the better, to be adjusted according to actual situation.
<Connector port="8080"   
        protocol="org.apache.coyote.http11.Http11NioProtocol"  
           connectionTimeout="20000"  
           redirectPort="443"   
           maxThreads="5000" 
           minSpareThreads="20"  
           acceptCount="10000" 
           disableUploadTimeout="true" 
           enableLookups="false"   
           URIEncoding="UTF-8" />
# Above configuration suitable for server memory 128G 
# annotation parameters: 
Protocol = "org.apache.coyote.http11.Http11NioProtocol"   # adjustment mode Nio 
connectionTimeout = "20000"   # connection timeout, in milliseconds, 0 to not limit, the current adjustment for the 20s. 
= redirectPort "443"   # when a user http requests a resource, and the resource itself must be set up to access https, then Tomcat will be automatically redirected to the https port redirectPort settings. 
maxThreads = "5000"   more # maximum number of threads, the number of threads occupation, the more memory and CPU utilization will 
minSpareThreads = "20"   # minimum number of idle threads 
acceptCount = "10000"   # request the maximum, more than 10,000, will accept clients request, it passes the request in a queue. 
= disableUploadTimeout "to true"   # Upload Timeout Disable 
enableLookups = "to false"   # closed dns resolution, to improve the response time of 
the URIEncoding = "UTF-8"   # set the character set is UTF-8

  4.JVM parameter adjustment vim bin / catalina.sh or vim / etc / profile, the profile configuration to be added export environment

CATALINA_OPTS="$CATALINA_OPTS -Xms512M -Xmx1024M -Xmn100M -XX:SurvivorRatio=4 -XX:+UseConcMarkS
weepGC -XX:CMSInitiatingOccupancyFraction=82 -DLOCALE=UTF-16LE  -DRAMDISK=/ -DUSE_RAM_DISK=ture
 -DRAM_DISK=true -Djava.rmi.server.hostname=192.168.111.128 -Dcom.sun.management.jmxremote.port
=10000 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
-Xms <size> # represents the initialization JVM heap size: Open java program memory occupied initial opening
 -Xmx <size> # denotes the maximum value of the JVM heap: after the memory occupied by the maximum opening procedure 
       # two or more parameters according to the application needs the adjustments required, if memory exceeds the maximum xmx, generally prompts a memory overflow will cause the program to crash. 
       # Recommended -xmx This value is usually set to the current memory% 80;
 -Xmn        # indicates that the memory size of the young band, recommended setting 3/8 whole heap of memory.

 

Guess you like

Origin www.cnblogs.com/shitou-st/p/11058393.html