zhangguanzhang's Blog

fio 静态编译和基础使用

字数统计: 2.3k阅读时长: 12 min
2021/09/02

由来

amd64,arm64 的静态编译和基础使用

buildx 使用

见文章 buildx 使用

编译

buildx Dockerfile 构建:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
FROM ubuntu as build
WORKDIR /opt
ARG VER=fio-3.29
#ARG DEBIAN_FRONTEND=noninteractive
RUN if [ -e /etc/apt/sources.list ];then sed -ri 's/[a-zA-Z0-9.]+(debian.org|ubuntu.com)/mirrors.aliyun.com/g' /etc/apt/sources.list; fi && \
export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install -y git gcc make cmake libaio1 libaio-dev zlib1g zlib1g-dev
RUN git clone https://github.com/axboe/fio.git && \
cd fio && \
git checkout ${VER}
RUN cd fio && \
./configure --build-static && \
make && make install && \
cp `which fio` /fio-$(dpkg --print-architecture)

FROM scratch AS bin
COPY --from=build /fio-* /

构建

1
2
3
docker buildx build  . --platform linux/amd64,linux/arm64 \
--target bin --output . \
--build-arg=VER=fio-3.29

结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ ll
total 4
-rw-r--r-- 1 root root 660 Feb 9 21:32 Dockerfile
drwxr-xr-x 2 root root 23 Feb 9 21:44 linux_amd64
drwxr-xr-x 2 root root 23 Feb 9 21:44 linux_arm64
$ tree .
.
├── Dockerfile
├── linux_amd64
│   └── fio-amd64
└── linux_arm64
└── fio-arm64
$ ldd linux_amd64/fio-amd64 linux_arm64/fio-arm64
linux_amd64/fio-amd64:
not a dynamic executable
linux_arm64/fio-arm64:
not a dynamic executable
$ file linux_amd64/fio-amd64 linux_arm64/fio-arm64
linux_amd64/fio-amd64: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=30dddb2ae5ca67f3533b8e54aa0900ee701c7b01, for GNU/Linux 3.2.0, not stripped
linux_arm64/fio-arm64: ELF 64-bit LSB executable, ARM aarch64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=6a644c0696153f99d2d527948e0400720742a002, for GNU/Linux 3.7.0, not stripped
$

符号链接可以 strip -s $(which nginx) 去掉减少大小。

fio 测速说明

1
2
3
4
5
6
7
--eta-newline=5s   5s切到新的行继续输出速度状态
--filename 写入到哪个文件,必须使用绝对路径
--rw=write 前面没带rand就是顺序,此处是顺序写,例如rw则是顺序读写,randwrite则是随机写,测速推荐顺序写
--ioengine libaio 是多线程内核态,速度很快,不推荐用它测速,推荐使用 psync 单线程测速
--runtime 秒数,测速的时间
--time_based 时间算速度
--output-format=json 如果有取输出的话,可以带上这个,带上这个就是结束后输出json,上面的 --eta-newline 就没有意义了

测速注意文件落地路径,ioengine 不要用 libaio 这种内核态的并发读写。

1
2
3
4
5
./fio --name TEST --eta-newline=5s \
--filename=/root/fio-tempfile.dat \
--rw=write --size=2g --io_size=2g --blocksize=4k \
--ioengine=psync --fsync=1 --iodepth=8 --direct=1 \
--numjobs=1 --runtime=300 --group_reporting --time_based

例如这个是个人电脑 Linux 的测速,不会是那种 vcenter 和虚拟化上受其他虚机和存储池的影响,这台 Linux 分区是 hdd 和 SDD 做的 lvm,最终的 avg 是 avg=837.02。现场测速记得参数 –filename= 改成 data 实际路径测速文件 ,下面数据结果可以参考下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
root@pve:~# fio --name TEST --eta-newline=5s --filename=/root/fio-tempfile.dat \
--rw=write --size=500m --io_size=2g --blocksize=4k \
--ioengine=psync --fsync=1 --iodepth=8 --direct=1 \
--numjobs=1 --runtime=300 --group_reporting --time_based
TEST: (g=0): rw=write, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=psync, iodepth=8
fio-3.12
Starting 1 process
Jobs: 1 (f=1): [W(1)][2.3%][w=3275KiB/s][w=818 IOPS][eta 04m:53s]
Jobs: 1 (f=1): [W(1)][4.3%][w=3383KiB/s][w=845 IOPS][eta 04m:47s]
Jobs: 1 (f=1): [W(1)][6.3%][w=3295KiB/s][w=823 IOPS][eta 04m:41s]
Jobs: 1 (f=1): [W(1)][8.3%][w=3263KiB/s][w=815 IOPS][eta 04m:35s]
Jobs: 1 (f=1): [W(1)][10.3%][w=3304KiB/s][w=826 IOPS][eta 04m:29s]
Jobs: 1 (f=1): [W(1)][12.3%][w=3324KiB/s][w=831 IOPS][eta 04m:23s]
Jobs: 1 (f=1): [W(1)][14.3%][w=3523KiB/s][w=880 IOPS][eta 04m:17s]
Jobs: 1 (f=1): [W(1)][16.3%][w=3368KiB/s][w=842 IOPS][eta 04m:11s]
Jobs: 1 (f=1): [W(1)][18.3%][w=3407KiB/s][w=851 IOPS][eta 04m:05s]
Jobs: 1 (f=1): [W(1)][20.3%][w=3395KiB/s][w=848 IOPS][eta 03m:59s]
Jobs: 1 (f=1): [W(1)][22.3%][w=3335KiB/s][w=833 IOPS][eta 03m:53s]
Jobs: 1 (f=1): [W(1)][24.3%][w=3335KiB/s][w=833 IOPS][eta 03m:47s]
Jobs: 1 (f=1): [W(1)][26.3%][w=3467KiB/s][w=866 IOPS][eta 03m:41s]
Jobs: 1 (f=1): [W(1)][28.3%][w=3328KiB/s][w=832 IOPS][eta 03m:35s]
Jobs: 1 (f=1): [W(1)][30.3%][w=3284KiB/s][w=821 IOPS][eta 03m:29s]
Jobs: 1 (f=1): [W(1)][32.3%][w=3295KiB/s][w=823 IOPS][eta 03m:23s]
Jobs: 1 (f=1): [W(1)][34.3%][w=3399KiB/s][w=849 IOPS][eta 03m:17s]
Jobs: 1 (f=1): [W(1)][36.3%][w=3391KiB/s][w=847 IOPS][eta 03m:11s]
Jobs: 1 (f=1): [W(1)][38.3%][w=3347KiB/s][w=836 IOPS][eta 03m:05s]
Jobs: 1 (f=1): [W(1)][40.3%][w=3331KiB/s][w=832 IOPS][eta 02m:59s]
Jobs: 1 (f=1): [W(1)][42.3%][w=3211KiB/s][w=802 IOPS][eta 02m:53s]
Jobs: 1 (f=1): [W(1)][44.3%][w=3351KiB/s][w=837 IOPS][eta 02m:47s]
Jobs: 1 (f=1): [W(1)][46.3%][w=3267KiB/s][w=816 IOPS][eta 02m:41s]
Jobs: 1 (f=1): [W(1)][48.3%][w=3320KiB/s][w=830 IOPS][eta 02m:35s]
Jobs: 1 (f=1): [W(1)][50.3%][w=3419KiB/s][w=854 IOPS][eta 02m:29s]
Jobs: 1 (f=1): [W(1)][52.3%][w=3344KiB/s][w=836 IOPS][eta 02m:23s]
Jobs: 1 (f=1): [W(1)][54.3%][w=3427KiB/s][w=856 IOPS][eta 02m:17s]
Jobs: 1 (f=1): [W(1)][56.3%][w=3388KiB/s][w=847 IOPS][eta 02m:11s]
Jobs: 1 (f=1): [W(1)][58.3%][w=3516KiB/s][w=879 IOPS][eta 02m:05s]
Jobs: 1 (f=1): [W(1)][60.3%][w=3320KiB/s][w=830 IOPS][eta 01m:59s]
Jobs: 1 (f=1): [W(1)][62.3%][w=3184KiB/s][w=796 IOPS][eta 01m:53s]
Jobs: 1 (f=1): [W(1)][64.3%][w=3468KiB/s][w=867 IOPS][eta 01m:47s]
Jobs: 1 (f=1): [W(1)][66.3%][w=3399KiB/s][w=849 IOPS][eta 01m:41s]
Jobs: 1 (f=1): [W(1)][68.3%][w=3540KiB/s][w=885 IOPS][eta 01m:35s]
Jobs: 1 (f=1): [W(1)][70.3%][w=3304KiB/s][w=826 IOPS][eta 01m:29s]
Jobs: 1 (f=1): [W(1)][72.3%][w=3187KiB/s][w=796 IOPS][eta 01m:23s]
Jobs: 1 (f=1): [W(1)][74.3%][w=3428KiB/s][w=857 IOPS][eta 01m:17s]
Jobs: 1 (f=1): [W(1)][76.3%][w=3751KiB/s][w=937 IOPS][eta 01m:11s]
Jobs: 1 (f=1): [W(1)][78.3%][w=3336KiB/s][w=834 IOPS][eta 01m:05s]
Jobs: 1 (f=1): [W(1)][80.3%][w=3456KiB/s][w=864 IOPS][eta 00m:59s]
Jobs: 1 (f=1): [W(1)][82.3%][w=3259KiB/s][w=814 IOPS][eta 00m:53s]
Jobs: 1 (f=1): [W(1)][84.3%][w=3416KiB/s][w=854 IOPS][eta 00m:47s]
Jobs: 1 (f=1): [W(1)][86.3%][w=3384KiB/s][w=846 IOPS][eta 00m:41s]
Jobs: 1 (f=1): [W(1)][88.3%][w=3299KiB/s][w=824 IOPS][eta 00m:35s]
Jobs: 1 (f=1): [W(1)][90.3%][w=3427KiB/s][w=856 IOPS][eta 00m:29s]
Jobs: 1 (f=1): [W(1)][92.3%][w=3176KiB/s][w=794 IOPS][eta 00m:23s]
Jobs: 1 (f=1): [W(1)][94.3%][w=3295KiB/s][w=823 IOPS][eta 00m:17s]
Jobs: 1 (f=1): [W(1)][96.3%][w=3359KiB/s][w=839 IOPS][eta 00m:11s]
Jobs: 1 (f=1): [W(1)][98.3%][w=3532KiB/s][w=883 IOPS][eta 00m:05s]
Jobs: 1 (f=1): [W(1)][100.0%][w=3351KiB/s][w=837 IOPS][eta 00m:00s]
TEST: (groupid=0, jobs=1): err= 0: pid=6687: Mon Jan 24 11:42:39 2022
write: IOPS=837, BW=3348KiB/s (3429kB/s)(981MiB/300001msec); 0 zone resets
clat (usec): min=29, max=5771, avg=107.72, stdev=56.50
lat (usec): min=29, max=5772, avg=108.00, stdev=56.50
clat percentiles (usec):
| 1.00th=[ 34], 5.00th=[ 42], 10.00th=[ 47], 20.00th=[ 73],
| 30.00th=[ 82], 40.00th=[ 102], 50.00th=[ 113], 60.00th=[ 128],
| 70.00th=[ 137], 80.00th=[ 143], 90.00th=[ 147], 95.00th=[ 151],
| 99.00th=[ 163], 99.50th=[ 169], 99.90th=[ 184], 99.95th=[ 208],
| 99.99th=[ 3261]
bw ( KiB/s): min= 2760, max= 3872, per=100.00%, avg=3348.14, stdev=140.52, samples=600
iops : min= 690, max= 968, avg=837.02, stdev=35.13, samples=600
lat (usec) : 50=10.97%, 100=27.52%, 250=61.48%, 500=0.01%, 750=0.01%
lat (usec) : 1000=0.01%
lat (msec) : 2=0.01%, 4=0.02%, 10=0.01%
fsync/fdatasync/sync_file_range:
sync (usec): min=383, max=27349, avg=1084.44, stdev=480.22
sync percentiles (usec):
| 1.00th=[ 701], 5.00th=[ 725], 10.00th=[ 742], 20.00th=[ 766],
| 30.00th=[ 799], 40.00th=[ 816], 50.00th=[ 832], 60.00th=[ 840],
| 70.00th=[ 947], 80.00th=[ 1696], 90.00th=[ 1811], 95.00th=[ 1876],
| 99.00th=[ 1975], 99.50th=[ 2040], 99.90th=[ 2180], 99.95th=[ 3458],
| 99.99th=[ 9634]
cpu : usr=1.09%, sys=4.30%, ctx=678813, majf=0, minf=13
IO depths : 1=200.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=0,251136,0,251136 short=0,0,0,0 dropped=0,0,0,0
latency : target=0, window=0, percentile=100.00%, depth=8

Run status group 0 (all jobs):
WRITE: bw=3348KiB/s (3429kB/s), 3348KiB/s-3348KiB/s (3429kB/s-3429kB/s), io=981MiB (1029MB), run=300001-300001msec

Disk stats (read/write):
dm-1: ios=0/725828, merge=0/0, ticks=0/282020, in_queue=282020, util=99.90%, aggrios=240/651563, aggrmerge=0/74672, aggrticks=583/280037, aggrin_queue=620, aggrutil=99.90%
sdb: ios=240/651563, merge=0/74672, ticks=583/280037, in_queue=620, util=99.90%

https://etcd.io/docs/v3.5/op-guide/hardware/ etcd 文档上写着:

1
2
etcd 对磁盘写入延迟非常敏感。通常需要 50 个顺序 IOPS(例如,7200 RPM 磁盘)。对于负载较重的集群,建议使用 500 顺序 IOPS(例如,典型的本地 SSD 或高性能虚拟化块设备)。请注意,大多数云提供商发布并发 IOPS 而不是顺序 IOPS;发布的并发 IOPS 可以是顺序 IOPS 的 10 倍。要测量实际的顺序 IOPS,我们建议使用磁盘基准测试工具,例如 diskbench 或 fio。
如果要取输出里的部分值,那就带上 --output-format=json
1
2
3
4
5
./fio --name TEST --eta-newline=5s --filename=/root/fio-tempfile.dat \
--rw=write --size=2g --io_size=2g --blocksize=4k \
--ioengine=psync --fsync=1 --iodepth=8 --direct=1 --numjobs=1 \
--runtime=300 --group_reporting --time_based \
--output-format=json

正常来说 普通 7200 的硬盘 IOPS 也就是 60 左右,500 的 IOPS 基本就得用 jbod 或者 raid10,或者更高的 SSD 了。
如果测得低的话可以肯定是 io 不行,高的话也不一定真的快,硬盘可能有缓存,可能会虚高。所以fio的需要长时间测试,推荐 3 分钟以上。

其他参考

CATALOG
  1. 1. 由来
    1. 1.1. buildx 使用
    2. 1.2. 编译
    3. 1.3. fio 测速说明
  2. 2. 其他参考