018 disk IO performance monitoring / pressure measurement tools (sar, iotop, fio, iostat)

Posted by cape on Sat, 26 Feb 2022 15:46:46 +0100

1. Use the SAR command to view the current disk IO read / write

sar (System Activity Reporter system activity report) is one of the most comprehensive system performance analysis tools on Linux. It can report system activities from many aspects, including file reading and writing, system call usage, disk I/O, CPU efficiency, memory usage, process activity, etc.

(1) sar tool installation

yum install sysstat

(2) sar view disk IO read / write status

# View the current disk IO read / write. It is displayed once every 1 second and 10 times.
sar -b 1 10 

  • The number of times tps # requests data from disk devices per second, including read and write requests, is the sum of rtps and wtps. For efficiency reasons, requests are not processed immediately after each IO is issued, but merged. Here tps refers to the request count after request merging
  • Number of read requests from rtps # per second to disk devices
  • wtps # number of write requests to disk devices per second
  • Number of bytes read from disk by bread # per second
  • bwrtn # number of bytes written to disk per second

2. Use the iotop command to view the disk IO performance

The iotop command is a tool for monitoring disk I/O usage. Iotop is process level IO monitoring.

(1) iotop tool installation

yum install iotop

(2) Common use cases of iotop

  • Iotop -o# only displays the processes or threads that are generating IO;
  • Iotop - D 3 - N 5 # time interval 3 seconds, output 5 times;
  • iotop -botq -p 8382 # outputs the process IO with pid 8382

(3) Description of iotop optional parameters

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -o, --only            only show processes or threads actually doing I/O
  -b, --batch           non-interactive mode
  -n NUM, --iter=NUM    number of iterations before ending [infinite]
  -d SEC, --delay=SEC   delay between iterations [1 second]
  -p PID, --pid=PID     processes/threads to monitor [all]
  -u USER, --user=USER  users to monitor [all]
  -P, --processes       only show processes, not all threads
  -a, --accumulated     show accumulated I/O instead of bandwidth
  -k, --kilobytes       use kilobytes instead of a human friendly unit
  -t, --time            add a timestamp on each line (implies --batch)
  -q, --quiet           suppress some lines of header (implies --batch)

3 disk performance pressure measuring tool fio

(1) fio tool installation

 yum install fio

(2) IOPS pressure measurement example

  • (/ data/test is the reading and writing directory of pressure measurement data)

    fio -directory=/data/test -direct=1 -iodepth 10 -thread -rw=randwrite -ioengine=psync -bs=4k -size=2G -numjobs=10 -runtime=180 -group_reporting -name=rand_write

(3) Bandwidth pressure measurement

  • (/ data/test is the reading and writing directory of pressure measurement data)

    fio -directory=/data/test -direct=1 -iodepth 10 -thread -rw=randwrite -ioengine=psync -bs=4096k -size=2G -numjobs=10 -runtime=180 -group_reporting -name=rand_write

4. Common use cases of iostat

iostat is system level IO monitoring, while iotop is process level IO monitoring.

iostat -d -k 1 10          #View TPS and throughput information (disk read / write speed in KB)
iostat -d -m 2             #View TPS and throughput information (disk read / write speed in MB)
iostat -d -x -k 1 10       #Check device utilization (% util), response time (await) 
iostat -c 1 10             #View cpu status

5. Simply verify whether the disk fails

touch an empty file on the target disk to see if it cannot be written due to disk failure.

6. Check which disk the file belongs to

Check which disk the file belongs to

df /data/

7 appendix

sar use: https://www.cnblogs.com/zcx-python/p/9001630.html
iostat use: https://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858810.html
IO Of test tools fio Detailed explanation: https://www.cnblogs.com/raykuan/p/6914748.html

8 summary

Disk IO performance monitoring / pressure measurement tools commonly used include sar, iotop, fio and iostat. This article is only a simple record, involving the use of relevant commands. It does not do too much detailed in-depth use practice instructions, but only plays a simple role of throwing a brick to attract jade.

"Code farmer who does not throw the pot" is original. Please indicate the source of reprint. Unauthorized commercial use is prohibited! Please pay attention to GZH with the same name!

Topics: Back-end