背景
因为是虚拟机,所以对于性能很虚。借助fio进行测试
安装
yum install fio
测试
以下测试 numjobs均为1。 这是最理想的情况。现实中不会只有一个job进行io。一定会竞争,当竞争激烈时cpu就飙了。
为了快速得到测试结果先这样测。
如何模拟现实中的IO
通常情况下,应用程序的 I/O 都是读写并行的,而且每次的 I/O 大小也不一定相同。所以,理想情况并不能精确模拟应用程序的 I/O 模式。
那怎么才能精确模拟应用程序的 I/O 模式呢?
幸运的是,fio 支持 I/O 的重放。借助前面提到过的 blktrace,再配合上 fio,就可以实现对应用程序 I/O 模式的基准测试。你需要先用 blktrace ,记录磁盘设备的 I/O 访问情况;然后使用 fio ,重放 blktrace 的记录。
fio参数解释
direct,表示是否跳过系统缓存。上面示例中,我设置的 1 ,就表示跳过系统缓存。 iodepth,表示使用异步 I/O(asynchronous I/O,简称 AIO)时,同时发出的 I/O 请求上限。在上面的示例中,我设置的是 64。 rw,表示 I/O 模式。我的示例中, read/write 分别表示顺序读 / 写,而 randread/randwrite 则分别表示随机读 / 写。 ioengine,表示 I/O 引擎,它支持同步(sync)、异步(libaio)、内存映射(mmap)、网络(net)等各种 I/O 引擎。上面示例中,我设置的 libaio 表示使用异步 I/O。 bs,表示 I/O 的大小。示例中,我设置成了 4K(这也是默认值)。 filename,表示文件路径,当然,它可以是磁盘路径(测试磁盘性能),也可以是文件路径(测试文件系统性能)。示例中,我把它设置成了磁盘 /dev/sdb。不过注意,用磁盘路径测试写,会破坏这个磁盘中的文件系统,所以在使用前,你一定要事先做好数据备份。
【1】随机读测试
fio -name=randread -direct=1 -iodepth=64 -rw=randread -ioengine=libaio -bs=4k -size=1G -numjobs=1-runtime=1000 -group_reporting -filename=/dev/sda2
randread: (g=0): rw=randread, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=libaio, iodepth=64 fio-3.7 Starting 1 process Jobs: 1 (f=0): [f(1)][100.0%][r=27.7MiB/s,w=0KiB/s][r=7088,w=0 IOPS][eta 00m:00s] randread: (groupid=0, jobs=1): err= 0: pid=8494: Mon Dec 26 15:38:53 2022 read: IOPS=7318, BW=28.6MiB/s (29.0MB/s)(1024MiB/35817msec) slat (nsec): min=1605, max=33837k, avg=130443.48, stdev=265911.59 clat (usec): min=205, max=42456, avg=8608.58, stdev=2235.62 lat (usec): min=209, max=42601, avg=8739.48, stdev=2256.27 clat percentiles (usec): | 1.00th=[ 6718], 5.00th=[ 6915], 10.00th=[ 7373], 20.00th=[ 8094], | 30.00th=[ 8160], 40.00th=[ 8225], 50.00th=[ 8291], 60.00th=[ 8356], | 70.00th=[ 8455], 80.00th=[ 8586], 90.00th=[ 9110], 95.00th=[ 9765], | 99.00th=[20579], 99.50th=[24249], 99.90th=[34341], 99.95th=[35914], | 99.99th=[42206] bw ( KiB/s): min=24742, max=36383, per=99.54%, avg=29141.79, stdev=1966.38, samples=71 iops : min= 6185, max= 9095, avg=7285.18, stdev=491.52, samples=71 lat (usec) : 250=0.01%, 500=0.01%, 750=0.01%, 1000=0.01% lat (msec) : 2=0.01%, 4=0.01%, 10=95.64%, 20=3.25%, 50=1.09% cpu : usr=0.08%, sys=16.38%, ctx=235543, majf=0, minf=74 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 rwts: total=262144,0,0,0 short=0,0,0,0 dropped=0,0,0,0 latency : target=0, window=0, percentile=100.00%, depth=64 Run status group 0 (all jobs): READ: bw=28.6MiB/s (29.0MB/s), 28.6MiB/s-28.6MiB/s (29.0MB/s-29.0MB/s), io=1024MiB (1074MB), run=35817-35817msec Disk stats (read/write): sda: ios=260147/221, merge=246/218, ticks=46995/85, in_queue=2680, util=99.88%
【2】随机写测试
对于磁盘分区需要先umount
fio -name=randwrite -direct=1 -iodepth=64 -rw=randwrite -ioengine=libaio -bs=4k -size=1G -numjobs1 -runtime=1000 -group_reporting -filename=/dev/sda2
fioo -name=randwrite -direct=1 -iodepth=64 -rw=randwrite -ioengine=libaio -bs=4k -size=1G -numjobs1 -runtime=1000 -group_reporting -filename=/dev/sda2 randwrite: (g=0): rw=randwrite, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=libaio, iodepth=64 fio-3.7 fio: /dev/sda2 appears mounted, and 'allow_mounted_write' isn't set. Aborting. Run status group 0 (all jobs): ⚡ root@pigsty2-179 /etc/yum.repos.d fio -name=randwrite -direct=1 -iodepth=64 -rw=randwrite -ioengine=libaio -bs=4k -size=1G -numjobs=1 -runtime=1000 -group_reporting -filename=/data ✘ ⚡ root@pigsty2-179 /etc/yum.repos.d umount /data ⚡ root@pigsty2-179 /etc/yum.repos.d df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 32G 0 32G 0% /dev tmpfs 32G 0 32G 0% /dev/shm tmpfs 32G 8.5M 32G 1% /run tmpfs 32G 0 32G 0% /sys/fs/cgroup /dev/sda1 40G 3.5G 37G 9% / tmpfs 6.3G 0 6.3G 0% /run/user/0 ⚡ root@pigsty2-179 /etc/yum.repos.d ⚡ root@pigsty2-179 /etc/yum.repos.d fio -name=randwrite -direct=1 -iodepth=64 -rw=randwrite -ioengine=libaio -bs=4k -size=1G -numjobs=1 -runtime=1000 -group_reporting -filename=/dev/sda2 randwrite: (g=0): rw=randwrite, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=libaio, iodepth=64 fio-3.7 Starting 1 process Jobs: 1 (f=1): [w(1)][100.0%][r=0KiB/s,w=27.9MiB/s][r=0,w=7132 IOPS][eta 00m:00s] randwrite: (groupid=0, jobs=1): err= 0: pid=10170: Mon Dec 26 15:43:30 2022 write: IOPS=7017, BW=27.4MiB/s (28.7MB/s)(1024MiB/37354msec) slat (usec): min=3, max=18306, avg=138.47, stdev=71.90 clat (usec): min=219, max=73243, avg=8973.12, stdev=1054.38 lat (usec): min=226, max=73782, avg=9111.89, stdev=1069.81 clat percentiles (usec): | 1.00th=[ 8225], 5.00th=[ 8586], 10.00th=[ 8717], 20.00th=[ 8717], | 30.00th=[ 8848], 40.00th=[ 8848], 50.00th=[ 8848], 60.00th=[ 8979], | 70.00th=[ 8979], 80.00th=[ 9110], 90.00th=[ 9241], 95.00th=[ 9503], | 99.00th=[10683], 99.50th=[10945], 99.90th=[11731], 99.95th=[33817], | 99.99th=[57934] bw ( KiB/s): min=19737, max=28958, per=99.64%, avg=27969.24, stdev=1167.02, samples=74 iops : min= 4934, max= 7239, avg=6991.97, stdev=291.68, samples=74 lat (usec) : 250=0.01%, 500=0.01%, 750=0.01%, 1000=0.01% lat (msec) : 2=0.01%, 4=0.01%, 10=97.52%, 20=2.38%, 50=0.06% lat (msec) : 100=0.03% cpu : usr=3.07%, sys=8.69%, ctx=261529, majf=0, minf=11 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 rwts: total=0,262144,0,0 short=0,0,0,0 dropped=0,0,0,0 latency : target=0, window=0, percentile=100.00%, depth=64 Run status group 0 (all jobs): WRITE: bw=27.4MiB/s (28.7MB/s), 27.4MiB/s-27.4MiB/s (28.7MB/s-28.7MB/s), io=1024MiB (1074MB), run=37354-37354msec Disk stats (read/write): sda: ios=133/260073, merge=0/238, ticks=235/49798, in_queue=299, util=100.00%
【3】 顺序读测试
fio -name=read -direct=1 -iodepth=64 -rw=read -ioengine=libaio -bs=4k -size=1G -numjobs=1 -runtim=1000 -group_reporting -filename=/dev/sda2
fio -name=read -direct=1 -iodepth=64 -rw=read -ioengine=libaio -bs=4k -size=1G -numjobs=1 -runtim=1000 -group_reporting -filename=/dev/sda2 read: (g=0): rw=read, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=libaio, iodepth=64 fio-3.7 Starting 1 process Jobs: 1 (f=1) read: (groupid=0, jobs=1): err= 0: pid=10946: Mon Dec 26 15:45:13 2022 read: IOPS=111k, BW=435MiB/s (456MB/s)(1024MiB/2356msec) slat (nsec): min=1444, max=505137, avg=4120.63, stdev=18433.16 clat (usec): min=282, max=1462, avg=569.87, stdev=77.20 lat (usec): min=283, max=1464, avg=574.22, stdev=77.41 clat percentiles (usec): | 1.00th=[ 457], 5.00th=[ 482], 10.00th=[ 494], 20.00th=[ 510], | 30.00th=[ 529], 40.00th=[ 537], 50.00th=[ 553], 60.00th=[ 570], | 70.00th=[ 586], 80.00th=[ 627], 90.00th=[ 676], 95.00th=[ 717], | 99.00th=[ 799], 99.50th=[ 873], 99.90th=[ 1057], 99.95th=[ 1156], | 99.99th=[ 1434] bw ( KiB/s): min=435305, max=446666, per=99.49%, avg=442808.75, stdev=5308.66, samples=4 iops : min=108826, max=111666, avg=110702.00, stdev=1327.16, samples=4 lat (usec) : 500=12.83%, 750=84.96%, 1000=2.01% lat (msec) : 2=0.20% cpu : usr=17.32%, sys=25.44%, ctx=9010, majf=0, minf=74 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 rwts: total=262144,0,0,0 short=0,0,0,0 dropped=0,0,0,0 latency : target=0, window=0, percentile=100.00%, depth=64 Run status group 0 (all jobs): READ: bw=435MiB/s (456MB/s), 435MiB/s-435MiB/s (456MB/s-456MB/s), io=1024MiB (1074MB), run=2356-2356msec Disk stats (read/write): sda: ios=8232/2, merge=230342/0, ticks=3074/1, in_queue=0, util=95.73%
【4】 顺序写测试
fio -name=write -direct=1 -iodepth=64 -rw=write -ioengine=libaio -bs=4k -size=1G -numjobs=1 -runtme=1000 -group_reporting -filename=/dev/sda2 write: (g=0): rw=write, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=libaio, iodepth=64 fio-3.7 Starting 1 process Jobs: 1 (f=1): [W(1)][100.0%][r=0KiB/s,w=386MiB/s][r=0,w=98.7k IOPS][eta 00m:00s] write: (groupid=0, jobs=1): err= 0: pid=11780: Mon Dec 26 15:47:30 2022 write: IOPS=64.3k, BW=251MiB/s (263MB/s)(1024MiB/4077msec) slat (nsec): min=1478, max=456245, avg=5188.01, stdev=19433.33 clat (usec): min=198, max=137994, avg=988.56, stdev=2721.27 lat (usec): min=294, max=137996, avg=994.00, stdev=2724.30 clat percentiles (usec): | 1.00th=[ 494], 5.00th=[ 529], 10.00th=[ 553], 20.00th=[ 586], | 30.00th=[ 619], 40.00th=[ 644], 50.00th=[ 668], 60.00th=[ 685], | 70.00th=[ 709], 80.00th=[ 742], 90.00th=[ 799], 95.00th=[ 2737], | 99.00th=[ 6849], 99.50th=[ 7373], 99.90th=[ 23200], 99.95th=[ 33817], | 99.99th=[137364] bw ( KiB/s): min=35235, max=404008, per=98.76%, avg=253998.25, stdev=152575.81, samples=8 iops : min= 8808, max=101002, avg=63499.25, stdev=38144.21, samples=8 lat (usec) : 250=0.01%, 500=1.46%, 750=81.89%, 1000=9.19% lat (msec) : 2=1.81%, 4=1.74%, 10=3.57%, 20=0.21%, 50=0.08% lat (msec) : 100=0.02%, 250=0.02% cpu : usr=11.46%, sys=23.75%, ctx=15521, majf=0, minf=12 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 rwts: total=0,262144,0,0 short=0,0,0,0 dropped=0,0,0,0 latency : target=0, window=0, percentile=100.00%, depth=64 Run status group 0 (all jobs): WRITE: bw=251MiB/s (263MB/s), 251MiB/s-251MiB/s (263MB/s-263MB/s), io=1024MiB (1074MB), run=4077-4077msec Disk stats (read/write): sda: ios=20/16703, merge=0/226614, ticks=5/5303, in_queue=421, util=97.89%
numjobs=5 测试
随机读
fio -name=randread -direct=1 -iodepth=64 -rw=randread -ioengine=libaio -bs=4k -size=1G -numjobs=5 -runtime=1000 -group_reporting -filename=/dev/sda2 randread: (g=0): rw=randread, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=libaio, iodepth=64 ... fio-3.7 Starting 5 processes Jobs: 3 (f=3): [r(2),_(2),r(1)][98.5%][r=30.6MiB/s,w=0KiB/s][r=7839,w=0 IOPS][eta 00m:03s] randread: (groupid=0, jobs=5): err= 0: pid=18938: Mon Dec 26 16:11:20 2022 read: IOPS=6774, BW=26.5MiB/s (27.7MB/s)(5120MiB/193491msec) slat (usec): min=2, max=9616, avg=729.70, stdev=198.85 clat (usec): min=173, max=148709, avg=46298.41, stdev=8574.87 lat (usec): min=178, max=150138, avg=47028.78, stdev=8701.73 clat percentiles (msec): | 1.00th=[ 34], 5.00th=[ 36], 10.00th=[ 37], 20.00th=[ 44], | 30.00th=[ 45], 40.00th=[ 45], 50.00th=[ 45], 60.00th=[ 46], | 70.00th=[ 47], 80.00th=[ 50], 90.00th=[ 55], 95.00th=[ 63], | 99.00th=[ 77], 99.50th=[ 82], 99.90th=[ 101], 99.95th=[ 109], | 99.99th=[ 122] bw ( KiB/s): min= 3056, max=13445, per=20.00%, avg=5419.74, stdev=728.08, samples=1924 iops : min= 764, max= 3361, avg=1354.88, stdev=182.01, samples=1924 lat (usec) : 250=0.01%, 500=0.01%, 750=0.01%, 1000=0.01% lat (msec) : 2=0.01%, 4=0.01%, 10=0.27%, 20=0.20%, 50=80.48% lat (msec) : 100=18.94%, 250=0.10% cpu : usr=0.36%, sys=2.98%, ctx=1308829, majf=0, minf=377 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 rwts: total=1310720,0,0,0 short=0,0,0,0 dropped=0,0,0,0 latency : target=0, window=0, percentile=100.00%, depth=64 Run status group 0 (all jobs): READ: bw=26.5MiB/s (27.7MB/s), 26.5MiB/s-26.5MiB/s (27.7MB/s-27.7MB/s), io=5120MiB (5369MB), run=193491-193491msec Disk stats (read/write): sda: ios=1306124/427, merge=2632/5, ticks=338644/791, in_queue=1036, util=100.00%
随机写
fio -name=randwrite -direct=1 -iodepth=64 -rw=randwrite -ioengine=libaio -bs=4k -size=1G -numjobs=5 -runtime=1000 -group_reporting -filename=/dev/sda2 randwrite: (g=0): rw=randwrite, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=libaio, iodepth=64 ... fio-3.7 Starting 5 processes Jobs: 3 (f=3): [w(3),_(2)][98.1%][r=0KiB/s,w=27.8MiB/s][r=0,w=7104 IOPS][eta 00m:04s] randwrite: (groupid=0, jobs=5): err= 0: pid=21669: Mon Dec 26 16:18:55 2022 write: IOPS=6276, BW=24.5MiB/s (25.7MB/s)(5120MiB/208839msec) slat (usec): min=2, max=103111, avg=788.15, stdev=312.09 clat (usec): min=203, max=237897, avg=49999.91, stdev=9339.97 lat (usec): min=211, max=239240, avg=50788.71, stdev=9471.33 clat percentiles (msec): | 1.00th=[ 36], 5.00th=[ 38], 10.00th=[ 42], 20.00th=[ 46], | 30.00th=[ 47], 40.00th=[ 47], 50.00th=[ 49], 60.00th=[ 51], | 70.00th=[ 53], 80.00th=[ 55], 90.00th=[ 58], 95.00th=[ 63], | 99.00th=[ 83], 99.50th=[ 93], 99.90th=[ 117], 99.95th=[ 131], | 99.99th=[ 222] bw ( KiB/s): min= 2560, max=14914, per=19.99%, avg=5018.74, stdev=642.60, samples=2077 iops : min= 640, max= 3728, avg=1254.63, stdev=160.67, samples=2077 lat (usec) : 250=0.01%, 500=0.01%, 750=0.01%, 1000=0.01% lat (msec) : 2=0.01%, 4=0.01%, 10=0.22%, 20=0.37%, 50=57.28% lat (msec) : 100=41.84%, 250=0.28% cpu : usr=0.47%, sys=3.10%, ctx=1310305, majf=0, minf=52 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 rwts: total=0,1310720,0,0 short=0,0,0,0 dropped=0,0,0,0 latency : target=0, window=0, percentile=100.00%, depth=64 Run status group 0 (all jobs): WRITE: bw=24.5MiB/s (25.7MB/s), 24.5MiB/s-24.5MiB/s (25.7MB/s-25.7MB/s), io=5120MiB (5369MB), run=208839-208839msec Disk stats (read/write): sda: ios=40/1306810, merge=0/2624, ticks=12/364641, in_queue=2495, util=100.00%
顺序读
fio -name=read -direct=1 -iodepth=64 -rw=read -ioengine=libaio -bs=4k -size=1G -numjobs=5 -runtime=1000 -group_reporting -filename=/dev/sda2 read: (g=0): rw=read, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=libaio, iodepth=64 ... fio-3.7 Starting 5 processes Jobs: 2 (f=2): [_(1),R(1),_(1),R(1),_(1)][100.0%][r=393MiB/s,w=0KiB/s][r=101k,w=0 IOPS][eta 00m:00s] read: (groupid=0, jobs=5): err= 0: pid=31699: Mon Dec 26 16:43:40 2022 read: IOPS=110k, BW=428MiB/s (449MB/s)(5120MiB/11950msec) slat (nsec): min=1751, max=59508k, avg=29497.74, stdev=296029.22 clat (usec): min=203, max=64850, avg=2852.81, stdev=1849.92 lat (usec): min=216, max=64853, avg=2882.43, stdev=1852.10 clat percentiles (usec): | 1.00th=[ 758], 5.00th=[ 1074], 10.00th=[ 1352], 20.00th=[ 2040], | 30.00th=[ 2376], 40.00th=[ 2573], 50.00th=[ 2704], 60.00th=[ 2835], | 70.00th=[ 2999], 80.00th=[ 3228], 90.00th=[ 3949], 95.00th=[ 5014], | 99.00th=[ 8848], 99.50th=[11338], 99.90th=[23987], 99.95th=[35390], | 99.99th=[59507] bw ( KiB/s): min=65708, max=108151, per=19.98%, avg=87663.03, stdev=8082.48, samples=115 iops : min=16427, max=27037, avg=21915.53, stdev=2020.61, samples=115 lat (usec) : 250=0.01%, 500=0.11%, 750=0.83%, 1000=2.55% lat (msec) : 2=15.80%, 4=70.99%, 10=9.00%, 20=0.59%, 50=0.12% lat (msec) : 100=0.01% cpu : usr=3.72%, sys=6.98%, ctx=49477, majf=0, minf=378 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 rwts: total=1310720,0,0,0 short=0,0,0,0 dropped=0,0,0,0 latency : target=0, window=0, percentile=100.00%, depth=64 Run status group 0 (all jobs): READ: bw=428MiB/s (449MB/s), 428MiB/s-428MiB/s (449MB/s-449MB/s), io=5120MiB (5369MB), run=11950-11950msec Disk stats (read/write): sda: ios=27102/119, merge=1279178/0, ticks=21450/236, in_queue=8497, util=99.25%
顺序写
blktrace+fio 模拟真实IO场景
先把
随机读 / 随机写 / 顺序读 / 顺序写 录制下来
再自由组合模拟真是情况
通过 blktrace+fio 的组合使用,得到了应用程序 I/O 模式的基准测试报告。
查看 blktrace 记录的结果
# 随机读 fio -name=randread -direct=1 -iodepth=64 -rw=randread -ioengine=libaio -bs=4k -size=1G -numjobs=5 -runtime=1000 -group_reporting -filename=/dev/sda2 # 随机写 fio -name=randwrite -direct=1 -iodepth=64 -rw=randwrite -ioengine=libaio -bs=4k -size=1G -numjobs=5 -runtime=1000 -group_reporting -filename=/dev/sda2 # 顺序读 fio -name=read -direct=1 -iodepth=64 -rw=read -ioengine=libaio -bs=4k -size=1G -numjobs=5 -runtime=1000 -group_reporting -filename=/dev/sda2 # 顺序写 fio -name=write -direct=1 -iodepth=64 -rw=write -ioengine=libaio -bs=4k -size=1G -numjobs=5 -runtime=1000 -group_reporting -filename=/dev/sda2 使用 blktrace 跟踪磁盘上述压测的I/O $ blktrace /dev/sda2 # 查看 blktrace 记录的结果 ll total 492M -rw-r--r-- 1 root root 84M Dec 26 16:11 sda2.blktrace.0 -rw-r--r-- 1 root root 54M Dec 26 16:11 sda2.blktrace.1 -rw-r--r-- 1 root root 43M Dec 26 16:11 sda2.blktrace.2 -rw-r--r-- 1 root root 54M Dec 26 16:11 sda2.blktrace.3 -rw-r--r-- 1 root root 26M Dec 26 16:11 sda2.blktrace.4 -rw-r--r-- 1 root root 82M Dec 26 16:11 sda2.blktrace.5 -rw-r--r-- 1 root root 85M Dec 26 16:11 sda2.blktrace.6 -rw-r--r-- 1 root root 67M Dec 26 16:11 sda2.blktrace.7
将结果转化为二进制文件
# 将结果转化为二进制文件 $ blkparse sda -d sda2.bin
重复上述机种读写操作之后,录制的IO流量如下
ll -ths total 2.0G 138M -rw-r--r-- 1 root root 138M Dec 26 16:52 sda2-write.bin 123M -rw-r--r-- 1 root root 123M Dec 26 16:46 sda2-read.bin 134M -rw-r--r-- 1 root root 134M Dec 26 16:42 sda2-randomwrite.bin 1.6G -rw-r--r-- 1 root root 1.6G Dec 26 16:39 sda2-randomread.bin
使用 fio 重放日志
cd /opt/fio/randomwrite
# 使用 fio 重放日志 $ fio --name=replay --filename=/dev/sda2 --direct=1 --read_iolog=sda2-randomread.bin $ fio --name=replay --filename=/dev/sda2 --direct=1 --read_iolog=sda2-randomwrite.bin
结论
随机读 | 随机写 | 顺序读 | 顺序写 | 速度 |
√ | 14.8MB/s | |||
√ | 18.1MB/s | |||