Original post address: http://finlandrbt.spaces.live.com/blog/cns! 70C541D1517F6BAE! 987. entry
Linux memory management-vmstat many of the things mentioned in this article are worthy of my reference in performance testing and improvement. Here, we can extract that it seems that page and cpu scheduling policies need to be paid special attention when reading the source code. What we hope most is to see some foreign performance monitoring solutions.
Ps: After the <FONT> label is set, the style, bug, and big bug of <DIV> will be overwritten.
Processing Unit is one of the fastest components in the system. It is rare to maintain a CPU usage of 100% for a single program at a time (that is, 0% idle, waiting for 0%) for more than a few seconds. Even in a heavy-load multi-user system, sometimes there is a period of 10 ms (MS), where all threads are waiting at the end. If the monitor shows that the CPU usage is 100% for a long time, it is likely that a program is in an endless loop. Even if the program "only" occupies a large amount of resources rather than crashes, it needs to be identified and processed.
R --> Number of processes waiting in the running queue
B --> Number of processes waiting for io
W --> processes that can enter the running queue but are replaced
Memoy
Swap --> available swap memory (k)
Free --> idle memory (k)
Pages
Re -- recycling page
Mf -- non-serious error page
Pi -- number of incoming pages (k)
Po -- number of outgoing pages (k)
Fr -- number of free pages (k)
De -- number of missed pages read in advance
Sr-page scanned by clock algorithm
Disk Displays disk operations per second. S indicates the scsi disk, and 0 indicates the disk number.
Fault displays the number of interrupts per second
In -- device interruption
Sy -- System interruption
Cy -- cpu Switching
Cpu indicates the cpu usage status
Cs -- time used by the user process
Sy -- time used by the system process
Id -- cpu idle time
If r is often greater than 4 and the id is often less than 40, the cpu load is heavy.
If pi and po are not equal to 0 for a long time, the memory is insufficient.
If the disk is often not equal to 0 and the queue in B is greater than 3, the io performance is poor.
Vmstat command (CPU)
The first tool to be used is the vmstat command, which quickly provides brief information about various system resources and related performance issues. The vmstat Command reports statistics about Kernel threads, includes kernel threads in the running and waiting queue, in memory, in page scheduling, on disk, interrupted, system calls, context switching, and CPU activity. The reported CPU activity is divided into user, system, idle time, and percentage of disk I/O waiting.
Note: If you use the vmstat command without any options, or with only the interval and any counting parameters, such as vmstat 2 10; the number in the first line is the average value since the system reboot.
As a CPU Monitor, the vmstat command is better than the iostat command, because the vmstat command is scroll, making it easier to scan the output of each report line, and if many disks are connected to the system, this reduces the overhead. The following example helps you identify situations where a program is out of control or when the CPU is too intensive to run in a multi-user environment.
# vmstat 2
kthr memory page faults cpu
----- ----------- ------------------------ ------------ -----------
r b avm fre re pi po fr sr cy in sy cs us sy id wa
1 0 22478 1677 0 0 0 0 0 0 188 1380 157 57 32 0 10
1 0 22506 1609 0 0 0 0 0 0 214 1476 186 48 37 0 16
0 0 22498 1582 0 0 0 0 0 0 248 1470 226 55 36 0 9
2 0 22534 1465 0 0 0 0 0 0 238 903 239 77 23 0 0
2 0 22534 1445 0 0 0 0 0 0 209 1142 205 72 28 0 0
2 0 22534 1426 0 0 0 0 0 0 189 1220 212 74 26 0 0
3 0 22534 1410 0 0 0 0 0 0 255 1704 268 70 30 0 0
2 1 22557 1365 0 0 0 0 0 0 383 977 216 72 28 0 0
2 0 22541 1356 0 0 0 0 0 0 237 1418 209 63 33 0 4
1 0 22524 1350 0 0 0 0 0 0 241 1348 179 52 32 0 16
1 0 22546 1293 0 0 0 0 0 0 217 1473 180 51 35 0 14
This output shows the effect of introducing a program into a busy multi-user system in an endless loop. The first three reports (Deleted summaries) indicate that the system is balanced among 50-55% users, 30-35% systems, and 10-15% I/O waits. When the cyclic program starts running, all available CPU cycles are consumed. Because the loop program does not perform I/O, it can occupy all the cycles that have not been used due to I/O wait. Worse, this means that when a useful process abandons the CPU, there is always a process ready to take over the CPU. Because the priority of the loop program is the same as that of all other foreground processes, when another process becomes allocable, it does not have to discard the CPU. The program runs for about 10 seconds (five reports), and then the activities reported by the vmstat command are restored to normal mode.
The best use is to allow the CPU to work in 100% of the time. This is suitable for single-user systems without the need to share the CPU. In general, ifUs+SyIf the time is lower than 90%, it is not considered that the CPU is restricted for a single user system. However, in a multi-user systemUs+SyIf the time exceeds 80%, the process may have to wait in the running queue. Response time and throughput will be compromised.
To check whether the CPU is a bottleneck, consider the fourCpuColumn and twoKthr(Kernel thread) column. ViewFaultColumns are also worth the following:
- Cpu
The percentage of CPU time used during this interval.CpuThe columns are as follows:
- Us
UsThe column shows the percentage of CPU time spent in user mode. A unix process can be executed either in user mode or in system (kernel) mode. In user mode, a process is executed in its own application code and does not require kernel resources to compute, manage memory, or set variables.
- Sy
SyThis column details the percentage of time the CPU spends executing a process in the system mode. This includes the CPU resources consumed by kernel processes (kprocs) and other processes that need to access kernel resources. If a process requires kernel resources, it must execute a system call and switch to the system mode to make the resource available. For example, read or write operations on a file require kernel resources to open the file, find a specific location, and read or write data, unless the memory ing file is used.
- Id
IdThe column shows the percentage of CPU idle or waiting time when no pending ephemeral disk I/O is available. If no thread can be executed (the running queue is empty), the system assigns a thread called wait, also known as idle kproc. In an SMP system, each processor has a wait thread that can be assigned. The report generated by the ps command (with the-k or-g 0 option) determines itKprocOrWait. If the ps report shows that the total time of this thread is relatively high, this indicates that there is an important time period, and no other threads are prepared to run on the CPU or wait for execution. Therefore, the system spends most of its time idle and waiting for new tasks.
- Wa
WaThe column details the percentage of CPU idle on ephemeral disk I/O and NFS attached disks. If at least one unfinished disk I/O is run in wait, the time is classified as I/O wait time. Unless the process uses abnormal I/O, I/O requests to the disk will cause the called process to be blocked (or sleep) until the request is complete. Once the process's I/O request is complete, the process is put into the running queue. If I/O is completed quickly, the process can use more CPU time.
More than 25%WaThe value indicates that the disk subsystem may not be properly balanced, or this may also be the result of intensive disk workloads.
- Kthr
The average value of the number of kernel threads in various queues at the sampling interval per second.KthrThe columns are as follows:
- R
Average number of runable kernel threads, including running threads and threads waiting for CPU. If this number is greater than the number of CPUs, at least one thread will wait for the CPU. The more threads wait for the CPU, the more likely it will affect the performance.
- B
The average number of kernel threads in the VMM wait queue per second. This includes threads waiting for file system I/O, or threads temporarily suspended due to memory loading control.
If the process is temporarily suspended due to memory loading control, the blocking column in The vmstat Report (B) Indicates that the number of threads increases, rather than the number of running queues increases.
- P
For vmstat-I, it is the number of threads waiting for the original device I/O per second. Threads waiting for file system I/O are not included here.
- Fault
Information about process control, such as traps and interruption rate.FaultThe columns are as follows:
- In
The number of device interruptions per second measured at a certain interval.
- Sy
Number of system calls per second measured at a certain interval. Through explicit system calls, user processes can use resources. These calls indicate that the kernel executes the operations of the calling thread and exchanges data between the kernel and the process. Because the workload and application changes a lot and different calls execute different functions, it is impossible to define the number of system calls per second. However, in generalSyWhen the column is increased to more than 10000 calls per second, further investigation is required (on an SMP system, this number is 10000 calls per processor per second ). One reason may be the "Round-Robin" subroutine, such as the select () subroutine. For this column, we recommend that you perform a benchmark evaluation to provide a normalSyValue count.
- Cs
The number of context switches observed at a certain interval per second. Physical CPU resources are subdivided into logical time slices of every 10 ms. Suppose a thread is scheduled to run until its time slice is used up, until it is preemptive, or until it voluntarily gives up CPU control. When giving CPU control to another thread, the context or working environment of the previous thread must be saved and loaded into the context of the current thread. The operating system has a very effective context switching process, so each switching does not consume resources. Any significant increase in context switching, such as whenCsThis is much higher than the disk I/O and network information packages. Further investigation should be conducted.