JVM tuning is primarily for heap memory, where heap memory is divided into: new, old, and permanent areas
The permanent zone stores the interface and class metadata of the system JDK itself, so only the new and old-age areas have optimized space.
New District: Eden Area and survivor area. All the classes were new in the Eden District, and the survivor Zone was divided into 0 and 1 districts. When the space in the Eden area is exhausted,
Garbage Collection Minor GC (that is, what we often call GC), objects that were not destroyed after GC are left to the surviving zone, and section 1 of zone 0 repeats minor GC process, eventually saving the remaining objects to
Retirement area, the old-age area full of FULLGC. If the old fullgc still full, then reported OutOfMemory Error.
Summarize three districts: frequent collection of young areas; less collection of old areas; basic fixed perm area
With these understandings, proceed to JVM tuning below. ‘
Tomcat Start-up optimization
The concurrency optimization of Tomcat
Bio default mode
Bio is the most stable and oldest connector, which is in a blocking way, meaning that each connection thread binds to each
HTTP requests until the HTTP response is returned, and if the HTTP client requests a keep-alive connection, then these
The connection may persist until the timeout time is reached and cannot be used for other requests. Poor performance but most stable
Direct is the factory default: Notice what the protocol is.
Bio Application Scenarios
For scenarios where the number of connections is small and a large amount of data is sent at a time, this is a much higher requirement for server resources and is limited to applications.
Nio
NIO is an asynchronous IO technology that uses Java, and does not cause blocking. NIO (new I/O) is a new I/O operation (i.e. the Java.nio package and its child packages) provided by Java SE1.4 and subsequent versions. Java NiO is a buffer-based, Java API that provides non-blocking I/O operations, so NiO is also considered an abbreviation for non-blocking I/O. It has better concurrency performance than traditional I/O operations (bio).
Modify the connector node in the Server.xml directly, modify the protocol to:
Protocol= "Org.apache.coyote.http11.Http11NioProtocol"
<port= "8080" protocol= " Org.apache.coyote.http11.Http11NioProtocol " maxthreads=" " minsparethreads " = "maxsparethreads " = " acceptcount"= "Max" ConnectionTimeout= "20000" redirectport= "8443"/>
NIO Application Scenario
The server needs to support an extremely large number of long-time connections . For example, 10,000 connections above, and each client does not frequently send too much data . For example, a central server in a head office needs to collect the transaction information of each register at a national convenience store, requiring only a small number of threads to handle the long-term connection of maintenance on demand.
Jetty, Mina, Netty, zookeeper, etc. are all based on the NIO method.
Tomcat in-memory optimization
Tomcat can use 128MB of memory by default, and in larger applications, this memory is not enough and may cause the system to fail to run.
A common problem is to report a Tomcat memory overflow error, an out of memory (system-out-of-low) exception, which causes the client to display a 500 error,
General tuning of Tomcat's use of memory solves this problem.
"%tomcat_home%\bin\catalina.sh" file, add the following settings at the beginning of the file:
java_opts=-xms2048m-xmx2048m
XMX is used to set the maximum amount of memory your application can use, and if the program is going to take a lot of memory, you need to modify the value to increase this number.
XMS is used to set the program initialization when the memory stack size, increase this value, your program's startup performance will be improved.
XMS is set to be the same as XMX, avoiding the need to reallocate memory each time garbage collection.
Common tuning strategies and garbage collection algorithms for JVMs and common tuning parameters for tomcat