概念简介
磁盘
数据指标
每秒I/O数(IOPS)
对于磁盘来说,一次磁盘的连续读或者连续写称为一次磁盘 I/O, 磁盘的 IOPS
就是每秒磁盘连续读次数和连续写次数之和。当传输小块不连续数据时,该指标有重要参考意义吞吐量、带宽
吞吐量通常指在一秒时间内磁盘传输的总数据量。当传输大块不连续数据时时此值比较有参考意义,此值越高越好 。平均 I/O 数据尺寸
平均 I/O 数据尺寸为吞吐量除以 I/O 数目,该指标对揭示磁盘使用模式有重要意义。一般来说,如果平均 I/O 数据尺寸小于 32K,可认为磁盘使用模式以随机存取为主;如果平均每次 I/O 数据尺寸大于 32K,可认为磁盘使用模式以顺序存取为主。磁盘活动时间百分比(Utilization)
磁盘处于活动时间的百分比,即磁盘利用率,磁盘在数据传输和处理命令(如寻道)处于活动状态。磁盘利用率与资源争用程度成正比,与性能成反比。也就是说磁盘利用率越高,资源争用就越严重,性能也就越差,响应时间就越长。一般来说,如果磁盘利用率超过 70%,应用进程将花费较长的时间等待 I/O完成,因为绝大多数进程在等待过程中将被阻塞或休眠。服务时间(Service Time)
指磁盘读或写操作执行的时间,包括寻道,旋转时延,和数据传输等时间。其大小一般和磁盘性能有关,CPU/ 内存的负荷也会对其有影响,请求过多也会间接导致服务时间的增加。如果该值持续超过 20ms,一般可考虑会对上层应用产生影响。I/O 等待队列长度(Queue Length)
指待处理的 I/O 请求的数目,如果 I/O 请求压力持续超出磁盘处理能力,该值将增加。如果单块磁盘的队列长度持续超过 2,一般认为该磁盘存在I/O性能问题。需要注意的是,如果该磁盘为磁盘阵列虚拟的逻辑驱动器,需要再将该值除以组成这个逻辑驱动器的实际物理磁盘数目,以获得平均单块硬盘的I/O 等待队列长度。等待时间(Wait Time)
指磁盘读或写操作等待执行的时间,即在队列中排队的时间。如果 I/O 请求持续超出磁盘处理能力,意味着来不及处理的 I/O 请求不得不在队列中等待较长时间。
软件简介
fio
- 源码
https://github.com/axboe/fio 安装包
- Debian
- Ubuntu
- Red Hat, CentOS & Co
- Mandriva:
urpmi fio
- Solaris
pkgadd -d http://get.opencsw.org/now
/opt/csw/bin/pkgutil -U
/opt/csw/bin/pkgutil -a fio
/opt/csw/bin/pkgutil -y -i fio - Windows:
http://www.bluestop.org/fio/ .
使用方法
- 常用参数介绍
参数 作用 -filename 指定被测试的磁盘(文件)的路径 -rw 读写方法,包括read、write、randwrite、randread -direct 是否使用I/O缓存(0或1) -iodepth I/O队列深度,设置系统中I/O等待队列中的事件数,通常当磁盘使用率到90%时再增加其值也无显著作用 -ioengine 使用的I/O引擎,Linux一般使用libaio -bs 每次读写的块大小 –runtime 指定fio运行时间 –size 指定fio需要写的数据量大小 -name 设置fio任务的名字 使用实例
fio -filename=/tmp/test -rw=write -iodepth=64 -direct=1 -ioengine=libaio -bs=4K --group_reporting -name=ini -size 1G ini: (g=0): rw=write, bs=4K-4K/4K-4K/4K-4K, ioengine=libaio, iodepth=64 fio-2.14 Starting 1 process Jobs: 1 (f=1): [W(1)] [100.0% done] [0KB/172.4MB/0KB /s] [0/44.2K/0 iops] [eta 00m:00s] ini: (groupid=0, jobs=1): err= 0: pid=24539: Fri Dec 2 17:45:23 2016 write: io=1024.0MB, bw=165286KB/s, iops=41321, runt= 6344msec slat (usec): min=1, max=14419, avg= 1.94, stdev=28.20 clat (usec): min=135, max=91634, avg=1546.36, stdev=2549.34 lat (usec): min=154, max=91635, avg=1548.30, stdev=2549.49 clat percentiles (usec): | 1.00th=[ 796], 5.00th=[ 1160], 10.00th=[ 1176], 20.00th=[ 1192], | 30.00th=[ 1208], 40.00th=[ 1224], 50.00th=[ 1240], 60.00th=[ 1256], | 70.00th=[ 1256], 80.00th=[ 1256], 90.00th=[ 2416], 95.00th=[ 2448], | 99.00th=[ 2512], 99.50th=[13504], 99.90th=[36608], 99.95th=[40192], | 99.99th=[90624] lat (usec) : 250=0.02%, 500=0.02%, 750=0.12%, 1000=3.63% lat (msec) : 2=80.97%, 4=14.49%, 10=0.18%, 20=0.29%, 50=0.24% lat (msec) : 100=0.05% cpu : usr=5.49%, sys=10.53%, ctx=132015, majf=0, minf=13 IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=0.1%, 32=0.1%, >=64=100.0% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.1%, >=64=0.0% issued : total=r=0/w=262144/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0 latency : target=0, window=0, percentile=100.00%, depth=64 Run status group 0 (all jobs): WRITE: io=1024.0MB, aggrb=165286KB/s, minb=165286KB/s, maxb=165286KB/s, mint=6344msec, maxt=6344msec Disk stats (read/write): sda: ios=0/131347, merge=0/123829, ticks=0/188876, in_queue=189008, util=98.45%
测试4k大小文件磁盘读写的IOPS
fio -filename=/tmp/test -rw=write -iodepth=64 -direct=1 -ioengine=libaio -bs=1M --group_reporting -name=ini -size 1G ini: (g=0): rw=write, bs=1M-1M/1M-1M/1M-1M, ioengine=libaio, iodepth=64 fio-2.14 Starting 1 process Jobs: 1 (f=1): [W(1)] [100.0% done] [0KB/114.0MB/0KB /s] [0/114/0 iops] [eta 00m:00s] ini: (groupid=0, jobs=1): err= 0: pid=24667: Fri Dec 2 18:03:27 2016 write: io=1024.0MB, bw=173980KB/s, iops=169, runt= 6027msec slat (usec): min=45, max=371082, avg=850.17, stdev=16289.69 clat (msec): min=7, max=729, avg=375.13, stdev=96.67 lat (msec): min=7, max=729, avg=375.98, stdev=95.62 clat percentiles (msec): | 1.00th=[ 83], 5.00th=[ 202], 10.00th=[ 351], 20.00th=[ 351], | 30.00th=[ 355], 40.00th=[ 359], 50.00th=[ 363], 60.00th=[ 363], | 70.00th=[ 367], 80.00th=[ 400], 90.00th=[ 461], 95.00th=[ 627], | 99.00th=[ 676], 99.50th=[ 701], 99.90th=[ 725], 99.95th=[ 734], | 99.99th=[ 734] lat (msec) : 10=0.20%, 50=0.29%, 100=0.98%, 250=4.39%, 500=85.35% lat (msec) : 750=8.79% cpu : usr=1.19%, sys=1.46%, ctx=901, majf=0, minf=13 IO depths : 1=0.1%, 2=0.2%, 4=0.4%, 8=0.8%, 16=1.6%, 32=3.1%, >=64=93.8% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=99.9%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.1%, >=64=0.0% issued : total=r=0/w=1024/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0 latency : target=0, window=0, percentile=100.00%, depth=64 Run status group 0 (all jobs): WRITE: io=1024.0MB, aggrb=173979KB/s, minb=173979KB/s, maxb=173979KB/s, mint=6027msec, maxt=6027msec Disk stats (read/write): sda: ios=0/1023, merge=0/32, ticks=0/365148, in_queue=398612, util=97.95%
使用8M大小文件测试吞吐量
总结
使用fio测试磁盘需要按照需要得到的结果来选择参数,测试磁盘IOPS时需要将bs取32K以下,测试吞吐量时需要将bs取32K以上,并且iops取值要使测试结果中的磁盘利用率达到100%.
- 更多参考
如何测试云硬盘