Typically, when the CPU of a service is high,
1. Use the PS-MP pid-o thread,tid,time command to view the thread condition of the process, enumerate the high-occupancy threads, pick the tid,eg of high-occupancy threads: pick the thread of Tid 14065, view the stack of the thread, Switch the thread ID to 16 first, and use the printf "%x\n" tid command to convert (
printf "%x\n" 14065
)
Then use the Jstack command to print the thread stack information, the command format: Jstack pid |grep tid-a (PID: Process Id,tid: 16 binary of the converted thread ID), you can print out the stack information and view the problem in the stack information.
2. You can also use the Jstack command to view the stack condition of a process
Jstack 14063 >>jstack.out
3. If the location of the information is only a GC problem, do not locate the problem code, then in the configuration of the server to optimize, if the location is the GC thread occupied high CPU caused the process of high occupancy, you can try to configure the JVM memory consumption of the initial value and maximum value, eg:java_opts = "-xms1024m-xmx4096m-xss1024k-xx:permsize=512m-xx:maxpermsize=2048m", if the JVM is optimized for Tomcat, it can be run without affecting other programs in the server. Tomcat's JVM attempts can be configured as half of the memory in the server house, and the%mem of using top to view the current Tomcat process after the configuration is complete restarts is growing, but it is not going to grow as soon as it is near the configured value.
4. Optimize TOMCAT: Configure the connection pool by configuring the maximum number of connections for Tomcat. The configuration Protocol is the NIO protocol, and concurrency is better than the default bio:
Protocol= "Org.apache.coyote.http11.Http11NioProtocol"
<executor name= "Tomcatthreadpool" nameprefix= "catalina-exec-" maxthreads= "" "Minsparethreads="/><C " Onnector port= "1881" executor= "Tomcatthreadpool" protocol= "Org.apache.coyote.http11.Http11NioProtocol" Conne ctiontimeout= "20000" uriencoding= "UTF-8" redirectport= "8443"/>
5. Relationships with Tomcat logs: Server.xml
<valve classname= "Org.apache.catalina.valves.AccessLogValve" directory= "Logs" prefix= "Localhost_access_lo G. "suffix=". txt "pattern="%h%l%u%t "%r" %s%b "/>
Comment out, this configuration is the output of the localhost log
, as well as the ability to configure output/dev/null in the catalina.sh file
If [-Z "$CATALINA _out"]; Then #CATALINA_OUT = "$CATALINA _base"/logs/catalina.outcatalina_out=/dev/nullfi
This will not output the Catalina log.
6.mysql optimization: Modifies the maximum number of MySQL connections, which can be configured in MY.CNF, so the configuration does not need to be reconfigured after a reboot, or it can be configured with a statement to configure the set max_connections, so that configuration needs to be reconfigured after each reboot.
If MySQL CPU is very high, you can try to optimize the wait_timeout time, the default is 28800, if there are multiple connections, you may not be able to free the waiting connection, but configure the release time to remember to configure the database connection pool in the project related parameters are also configured
<!--removeabandonedtimeout: Time-out (in seconds)-<property name= "removeabandonedtimeout" value= "/>" <!--maxwait: Timeout wait time in milliseconds 6000 milliseconds/1000 equals 60 seconds-<property name= "maxwait" value= "
Otherwise, the code cannot be freed from waiting for a connection after it is connected.
7. Optimize the recovery time of time_wait connection of Linux system,
By adjusting the kernel parameters to resolve the vi/etc/sysctl.conf edit file, add the following: net.ipv4.tcp_syncookies = 1 Net.ipv4.tcp_tw_reuse = 1 Net.ipv4.tcp_tw_r ecycle = 1 Net.ipv4.tcp_fin_timeout = 30 then execute/sbin/sysctl-p to let the parameters take effect. Net.ipv4.tcp_syncookies = 1 means that Syn Cookies are turned on. When a SYN wait queue overflow occurs, cookies are enabled to protect against a small number of SYN attacks, the default is 0, which means close; Net.ipv4.tcp_tw_reuse = 1 means turn on reuse. Allow time-wait sockets to be reused for new TCP connections, default = 0, net.ipv4.tcp_tw_recycle = 1 for fast recycle of time-wait sockets on TCP connection, default = 0 to close ; net.ipv4.tcp_fin_timeout modifies the default timeout time for the system.
8. Release the value of Ulimit-n, the system default open the number of files is 1024, set to Ulimit-n 65535, this can increase the number of systems can be connected
Operating environment for Centos7,tomcat and MySQL optimization method, experience summary