Tomcat 16G memory concurrency optimization, memory configuration, garbage collection, downtime prevention

Tomcat concurrent optimization, memory configuration, garbage collection, downtime prevention
directory
 

Tomcat concurrency optimization, configuration memory, garbage collection, preventing downtime
directory
Preamble
a, Tomcat concurrent optimization
(1) tomcat complicated parameters
(2) tomcat complicated configuration
two, Tomcat memory configuration
(1) tomcat parameter memory
(2) tomcat memory configuration
three , Tomcat garbage collection
(1) Classification and management of objects in the JVM
(2) the JVM garbage collection parameters
(3) tomcat garbage collection configuration
four, Tomcat downtime prevention
(1) TCP port status
(2) TCP parameters Windows system
( 3) tomcat suspended animation analysis and prevention
V. Conclusion
 

Preamble
These days the system issues abound, server concurrency poor, tomcat memory overflow, suspended animation downtime, network congestion, and made me really uncomfortable, sleepless nights. But after expert advice, network data, coupled with the practice of running tests, the system gradually stabilized, the performance also improved a lot, apart easily, to share my experience for everyone, I hope you can gain something.

A, Tomcat concurrent optimization
tomcat concurrency is closely related to its configuration, the average amount of concurrent machine hundreds of sufficient, if set too high may lead to various problems, memory, network and other issues can be exposed at high concurrency, and therefore, the configuration setting the parameters is very important.

(1) tomcat concurrent parameters

maxThreads: Maximum number of concurrent requests, when high cpu utilization, not to increase the number of threads, when the cpu utilization is not high, most of which are based upon blocking io operation, this value can be increased.
maxSpareThreads: The maximum number of idle threads Tomcat socket connector
acceptCount: when the maximum number of threads is reached processing task, the number of queued request acceptance
connectionTimeout: network connection timeout, in milliseconds
enableLookups: If the DNS query is not false, improved business capacity should be set to false
disableUploadTimeout: If it is true then upload timeout disabled

  These are some of the more commonly used parameters, Tomcat server.xml configuration in detail there will be in more detail.

(2) tomcat concurrent configuration

Server.xml file configuration in the conf <Connector> node
<Connector Port = "8080" = Protocol "the HTTP / 1.1"
connectionTimeout = "30000"
the redirectPort = "8443"
the maxThreads = "400"
minSpareThreads = "50"
maxSpareThreads = "200 is"
acceptCount to = "400"
enableLookups = "to false"
disableUploadTimeout = "to true" />
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
two, tomcat memory configuration
tomcat generally has a default memory size, default values the entire physical memory is very small, if not configured tomcat memory, a waste of resources will greatly server to verify the performance impact of the system, so the tomcat memory configuration for the user than the larger system is particularly important.

(1) tomcat memory parameters

-server: Be sure to as the first parameter, when a plurality of CPU performance good
-Xms: java Heap initial size. The default is the physical memory of 1/64.
-Xmx: java heap maximum. Recommendations are set to half of physical memory. Not exceed the physical memory.
-XX: PermSize: The initial size of permanent preservation area set memory. The default value is 64M.
-XX: MaxPermSize: set the maximum size of the memory of the permanent preservation area. The default value is 64M.
-Xmn: young generation (the young generation) of the heap size. 3 and 4 is generally set to one of the sub Xmx
(2) tomcat memory configuration

In echo Using CATALINA_BASE catalina.bat file in the bin: "% CATALINA_BASE%" of the previous row adding the following code.
the JAVA_OPTS the JAVA_OPTS% =% the SET -server -Xms8192m -Xmx8192m -Xmn1890m
1
2
3
three, Tomcat garbage collection
garbage collection (gc) mechanism is very important, because sometimes the system memory is not recovered in time lead to memory overflow or memory saturation appears unable to respond user requests, which would require us to clean up free memory to ensure proper system operation, the optimal configuration tomcat GC is to ensure the normal operation of critical systems.

(1) Classification and management of objects in the JVM

The JVM is running on the survival time of the object which is substantially divided into three kinds. And these three different types of objects are stored assigned to the system from a different memory space in the JVM. This management target storage space called Generation management.

Young Generation (the young generation): used to store the "untimely death" objects (ie transient object). For example: temporary objects used when calling a method or when you create an object or local variables.
Tenured Generation (old generation): used to store the object "resident" (i.e. longer referenced objects). Often reflected in a large-scale program objects in global object or being used for a long time.
Perm Generation (permanent preservation region): for storage of "permanent" objects. These objects manage classes and methods to run in the JVM.
(2) jvm garbage collection parameters

-verbose: gc: garbage collection display information (display information output device when garbage collection occurs in a virtual machine)
UseConcMarkSweepGC: Enabling this parameter ParNew & CMS (serial old as substitute) Collector
MaxTenuringThreshold: maximum age for promotion of old age. The default is 15, for example, is set to 10, the object after 10 GC will be put into ordinary old generation.
-XX: + ExplicitGCInvokesConcurrent: System.gc () can be executed concurrently with the application.
GCTimeRatio: the throughput of the system. 99 for example, the time ratio of GC 1/1 + 1 = 99%, which is 99% certain requirements. If you can not meet the new generation will be reduced in size.
CMSInitiatingOccupancyFraction: triggering memory ratio CMS collector. For example, 60% means is that, when the memory up to 60%, CMS will begin concurrent collection.
CMSFullGCsBeforeCompaction: Set after several CMS garbage collection, triggers a memory consolidation.
-Xnoclassgc: Disable class garbage collection, performance will be higher;
-XX: SoftRefLRUPolicyMSPerMB = N: The official explanation is: Soft reference customer concentration in the survival of a virtual machine than longer. Frequency can be cleared with the command line parameter -XX: SoftRefLRUPolicyMSPerMB = controls, which you can specify soft reference heap per megabyte of free space to keep alive (once it is not strong up the) number of milliseconds, which means that per megabyte heap free space in the soft reference will be (after the last strong reference recycled) survived a second. Note that this is an approximate value, because the soft reference will only be cleared when garbage collection, but the garbage collector does not always happen. The default is one second.

  These are some basic parameters, by JVM memory management - to view a more detailed configuration parameters refined solution garbage collection, view in principle by Tomcat Java garbage collection tuning

(3) tomcat garbage collection configuration

Tomcat garbage collection and memory settings are configured together, and gc memory settings is not bigger is better, a good proportion can make your system even more general performance, the following is tomcat7, 16g server physical memory as standard

In echo Using CATALINA_BASE catalina.bat file in the bin: "% CATALINA_BASE%" of the previous row adding the following code.
. 1
2
SET = the JAVA_OPTS the JAVA_OPTS%%
-server -Xms8192m -Xmx8192m -Xmn1890m -verbose: GC
-XX: + UseConcMarkSweepGC -XX: MaxTenuringThreshold -XX =. 5: + ExplicitGCInvokesConcurrent -XX: GCTimeRatio -XX =. 19: 70 -XX = CMSInitiatingOccupancyFraction : CMSFullGCsBeforeCompaction = 0 -Xnoclassgc -XX: SoftRefLRUPolicyMSPerMB = 0

* Take over code written in a row to take effect. *
. 1
2
configuration after jvm memory system operating conditions are as follows:


You can see the system will be recycled after reaching the memory 2g free memory, the basic situation of overflow does not occur, 8g maximum memory up only with the 2g, illustrate the performance of the system is still very favorable, and then increase the number of users can be certain ensure system stability degree.

Four, Tomcat downtime prevention
tomcat after running for some time, the situation appears inaccessible, check the memory completely normal, view the server port found a large number close_wait, resulting in network congestion, not that they can not respond to the request, which is the most frequently occurring tomcat downtime phenomenon of suspended animation.

(1) TCP port status

LISTENING state
after the first start FTP service is listening (LISTENING) state.
ESTABLISHED state
ESTABLISHED means to establish a connection. It represents the two machines are communicating.
CLOSE_WAIT
the other party take the initiative to close the connection or the network connection is lost resulting in abnormal, then we will become a state CLOSE_WAIT At this point we want to call close () to make the connection correctly closed.
TIME_WAIT
we take the initiative to call close () is disconnected, the other party to confirm receipt of state to TIME_WAIT. TCP agreement TIME_WAIT status will continue 2MSL (ie twice the maximum lifetime of the segment), in order to ensure that the old connection status will not affect the new connection. Connection resources occupied in the TIME_WAIT state will not be a kernel release, so as a server, where possible, try not to take the initiative to disconnect, to reduce the waste of resources caused by the TIME_WAIT state.

  More detailed TCP port status refer to TCP port Status Description

(2) TCP parameters Windows system

The KeepAliveTime
  the KeepAliveTime the value of the control system attempts to verify that an idle connection is still intact frequency. If the connection is not inactive for a period of time, the system will remain connected to the transmission signal, If the network and the recipient is active, it will respond. If you need to lose sensitive to the situation of the recipient, that need to quickly find out whether the recipient is lost, consider reducing this value. And if the number of occurrences of long-term inactivity of many idle connections, but the situation appears less loss recipient, you may need to increase this value to reduce overhead.
  By default, the idle connection 7200000 milliseconds (2 hours) is not active, the system will send a message to maintain the connection.
KeepAliveInterval
  value KeepAliveInterval represents the other party in response to "stay connected" signal is not received, the system repeatedly transmits "stay connected" frequency signal. In the case of no response, continuously sends the value "stay connected" signal exceeds the number of times the TcpMaxDataRetransmissions (described below) will drop the connection. If the network environment is poor, allowing a longer response time, increase the value is considered to reduce overhead; soon need to verify whether, if the receiver has been lost, consider reducing this value or TcpMaxDataRetransmissions value.
  Before default, the response is not received and re-transmitted signal "stay connected", the system will wait for 1000 milliseconds (1 second).
KeepAliveInterval
  KeepAliveInterval value represents the other party in response to "stay connected" signal is not received, the system repeatedly transmits "stay connected" frequency signal. In the case of no response, continuously sends the value "stay connected" signal exceeds the number of times the TcpMaxDataRetransmissions (described below) will drop the connection. If the network environment is poor, allowing a longer response time, increase the value is considered to reduce overhead; soon need to verify whether, if the receiver has been lost, consider reducing this value or TcpMaxDataRetransmissions value.
  Before default, the response is not received and re-transmitted signal "stay connected", the system will wait for 1000 milliseconds (1 second).

  More system parameters, please refer to the Windows TCP parameters of the system

(3) Analysis and Prevention of suspended animation tomcat

The reason close_wait happens is that TCP connection without calling close approach needs to be applied to handle the network link is closed for Web requests this reason, often because the Response of BodyStream not call Close, in addition to tweak the code, but you can adjust the windows system parameters to solve the tomcat suspended animation problem

tomcat when using the netstat phenomenon of suspended animation -ano view the port as follows:

KeepLive default in the Windows operating system is 7200000 milliseconds, which is only 2 hours to clean up once, for a large number of close_wait under circumstances, can reduce the time
in the registry [HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Tcpip \ Parameters] changes or create the following entry
"KeepAliveTime" = dword: afc8 ( 45000 milliseconds)
"KeepAliveInterval" = DWORD: 1
"TcpMaxDataRetransmissions" = DWORD: "5"
situation will be significantly improved, but does not guarantee large concurrent server does not appear under suspended animation phenomenon, after all regulatory code also accounts for a large proportion.

V. Conclusion
write so much I'm tired, and you get tired, even more appalling is written to the middle half of network instability, leading to many of the things I write are missing, the back teeth or finished, now not dinner, baths were closed, hey, but still worth it. You can see here and I am honored, I hope for your help
----------------
Disclaimer: This article is CSDN blogger original article "ceozero", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/u010133338/article/details/81142902

Guess you like

Origin www.cnblogs.com/zhanying999666/p/12188981.html