数据库是一个IO密集型的应用(在热点数据量比服务器可用内存大得多的情况下),IO的性能指标,是应用性能、用户体验的极其关键的一个因素,建议参考如下测试模型,对于FIO测试,标红的参数不能调整,对于单个服务器并发数超过1000的系统,且热点数据只有50%常驻内存的数据库服务器,要求该测试指标IOPS高于5000,吞吐量高于150MBPS。
(测试一)dd测试
dd if=/dev/zero of=test bs=32k count=40k oflag=dsync
参数详解:
- if=文件名:输入文件名,默认为标准输入。即指定源文件。
- of=文件名:输出文件名,默认为标准输出。即指定目的文件。
- ibs=bytes:一次读入bytes个字节,即指定一个块大小为bytes个字节。
obs=bytes:一次输出bytes个字节,即指定一个块大小为bytes个字节。
bs=bytes:同时设置读入/输出的块大小为bytes个字节。 - count=blocks:仅拷贝blocks个块,块大小等于ibs指定的字节数。
- oflag=DSYNC, IO模式,一般来说数据库有两种IO模型,直接IO和缓存IO。直接IO是对应的输出文件绕开Linux的内存buffer,直接写入磁盘。缓存IO是输出的文件先写入缓存,然后由操作系统的调度落盘。我们这里需要测试裸磁盘的IO,因此直接IO更具有代表性。
测试结果分析:磁盘每秒写入速度,174 MB。一共测试了1.3GB的写入,耗时7.72秒。
(测试二)fio测试
fio -filename=filename -direct=1 -iodepth 1 -thread -rw=randrw -ioengine=psync -bs=32k -size=5G -numjobs=32 -runtime=10 -group_reporting -name=mytest
参数详解:
- -filename=filename 测试输出的文件名字
- -direct=1 等同于dd的dsync,采用直接IO的模式,绕开操作系统内存buffer
- -iodepth 1 当队列深度为1时,增加队列深度,可以测试出磁盘的峰值。
- -thread 多线程方式测试。
- -rw=randrw 随机读写
- -ioengine=psync 测试过程绕过机器自带的buffer,使测试结果更真实(Linux在读写时,数据会先写到缓存,再在后台写到硬盘,读的时候也是优先从缓存中读,这样访问速度会加快,但是一旦掉电,缓存中数据就会清空,所有一种模式为DirectIO,可以跳过缓存,直接读写硬盘)
- -bs=32k 单次io的块文件大小为32K
- -size=5G 输出测试文件大小5G
- -numjobs=32 并发任务32个
- -runtime=10 测试时间为10s
- -group_reporting 关于显示结果的,汇总每个进程的信息
- -name=mytest 测试结果命名mytest
mytest: (g=0): rw=randrw, bs=(R) 32.0KiB-32.0KiB, (W) 32.0KiB-32.0KiB, (T) 32.0KiB-32.0KiB, ioengine=psync, iodepth=1
...
fio-3.7
Starting 32 threads
mytest: Laying out IO file (1 file / 5120MiB)
Jobs: 5 (f=5): [_(1),m(1),_(4),m(2),_(5),m(1),_(7),E(1),_(6),m(1),_(3)][4.4%][r=850KiB/s,w=0KiB/s][r=26,w=0 IOPS][eta 04m:18s]
mytest: (groupid=0, jobs=32): err= 0: pid=21995: Fri Oct 14 16:39:55 2022
read: IOPS=1484, BW=46.4MiB/s (48.6MB/s)(522MiB/11247msec)
clat (usec): min=43, max=1337.3k, avg=19459.88, stdev=43775.36
lat (usec): min=43, max=1337.3k, avg=19460.10, stdev=43775.36
clat percentiles (usec):
| 1.00th=[ 64], 5.00th=[ 67], 10.00th=[ 78],
| 20.00th=[ 1811], 30.00th=[ 3916], 40.00th=[ 5932],
| 50.00th=[ 8094], 60.00th=[ 11338], 70.00th=[ 15926],
| 80.00th=[ 23725], 90.00th=[ 44303], 95.00th=[ 76022],
| 99.00th=[ 191890], 99.50th=[ 248513], 99.90th=[ 455082],
| 99.95th=[ 599786], 99.99th=[1317012]
bw ( KiB/s): min= 64, max= 3776, per=3.52%, avg=1671.08, stdev=658.68, samples=638
iops : min= 2, max= 118, avg=52.17, stdev=20.58, samples=638
write: IOPS=1494, BW=46.7MiB/s (48.0MB/s)(525MiB/11247msec)
clat (usec): min=39, max=221376, avg=185.77, stdev=3436.55
lat (usec): min=39, max=221378, avg=187.98, stdev=3436.69
clat percentiles (usec):
| 1.00th=[ 61], 5.00th=[ 63], 10.00th=[ 64], 20.00th=[ 66],
| 30.00th=[ 67], 40.00th=[ 69], 50.00th=[ 70], 60.00th=[ 72],
| 70.00th=[ 74], 80.00th=[ 80], 90.00th=[ 100], 95.00th=[ 112],
| 99.00th=[ 172], 99.50th=[ 347], 99.90th=[ 47973], 99.95th=[100140],
| 99.99th=[217056]
bw ( KiB/s): min= 64, max= 4224, per=3.53%, avg=1688.79, stdev=808.51, samples=637
iops : min= 2, max= 132, avg=52.72, stdev=25.27, samples=637
lat (usec) : 50=0.21%, 100=51.21%, 250=6.12%, 500=0.50%, 750=0.41%
lat (usec) : 1000=0.23%
lat (msec) : 2=1.76%, 4=4.90%, 10=12.53%, 20=10.18%, 50=7.60%
lat (msec) : 100=2.73%, 250=1.37%, 500=0.20%, 750=0.03%
cpu : usr=0.06%, sys=0.35%, ctx=33902, majf=0, minf=7
IO depths : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.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.0%, >=64=0.0%
issued rwts: total=16693,16811,0,0 short=0,0,0,0 dropped=0,0,0,0
latency : target=0, window=0, percentile=100.00%, depth=1
Run status group 0 (all jobs):
READ: bw=46.4MiB/s (48.6MB/s), 46.4MiB/s-46.4MiB/s (48.6MB/s-48.6MB/s), io=522MiB (547MB), run=11247-11247msec
WRITE: bw=46.7MiB/s (48.0MB/s), 46.7MiB/s-46.7MiB/s (48.0MB/s-48.0MB/s), io=525MiB (551MB), run=11247-11247msec
Disk stats (read/write):
dm-2: ios=16798/16827, merge=0/0, ticks=328943/2649, in_queue=337201, util=99.19%, aggrios=16797/16828, aggrmerge=0/0, aggrticks=335346/2655, aggrin_queue=338244, aggrutil=99.22%
sdb: ios=16797/16828, merge=0/0, ticks=335346/2655, in_queue=338244, util=99.22%