


Linux performance testing and monitoring sar command_PHP tutorial
Linux performance testing and monitoring sar command
sar (System Activity Reporter system activity report) is currently one of the most comprehensive system performance analysis tools on Linux, which can be used from many aspects Report system activities, including: file reading and writing, system call usage, disk I/O, CPU efficiency, memory usage, process activities and IPC-related activities. This article mainly uses the CentOS6.3 x64 system as an example to introduce the sar command.
Common format of sar command
sar [options] [-A] [-o file] t [n]
where:
t is sampling Interval, n is the number of samples, and the default value is 1;
-o file means storing the command results in a file in binary format, and file is the file name.
options are command line options. Commonly used options for the sar command are as follows:
-A: The sum of all reports
-u: Output CPU usage statistics
-v: Output statistics about inodes, files, and other kernel tables
-d: Output activity information for each block device
- r: Output statistical information of memory and swap space
-b: Display statistical information of I/O and transfer rate
-a: File reading and writing status
-c : Output process statistics, number of processes created per second
-R: Output statistics of memory pages
-y: Terminal device activity
-w: Output System exchange activity information
1. CPU resource monitoring
For example, sample once every 10 seconds, sample 3 times continuously, observe the CPU usage, and store the sampling results in binary form into the current In the file test in the directory, you need to type the following command:
sar -u -o test 10 3
The screen displays as follows:
17:06:16 CPU %user %nice %system %iowait %steal %idle
17:06:26 all 0.00 0.00 0.20 0.00 0.00 99.80
17:06:36 all 0.00 0.00 0.20 0.00 0.00 99.8 0
17:06:46 all 0.00 0.00 0.10 0.00 0.00 99.90
Average: all 0.00 0.00 0.17 0.00 0.00 99.83
Output item description:
C PU: all means statistics Information is averaged across all CPUs.
%user: Displays the percentage of total CPU time used by running at the user level (application).
%nice: Displayed at the user level, the percentage of the total CPU time used for nice operations.
%system: The percentage of total CPU time used by running at the kernel level.
%iowait: Displays the percentage of total CPU time spent waiting for I/O operations.
%steal: The percentage of virtual CPU that the hypervisor is waiting for to service another virtual process.
%idle: Displays the percentage of CPU idle time occupied by the total CPU time.
1. If the value of %iowait is too high, it means that the hard disk has an I/O bottleneck
2. If the value of %idle is high but the system response is slow, it may be that the CPU is waiting to allocate memory. , at this time, the memory capacity should be increased
3. If the value of %idle continues to be lower than 1, the system's CPU processing capability is relatively low, indicating that the most important resource in the system is the CPU.
If you want to view the contents of the binary file test, you need to type the following sar command:
sar -u -f test
2. Inode, file and other kernel table monitoring
For example, to sample every 10 seconds for 3 consecutive times to observe the status of the core table, type the following command:
sar -v 10 3
The screen displays as follows :
17:10:49 dentunusd file-nr inode-nr pty-nr
17:10:59 6301 5664 12037 4
17:11:09 6301 5664 12037 4
17:11:19 6301 5664 12037 4
Average: 6301 5664 12037 4
Output description:
dentunusd: directory cache The number of unused entries in
file-nr: the number of file handles used
inode-nr: the number of inode handles used
pty-nr: Number of pty used
3. Memory and swap space monitoring
For example, sample every 10 seconds, sample 3 times continuously, monitor memory paging:
sar -r 10 3
The screen displays as follows:
Output item description:
kbmemfree: This value is the same as in the free command The free value is basically the same, so it does not include the buffer and cache space.
kbmemused: This value is basically the same as the used value in the free command, so it includes the buffer and cache space.
%memused: This value is a percentage of kbmemused and total memory (excluding swap).
kbbuffers and kbcached: These two values are the buffer and cache in the free command.
kbcommit: Guarantee the memory required by the current system, that is, the memory (RAM swap) required to ensure no overflow.
%commit: This value is a percentage of kbcommit and the total memory (including swap).
4. Memory paging monitoring
For example, sample every 10 seconds, sample 3 times continuously, monitor memory paging:
sar -B 10 3
The screen displays as follows:
Output item description:
pgpgin/s: Indicates the number of bytes (KB) replaced from disk or SWAP to memory per second
pgpgout/s: Indicates the number of bytes replaced from memory to disk or SWAP per second (KB)
fault/s: The number of page faults generated by the system per second, that is, the number of primary and secondary page faults Sum of missing pages (major minor)
majflt/s: The number of major missing pages generated per second.
pgfree/s: The number of pages placed in the idle queue per second
pgscank/s: The number of pages scanned by kswapd per second
pgscand/s: The number of pages directly scanned per second
pgsteal/s: per second The number of pages cleared from the cache to meet memory requirements
%vmeff: the percentage of pages cleared per second (pgsteal) to the total scanned pages (pgscank pgscand)
5. I /O and transfer rate monitoring
For example, to sample every 10 seconds, sample 3 times continuously, and report buffer usage, type the following command:
sar -b 10 3
The screen displays as follows:
18:51:05 tps rtps wtps bread/s bwrtn/s
18:51:15 0.00 0.00 0.00 0.00 0.00
18:51:25 1.92 0.00 1.92 0.00 22.65
18:51:35 0.00 0.00 0.00 0.00 0.00
Average: 0.64 0.00 0.64 0.00 7.59
Output item description:
tps: The total amount of I/O transfers from the physical device per second
rtps: The total amount of data read from the physical device per second
wtps: per second The total amount of data written to the physical device
bread/s: The amount of data read from the physical device per second, in blocks/s
bwrtn/s: The amount of data written to the physical device per second The amount of data written by the physical device, in blocks/s
6. Process queue length and average load status monitoring
For example, sample every 10 seconds, sample 3 times continuously, monitor the process Queue length and average load status:
sar -q 10 3
The screen displays as follows:
19:25:50 runq-sz plist-sz ldavg-1 ldavg- 5 ldavg-15
19:26:00 0 259 0.00 0.00 0.00
19:26:10 0 259 0.00 0.00 0.00
19:26:20 0 259 0.00 0.00 0.00
Average: 0 259 0.00 0.00 0.00
Output item description:
runq-sz: The length of the run queue (number of processes waiting to run)
plist-sz: The number of processes and threads in the process list
ldavg-1: System load average in the last minute
ldavg- 5: System load average in the past 5 minutes
ldavg-15: System load average in the past 15 minutes
7. System exchange activity information monitoring
For example, every 10 seconds Sampling once, sampling 3 times continuously, the monitoring system exchanges activity information:
sar -W 10 3
The screen displays as follows:
19:39:50 pswpin/s pswpout /s
19:40:00 0.00 0.00
19:40:10 0.00 0.00
19:40:20 0.00 0.00
Average: 0.00 0.00
Output item description:
pswpin/s: The number of swap pages swapped in by the system per second
pswpout/s: The number of swap pages swapped out by the system per second Number of swap pages
8. Device usage monitoring
For example, to sample every 10 seconds for 3 consecutive times to report device usage, type the following command:
# sar -d 10 3 –p
The screen displays as follows:
17:45:54DEVtpsrd_sec/swr_sec/savgrq-szavgqu-szawaitsvctm%util
17 :46:04scd00.000.000.000.000.000.000.000.00
17:46:04sda0.000.000.000.000.000.000.000.00
17:46:04vg_livedvd -lv_root0.000.000.000.000.000.000 .000.00
17:46:04vg_livedvd-lv_swap0.000.000.000.000.000.000.000.00
Among them:
The parameter -p can print out the disk device names such as sda, hdc and so on. , if the parameter -p is not used, the device node may be dev8-0, dev22-0
tps: the number of I/Os from the physical disk per second. Multiple logical requests will be merged into one I/O O disk request, the size of a transfer is uncertain.
rd_sec/s: The number of sectors read per second.
wr_sec/s: The number of sectors written per second.
avgrq-sz: Average data size (sectors) of each device I/O operation.
avgqu-sz: Average length of disk request queue.
await: Request disk from From the operation until the system completes processing, the average time consumed for each request, including the request queue waiting time, the unit is milliseconds (1 second = 1000 milliseconds).
svctm: The average time the system takes to process each request, excluding The time spent in the request queue.
%util: The percentage of I/O requests in the CPU. The larger the ratio, the more saturated it is.
1. When the value of avgqu-sz is low , the equipment utilization rate is higher.
2. When the value of %util is close to 1%, it means that the device bandwidth is full.
To determine system bottlenecks, sometimes you need to combine several sar command options
If you suspect that there is a CPU bottleneck, you can use sar -u and sar -q to check
If you suspect If there is a bottleneck in the memory, you can use sar -B, sar -r and sar -W to check
If you suspect that there is a bottleneck in I/O, you can use sar -b, sar -u and sar -d to check

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

OnLeaks has now partnered with Android Headlines to provide a first look at the Galaxy S25 Ultra, a few days after a failed attempt to generate upwards of $4,000 from his X (formerly Twitter) followers. For context, the render images embedded below h

Alongside announcing two new smartphones, TCL has also announced a new Android tablet called the NXTPAPER 14, and its massive screen size is one of its selling points. The NXTPAPER 14 features version 3.0 of TCL's signature brand of matte LCD panels

The Vivo Y300 Pro just got fully revealed, and it's one of the slimmest mid-range Android phones with a large battery. To be exact, the smartphone is only 7.69 mm thick but features a 6,500 mAh battery. This is the same capacity as the recently launc

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

Samsung has not offered any hints yet about when it will update its Fan Edition (FE) smartphone series. As it stands, the Galaxy S23 FE remains the company's most recent edition, having been presented at the start of October 2023. However, plenty of

Motorola has released countless devices this year, although only two of them are foldables. For context, while most of the world has received the pair as the Razr 50 and Razr 50 Ultra, Motorola offers them in North America as the Razr 2024 and Razr 2

The Redmi Note 14 Pro Plus is now official as a direct successor to last year'sRedmi Note 13 Pro Plus(curr. $375 on Amazon). As expected, the Redmi Note 14 Pro Plus heads up the Redmi Note 14 series alongside theRedmi Note 14and Redmi Note 14 Pro. Li
