Load Average
Refers to the number of tasks in the run queue, if only 1 processes in the running queue for 1 minutes, the 1-minute load average is 1, only 1 processes in the running queue half a minute, the 1-minute load average is 0.5, meaning that in the last 1 minutes, the running queue has 50 % of the time is no task.
The state of the process in the running queue is R, and in Linux, processes other than the R state are computed into the load average, and the D state process is counted, and the process of the D state is in the process of uninterruptable sleep (not interrupted). These processes may be waiting for disk IO, network IO, or a system call to wait for the return of the kernel space.
It is also important that the number of threads in a process is calculated as a different process, and if a process produces 1000 threads running concurrently, the length of the running queue is 1000,load average is 1000.
CPU Usage
is the ratio of the amount of time the CPU is used to perform a task and the total time that is commonly seen:%us,%sy,%ni,%id,%wa,%hi,%si,%st, where CPU Usage = (%us +%sy +%ni) = (100%-), which What you see is the rate of CPU work.
Why is load high and CPU usage low?
That's very likely the process of D states is very large, we use the following command to look at the number of processes (or threads) in R state and D state, only a few processes (or threads) have found R state, and the process (or thread) of the D state has a large heap, and these are Apache threads Because the Linux compute load average will also calculate the D-State task, so the load will be very high, but in fact, the CPU usage is not high, because the actual CPU consumes a few tasks.
[Email protected] ~]# Ps-emo User,pid,stat,command | awk ' {print $} ' | Grep-e "^d|^r"
Apache and KeepAlive
Using Ps-elf | grep httpd | Wc-l count the number of Apache threads and find more than 3,000, why does Apache open so many threads?
Look at the Apache configuration, using the worker mode, this mode will start a number of sub-processes, the child process will start multiple child threads, the configuration of the maximum boot 64 processes, each process 64 threads, the maximum can start 4,096 threads.
<ifmodule mpm_worker_module>serverlimit 128StartServers 64MaxClients 4096minsparethreads 64maxsparethreads 128threadsperchild 64maxrequestsperchild 10000</ifmodule>
It is important to note that these threads bind to a connection, not a request, which means that a connection consumes a thread until the connection is closed. And then found that Apache KeepAlive is turned on by default, timeout 5 seconds, that is, if a host of QPS is 600, if these requests are different user requests, that is, there are 600 new connections per second, and each connection keepalive 5 seconds, That is, at the same time every second there are 3,000 connections hold live there, and Apache is a thread corresponding to a connection, that is, Apache to open 3,000 threads there.
In some scenarios, keepalive optimization is turned on, such as an HTML request, with a subsequent js/css/picture request, when the keepalive is turned on, the connection can be reused, saving the consumption of TCP connections and RTT, and for some special scenarios, the scene may be very simple, The user requests the service side, obtains the data, then does not have then, may after a few hours or the next day requests again, so the request is almost different user different connection, when the concurrency volume is large, the opening keepalive causes the massive connection to wait for the timeout after processing the request, You're not doing anything!
The keepalive configuration on the line is turned off and the following configuration is added to the httpd.conf:
KeepAlive OFF
D State Process
After shutting down the keepalive, the load obviously lowered, no longer suddenly soar to more than 100, but the load is still abnormal, from the chart below can be seen, sometimes the load will still have a sudden spike in the situation, from single-digit soared to 2 digits.
According to the above troubleshooting, found that the D status of the Apache thread caused by the load, the shutdown keepalive just let these threads reduced, but has not been fundamentally resolved. Why does the Apache thread turn into D state?
We know that the D state of the process is actually waiting for the disk I/o,apache and disk I/O related to the write log, and then use the exclusion of the individual log output configuration to shut down, and ultimately to a compile into the Apache module component problem, The rotation logic inside can easily cause Apache threads to wait for disk I/O in large concurrency, and is especially severe in keepalive cases, by troubleshooting the final location of the configuration and closing the configuration to resolve the issue.
<RLog>Path=/home/abc/app/apache2/logs/patcher_logSize=100000000Num=5Level=20000</RLog>
This article is from the "Meditation Trip" blog, please be sure to keep this source http://shen445122.blog.51cto.com/6716303/1717780
The difference between Load average and CPU usage