Analysis and resolution of slow response of server

Source: Internet
Author: User
Tags reverse dns

One, the elimination of their own network problems

You can use webmaster tools to test website speed: Webmaster's home

Image.png

Second, check whether and browser-related

Change a browser to visit the website and do the same to see if there are any differences.
Previously encountered a problem is on the MacBook Google Browser, there is one step operation always can not render the results, press F12 View console also no error, but there is an interface is always in the pending state. Then a different browser tries, the problem does not occur. The final discovery is due to the fact that the parameters carried after the interface get request are not the same as the default encoding in the browser, and the problem is resolved by UTF-8 encoding instead.

Third, check the log of the services

See if the program throws an exception. Of course, the service response is slow, not return, or HTTP returns 500. Check the logs in Tomcat or the business logs that are logged by the program.
In general, it is also:

Linux # cd xx/tomcat/logs# tail-f catalina.out 

Iv. viewing the parameters of the server

Most companies now have a service monitoring system that has CPU, memory, NIC, disk, response time requests for URL requests concurrency, JVM-related monitoring, and so on. Of course, the company does not have a monitoring system or panic, monitoring system just looks intuitive point. No monitoring system, or can be through the Linux command, JDK JPS, Jstack, Jmap, Jconsole, IBM Heapanalyzer and more intuitive monitoring jprofiler, and so on.

Top command View load (can install a htop tool, more intuitive and more powerful than top)

                       Top Command Interface Htop Interface

Can be installed directly using the Yum install-y htop command htop

The tasks line shows the total number of processes and the status of the current process, pay attention to Zombie, which represents the zombie process 不为0则表示有进程出现问题 .

The CPU (s) line shows the state of the current CPU, which means that the user process consumes CPU scale, SY indicates that the kernel process consumes CPU, the ID represents the percentage of idle CPU, and WA represents the percentage of CPU time that IO waits. wa占用超过30%则表示IO压力很大.

The MEM line shows the current state of the memory, total is the overall memory size, userd is used, free is the rest, and buffers is the directory cache.

Swap lines with the Mem line, cached represents the cache, the user has opened the file. 如果Swap的used很高,则表示系统内存不足.

Under the top command, press 1 to show how much CPU the server has and how each CPU is used. In general, the server's reasonable load is CPU core count. This means that for a 8-core CPU, the load within 16 indicates that the machine is running stably and smoothly. If the load exceeds 16, it indicates that the server is running with some pressure.

If the CPU is too high, you can look at the PID and Jstack tools to see which code is causing the details.

V. Analysis of the project itself

Check the configuration of some parameters such as thread pool, database connection pool, etc. in the project. (Some services that do not need to be opened on the production service should also be closed, such as swagger UI, etc.)

VI. Virtual Machine Analysis

Using the top command to see the memory footprint of a virtual machine, it is sometimes found that while the percentage of virtual machines that occupy memory is small and there is a significant upper limit, we need to look at the configuration of the virtual machine.

Workaround (in Tomcat, for example):

Image

The specific values are based on the actual situation.

VII. Database Analysis
    1. Open the log print of the SQL execution statement in the project, take out the statement analysis and optimize it (optimize the statement itself or optimize the database)

    2. Set maximum number of connections

--View the maximum number of connections show variables like '%max_connections% ';--Current connection usage show status like ' threads% ';

If the value of the maximum number of connections is too small can be modified according to the actual situation, generally modified to 1000

    1. Timeout control

MySQL has an attribute "Wait_timeout", the default value is 28,800 seconds (8 hours), the value of Wait_timeout can be set, but can only be 2147483, can not be larger. That is, about 24.85 days, can be viewed through show global variables like ' wait_timeout ';

Wait_timeout means: A connection idle for more than 8 hours, MySQL will automatically disconnect the connection, popularly speaking is a connection within 8 hours of inactivity, will automatically disconnect the connection. Because DBCP does not verify that the connection is valid, an exception occurs when data is manipulated with it.

If the problem is caused by time-out control, it is not recommended to modify the value of Wait_timeout, which is resolved by adding "&autoreconnect=true&failoverreadonly=false" after the URL of the database connection.

    1. DNS Reverse resolution

After the MySQL database receives a network connection, first obtains the other's IP address, then carries on the reverse DNS resolution to this IP address to obtain this IP address corresponding host name. Use the host name in the permission system to determine the permissions. Reverse DNS parsing is time-consuming and may make users feel slow. Even sometimes, the reverse resolution of the host name does not point to this IP address, this time can not be connected successfully. You can disable MySQL for reverse DNS resolution in the configuration file by simply adding the following line to the MY.CNF [MYSQLD] paragraph:

Skip-name-resolve (Windows is the same as Linux)

    1. Table Cache
--View the number of open tables show global status like ' open%tables% ';--View cache's upper limit value show variables like ' Table_open_cache ';

Open_tables: Is the number of tables currently open in the cache.
Opened_tables: Is the number of open tables since MySQL started.
When the Opened_tables value is very large, indicating that the cache is too small, causing the open table to be frequent, you can view the current Table_open_cache settings

    1. Slow query log
      The purpose of the logged slow query log is to confirm that the server response is slow due to slow execution of some statements. Need to turn on slow log query logging and set the time threshold for slow query log (in seconds)
--Queries whether slow logging is turned on. The default is off offshow variables like '%slow_query_log% ';---Query time threshold (seconds), SQL that exceeds this execution time will be recorded show variables like ' long_query_time '; 

Reference: https://www.cnblogs.com/yangc/p/6859985.html

Analysis and resolution of slow response of server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.