监控磁盘IO
2020-07-19 本文已影响0人
wayyyy
磁盘工作原理
-
磁头
读取磁盘表面磁方向和改变其方向,每个盘面有一个磁头,它极其贴近地悬浮在盘面上,但是绝对不与盘面接触,否则会损坏磁头和盘面; -
磁道
磁道是单个盘面上的同心圆 -
柱面
在有多个盘片构成的盘组中,由不同盘片的面,但处于同一半径圆的多个磁道组成的一个圆柱面。 -
扇区
磁盘上的每个磁道被等分为若干个弧段,这些弧段便是硬盘的扇区(Sector)。扇区是读写磁盘最基本的单位。
image.jpg
-
寻道时间
为了访问数据,第一步是:将磁头移动到目标的磁道之上。 -
旋转延时
一旦磁头到达了正确的磁道,就必须等待要访问的扇区转动到读写头下面,该等待时间称为旋转延时。
平均时延通常是磁盘转档一周时间的一半。 -
传输时间
即传输一块数据所需要的时间。
磁盘性能指标
- 使用率
指磁盘处理I/O的时间的百分比,过高的使用率(比如超过 80%),通常意味着磁盘 I/O 存在性能瓶颈。 - 饱和度
是指磁盘处理 I/O 的繁忙程度 - IOPS
Input/Output Per Second,指每秒的 I/O 请求数 - 吞吐量
指每秒的 I/O 请求大小。 - 响应时间
指 I/O 请求从发出到收到响应的间隔时间。
查看磁盘扇区大小信息
fdisk -l

查看磁盘使用情况
df -h

dd 命令生成测试文件测试
- 生成一个4M * 2048 大小的文件
dd if=/dev/zero of=in.txt bs=4M count=2048
磁盘基准测试工具fio
安装
# ubuntu
apt-get install -y fio
# centos
yun install -y fio
测试随机写
测试随机读
fio -name=randread -direct=1 -iodepth=64 -rw=randread \
-ioengine=libaio -bs=4k -size=1G -numjobs=1 \
-runtime=1000 -group_reporting -filename=/dev/vda1
测试顺序读
测试顺序写
报告
- slat ,是指从 I/O 提交到实际执行 I/O 的时长
- latency);clat ,是指从 I/O 提交到 I/O 完成的时长
- lat ,指的是从 fio 创建 I/O 到 I/O 完成的总时长。
iostat
iostat监控的请求数量,并不是我们进程中执行read的数量,而是具体对磁盘扇区操作请求的数量
iostat -x 1

- r/s
The number (after merges) of read requests completed per second for the device- w/s
The number (after merges) of write requests completed per second for the device- rrqm/s
The number of read requests merged per second that were queued to the device- wrqm/s
The number of write requests merged per second that were queued to the device- r_awati
The average time (in milliseconds) for read requests issued to the device to be served. This includes the time spent by the requests in queue and the time spent servicing them.- avgrq-sz
The average size (in kilobytes) of the I/O requests that were issued to the device.- await:平均每个 I/O 花费的时间,包括在队列中等待时间以及磁盘控制器中真正处理的时间
- svctm:每个 I/O 的服务时间。
- util:磁盘的繁忙程度,如果该值很高,表示IO很高。若要看是哪些个进程占用IO,使用下面的
iotop
命令。
sar命令
sar -b 1 3

- tps 磁盘每秒的IO总数
- rtps 每秒钟从磁盘读取的IO总数
- wtps 每秒钟写入磁盘的IO总数
- bread/s 每秒钟从磁盘读取的块总数
- bwrtn/s 每秒钟此写入到磁盘的块总数
iotop
前面的命令都是系统整体展示,iotop
命令类是top 可以查看各个进程的io情况:

-
o
实际正在IO的处理器和线程 -
-p [pid]
监控某个指定的进程
pidstat
定位IO瓶颈问题
- 先用top,free,iostat发现磁盘IO性能瓶颈
- 借助pidstat ,定位出导致瓶颈的进程
- 随后用strace分析进程的I/O行为