The following sections show how load average works in stress testing.
CPU time slice
To improve Program Execution efficiency: multiple threads are used in many applications. In this way, the original serialization execution can be changed to parallel execution. The task decomposition and parallel execution can greatly improve the program running efficiency. But this is all code-level performance, and how does the hardware support it? It depends on the CPU time slice mode to describe all this. The execution of any command of the program will often compete for the most valuable resource of the CPU, no matter how many threads your program is divided into to execute different tasks, they all have to wait in queue to get this resource for computing and processing commands. First, let's look at the situation of a single CPU.
If all threads queue for CPU resource acquisition, the so-called multithreading has no practical significance. CPU manager is just a virtual role for me. It allocates and manages CPU usage. At this time, multithreading will have the opportunity to obtain CPU resources during the running process, it also implements multi-thread parallel processing with a single CPU.
Multiple CPUs only support the expansion of a single CPU. When all the CPUs are running at full capacity, the time slice will be used for each CPU to Improve the efficiency.
During Linux kernel processing, each process has a fixed time slice by default to execute commands (the default value is 1/100 seconds). During this period, the process is allocated to the CPU and then exclusively used. If the time slice is used up and the specified time is not reached, the CPU usage will be abandoned. If the time slice has not completed the work, the CPU usage will be revoked, the process will be interrupted and suspended waiting for the next time slice.
Difference between CPU utilization and load average
Stress Testing not only simulates stress parameters such as concurrent users in business scenarios, but also keeps an eye on the performance of the machine during stress testing to ensure the effectiveness of stress testing. When a server is running under an overload for a long time, the pressure we receive is not what we think is acceptable. For example, if a project manager asks a person to work 12 hours a day to estimate the workload, the project plan is not a reasonable plan, that person will collapse sooner or later, which affects the overall project progress.
In the past, CPU utilization was often considered by our layers to determine whether the machine has reached a full-load standard. When we see the 50%-60% usage, we think that the machine has reached a critical threshold. CPU utilization, as the name implies, is the usage of the CPU. This is the statistics on the CPU usage in a period of time. This indicator shows the CPU usage in a certain period of time, if it takes a long time, you need to consider whether the CPU is already overloaded. The long-term overload operation is a damage to the machine itself, therefore, the CPU utilization must be controlled under a certain proportion to ensure the normal operation of the machine.
The load average is the load of the CPU. It does not contain the CPU usage, but the statistical information of the sum of the number of processes that the CPU is processing and waiting for CPU processing within a period of time, that is, the statistical information of the length of the CPU queue. Why is this information counted? What is the impact of this information on stress testing, then, an analogy is used to explain the differences between CPU utilization and load average and its guiding significance for stress testing.
We compare the CPU to a phone booth. Every process is a caller. Now there are a total of four phone booths (just like our machines have 4 cores), and 10 people need to make calls. Now, the Administrator allocates one minute's call time to each person in sequence. If the user finishes using the phone within one minute, you can immediately return the call right to the Administrator. If the call is not completed within one minute, you need to queue up again and wait for another call.
Users who use the phone are classified again. 1 minute means that the time used by these users is less than or equal to 1 minute, 2 min means that the time used by the user is less than or equal to 2 min, and so on. According to the telephone usage rules, users in 1 min can complete the call only after one allocation, while the other two types of users need to queue up two to three times.
Telephone usage = sum (Active use CPU time)/Period
The sum of the telephone time used by each user assigned to the phone is divided by the statistical time period. Note that sum (Active use CPU time) is the sum of telephone usage time, which is different from sum (occupy CPU time. (For example, if a user gets a one-minute permission and calls within 10 seconds, it takes 20 seconds to query the number book, and then calls another call in the remaining 30 seconds, in this case, the phone number is used for 1 minute, but only 40 seconds is used)
The telephone average load shows an average of all telephone users plus those waiting for telephone distribution within a certain statistical period.
The telephone utilization rate statistics reflect the telephone usage. When the telephone is used for a long time and there is not enough time to rest, therefore, the telephone hardware is overloaded and the frequency of use needs to be adjusted. The telephone average load shows the telephone usage status from another perspective. The higher the average load, the more intense the competition for telephone resources and the shortage of telephone resources. The Application and Maintenance of resources also requires a great deal of cost. Therefore, in this case of high average load, the long-term "Hot competition" of telephone resources is also a kind of damage to hardware.
Is there a high load average in the case of low utilization? You can understand the occupation time and usage time. After a time slice is allocated, whether or not it is used depends on the user. Therefore, it is entirely possible that the load average with low utilization is high. From this point of view, it is not enough to judge whether the CPU is in an overloaded working state from the CPU usage. You must use the load average to view the CPU usage and application situation globally.
So let's look back at the requirements of the Test Department for load average. When our machine has eight CPUs, the load is controlled at around 10, that is, each CPU is processing a request, there are also two waiting for processing. After reading the introduction from many people on the Internet, the simple calculation of load is generally about 2 * CPU count minus 1-2 (this is only online, not necessarily a standard ).
Additional points:
1. Identify performance problems based on the results of CPU utilization and CPU load average. First, low CPU utilization does not indicate that the CPU is not a bottleneck. long-running queues of competing CPUs are also a manifestation of CPU overload. For applications that may spend time on I/O, socket, and so on, you can consider whether the speed of these hardware affects the overall efficiency.
The best sample here is a phenomenon I found during the test: In order to improve the processing efficiency, the control policy and counting information are put in the memcached Cache during the processing of SIP, after I doubled the memcached cache configuration, the CPU utilization and load were all decreased. In fact, in the process of processing the task, wait for the response of the socket to affect the CPU competition.
2. The importance of multi-CPU programming in the future. Now the CPU of the server is multiple CPUs, and our server's processing capacity is no longer in accordance with Moore's Law. As far as the telephone kiosk scenario I mentioned above is concerned, for three users with different time requirements, we can see that the load average will be different in different order of allocation. Assume that the load period is counted as 2 minutes. If the phone number is allocated in the order of 1 min, 2 min, and 3 min, then our load average will be the lowest, and there will be different results in other order. Therefore, in the future, multi-CPU programming can better improve the CPU utilization and make the program run faster.
The content mentioned above may not be accurate or correct. If there is any deviation, please point out that some unclear concepts can be corrected.
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