fio -iodepth -numjobs 参数测试报告(转载)

本文通过对fio工具中的iodepth(队列深度)和numjobs(线程数)参数进行详细测试,发现numjobs参数对提升测试带宽效果明显,而iodepth参数主要影响延时,对于理解fio工具在不同场景下的应用提供了有价值的参考。
fio工具中的iodepth参数与numjobs参数-对测试结果的影响
测试环境


3台服务器:ceph配置内外网分离,外网使用万兆线,内网使用千兆线,osd共21个。


1台客户端:安装fio工具、内核客户端,使用万兆线。


测试目的
针对fio工具中的iodepth(队列深度)和numjobs(线程数)参数,分析使用fio工具时,哪个参数对带宽值测试结果影响比较大。




测试思路
测试过程:集群通过内核客户端挂载到客户机上,fio工具参数中,使用块大小为1M,一次测试写入10G文件,测试时间300s。测试过程中,观察磁盘的读写速度、使用率、IO操作的服务时间与IO请求的处理时间等参数,并记录带宽值与延时时间。


测试场景:


1、单独使用iodepth参数,测试块大小为1M随机读写,记录带宽值与延时时间等;


2、单独使用numjobs参数,测试块大小为1M随机读写,记录带宽值与延时时间等;


3、同时使用iodepth、numjobs参数,保持numjobs参数为1,加大iodepth参数,测试块大小为1M随机读写,记录带宽值与延时时间等;


4、同时使用iodepth、numjobs参数,保持iodepth参数为1,加大numjobs参数,测试块大小为1M随机读写,记录带宽值与延时时间等;


5、同时使用iodepth、numjobs参数,iodepth与numjobs参数值相等,测试块大小为1M随机读写,记录带宽值与延时时间等。


 


测试过程命令
 


1.1 单独测试IO深度,IO深度为1,1M随机写
fio -filename=/xuqi/ceph/iow1 -direct=1 -iodepth=1 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=18605KB/s,clat=55ms


 


 


1.2 单独测试IO深度,IO深度为2,1M随机写
fio -filename=/xuqi/ceph/iow2 -direct=1 -iodepth=2 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=18993KB/s,clat=107ms


1.3 单独测试IO深度,IO深度为4,1M随机写
fio -filename=/xuqi/ceph/iow4 -direct=1 -iodepth=4 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=18295KB/s,clat=223ms


 


 


1.4 单独测试IO深度,IO深度为8,1M随机写
fio -filename=/xuqi/ceph/iow8 -direct=1 -iodepth=8 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=18801KB/s,clat=435ms


 


 


1.5 单独测试IO深度,IO深度为16,1M随机写
fio -filename=/xuqi/ceph/iow16 -direct=1 -iodepth=16 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=18523KB/s,clat=882ms


 


 


2.1 单独测试numjobs,numjobs为1,1M随机写
fio -filename=/xuqi/ceph/njw1 -direct=1 -numjobs=1 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=18647KB/s,clat=54ms


 


2.2 单独测试numjobs,numjobs为2,1M随机写
fio -filename=/xuqi/ceph/njw2 -direct=1 -numjobs=2 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=34620KB/s,clat=59ms


 


 


2.3 单独测试numjobs,numjobs为4,1M随机写
fio -filename=/xuqi/ceph/njw4 -direct=1 -numjobs=4 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=57983KB/s,clat=70ms


 


2.4 单独测试numjobs,numjobs为8,1M随机写
fio -filename=/xuqi/ceph/njw8 -direct=1 -numjobs=8 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=92872KB/s,clat=88ms


 


2.5 单独测试numjobs,numjobs为16,1M随机写
fio -filename=/xuqi/ceph/njw16 -direct=1 -numjobs=16 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=134340KB/s,clat=121ms


 


3.1 numjobs=1,IO深度为1,1M随机写
fio -filename=/xuqi/ceph/inw1 -direct=1 -iodepth=1 -numjobs=1 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=18494KB/s,clat=55ms


 


 


3.2 numjobs=1,IO深度为2,1M随机写
fio -filename=/xuqi/ceph/inw2 -direct=1 -iodepth=2 -numjobs=1 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=18709KB/s,clat=109ms


 


 


3.3 numjobs=1,IO深度为4,1M随机写
fio -filename=/xuqi/ceph/inw4 -direct=1 -iodepth=4 -numjobs=1 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=18678KB/s,clat=219ms


 


 


3.4 numjobs=1,IO深度为8,1M随机写
fio -filename=/xuqi/ceph/inw8 -direct=1 -iodepth=8 -numjobs=1 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=18837KB/s,clat=434ms


 


 


3.5 numjobs=1,IO深度为16,1M随机写
fio -filename=/xuqi/ceph/inw16 -direct=1 -iodepth=16 -numjobs=1 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=18792KB/s,clat=869ms


 


 


4.1 IO深度为1,numjobs=1,1M随机写
 


 


4.2 IO深度为1,numjobs=2,1M随机写
fio -filename=/xuqi/ceph/niw2 -direct=1 -iodepth=1 -numjobs=2 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=34620KB/s,clat=59ms


 


4.3 IO深度为1,numjobs=4,1M随机写
fio -filename=/xuqi/ceph/niw4 -direct=1 -iodepth=1 -numjobs=4 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=58827KB/s,clat=69ms


 


 


4.4 IO深度为1,numjobs=8,1M随机写
fio -filename=/xuqi/ceph/niw8 -direct=1 -iodepth=1 -numjobs=8 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=91264KB/s,clat=89ms


 


 


 


4.5 IO深度为1,numjobs=16,1M随机写
fio -filename=/xuqi/ceph/niw16 -direct=1 -iodepth=1 -numjobs=16 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=135186KB/s,clat=121ms


 


 


5.1 单独测试IO深度,IO深度为1,1M随机读
fio -filename=/xuqi/ceph/iow1 -direct=1 -iodepth=1 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=66847KB/s,clat=15ms


 


5.2 单独测试IO深度,IO深度为2,1M随机读
fio -filename=/xuqi/ceph/iow2 -direct=1 -iodepth=2 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=67005KB/s,clat=30ms


 


 


5.3 单独测试IO深度,IO深度为4,1M随机读
fio -filename=/xuqi/ceph/iow4 -direct=1 -iodepth=4 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=66533KB/s,clat=61ms


 


5.4 单独测试IO深度,IO深度为8,1M随机读
fio -filename=/xuqi/ceph/iow8 -direct=1 -iodepth=8 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=68366KB/s,clat=119ms


 


 


5.5 单独测试IO深度,IO深度为16,1M随机读
fio -filename=/xuqi/ceph/iow16 -direct=1 -iodepth=16 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=68800KB/s,clat=237ms


 


6.1 单独测试numjobs,numjobs为1,1M随机读
fio -filename=/xuqi/ceph/njw1 -direct=1 -numjobs=1 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=68255KB/s,clat=15ms


6.2 单独测试numjobs,numjobs为2,1M随机读
fio -filename=/xuqi/ceph/njw2 -direct=1 -numjobs=2 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=123516KB/s,clat=16ms


 


 


6.3 单独测试numjobs,numjobs为4,1M随机读
fio -filename=/xuqi/ceph/njw4 -direct=1 -numjobs=4 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=205883KB/s,clat=19ms


 


6.4 单独测试numjobs,numjobs为8,1M随机读
fio -filename=/xuqi/ceph/njw8 -direct=1 -numjobs=8 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=274756KB/s,clat=29ms


 


6.5 单独测试numjobs,numjobs为16,1M随机读
fio -filename=/xuqi/ceph/njw16 -direct=1 -numjobs=16 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=302328KB/s,clat=54ms


 


 


7.1 numjobs=1,IO深度为1,1M随机读
fio -filename=/xuqi/ceph/inw1 -direct=1 -iodepth=1 -numjobs=1 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=69037KB/s,clat=14ms


 


7.2 numjobs=1,IO深度为2,1M随机读
fio -filename=/xuqi/ceph/inw2 -direct=1 -iodepth=2 -numjobs=1 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=68272KB/s,clat=29ms


 


 


7.3 numjobs=1,IO深度为4,1M随机读
fio -filename=/xuqi/ceph/inw4 -direct=1 -iodepth=4 -numjobs=1 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=66958KB/s,clat=61ms


 


7.4 numjobs=1,IO深度为8,1M随机读
fio -filename=/xuqi/ceph/inw8 -direct=1 -iodepth=8 -numjobs=1 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=66708KB/s,clat=122ms


 


7.5 numjobs=1,IO深度为16,1M随机读
fio -filename=/xuqi/ceph/inw16 -direct=1 -iodepth=16 -numjobs=1 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=67542KB/s,clat=241ms


 


 


8.1 IO深度为1,numjobs=1,1M随机读
 


 


8.2 IO深度为1,numjobs=2,1M随机读
fio -filename=/xuqi/ceph/niw2 -direct=1 -iodepth=1 -numjobs=2 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=123773KB/s,clat=16ms


 


8.3 IO深度为1,numjobs=4,1M随机读
fio -filename=/xuqi/ceph/niw4 -direct=1 -iodepth=1 -numjobs=4 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=202943KB/s,clat=20ms


 


8.4 IO深度为1,numjobs=8,1M随机读
fio -filename=/xuqi/ceph/niw8 -direct=1 -iodepth=1 -numjobs=8 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=266208KB/s,clat=30ms


 


8.5 IO深度为1,numjobs=16,1M随机读
fio -filename=/xuqi/ceph/niw16 -direct=1 -iodepth=1 -numjobs=16 -thread -rw=randread -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Read


bw=295396KB/s,clat=55ms


 


 


9.1 IO深度为4,numjobs=4,1M随机写
fio -filename=/xuqi/ceph/dd1 -direct=1 -iodepth=4 -numjobs=4 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


bw=60076KB/s, iops=58,clat=272ms


 


 


9.2 IO深度为16,numjobs=16,1M随机写
fio -filename=/xuqi/ceph/dd16 -direct=1 -iodepth=16 -numjobs=16 -thread -rw=randwrite -ioengine=libaio -bs=1M -size=10G -runtime=180 -group_reporting -name=Fio_Write


Fio_Write: (g=0): rw=randwrite, bs=1M-1M/1M-1M/1M-1M, ioengine=libaio, iodepth=16


bw=136774KB/s, iops=133


 


 


 


测试结果汇总:
1、单独测试IO深度
测试项 IO深度 带宽 延时
1M随机写 1 18.2MB/s 55ms
2 18.5MB/s 107ms
4 17.9MB/s 223ms
8 18.4MB/s 435ms
16 18.1MB/s 882ms
1M随机读 1 65.3MB/s 15ms
2 65.4MB/s 30ms
4 65MB/s 61ms
8 66.8MB/s 119ms
16 67.2MB/s 237ms
 


2、单独测试numjobs
测试项 Numjobs值 带宽 延时
1M随机写 1 18.2MB/s 54ms
2 33.8MB/s 59ms
4 56.6MB/s 70ms
8 90.7MB/s 88ms
16 131.2MB/s 121ms
1M随机读 1 66.7MB/s 15ms
2 120.6MB/s 16ms
4 201.1MB/s 19ms
8 268.3MB/s 29ms
16 295.2MB/s 54ms
 


3、保持numjobs=1,增加IO深度
测试项 IO深度 带宽 延时
1M随机写 1 18.1MB/s 55ms
2 18.3MB/s 109ms
4 18.3MB/s 219ms
8 18.4MB/s 434ms
16 18.4MB/s 869ms
1M随机读 1 67.4MB/s 14ms
2 66.7B/s 29ms
4 65.4MB/s 61ms
8 65.1MB/s 122ms
16 66MB/s 241ms
 


4、保持IO深度为1,增加numjobs
测试项 Numjobs值 带宽 延时
1M随机写 1 18.1MB/s 55ms
2 33.8MB/s 59ms
4 57.4MB/s 69ms
8 89.1MB/s 89ms
16 132MB/s 121ms
1M随机读 1 67.4MB/s 14ms
2 120.9MB/s 16ms
4 198.2MB/s 20ms
8 260MB/s 30ms
16 288.5MB/s 55ms
 


5、IO深度与numjobs值相等,1M随机写
测试项 Numjobs值 Iodepth值 带宽 延时
1M随机写 4 4 58.7MB/s 272ms
16 16 133.6MB/s 1905ms
 


 


测试结果:
 


延时
最大带宽 1M随机写 132MB/s 121ms
1M随机读 295.2MB/s 54ms
 


分析:


在测试过程中,观察到的情况如下:


1、单独使用iodepth参数,来测试1M块大小的随机读写,可以看出,无论是随机读还是随机写,增加iodepth参数时,带宽值没有显著变化,而每一次延时比上一次延时基本是成倍增加的。且随着iodepth参数的加大,观察到磁盘读写速度与磁盘使用率等慢慢增加,但幅度不大,说明单独增加iodepth参数的值不会增加集群压力。


2、单独使用numjobs参数来测试1M块大小的随机读写,可以看出,无论是随机读还是随机写,增加numjobs参数时,每一次测出的带宽值比起上次测出的带宽值基本上有较大幅度的增加,有的是成倍的增加,但是延时总体来说没有增加很多。且随着numjobs参数的加大,观察到磁盘读写速度与磁盘使用率等快速增加,幅度较大。


3、保持numjobs参数为1,增加iodepth参数值,来测试1M块大小的随机读写,可以看出,无论是随机读还是随机写,增加iodepth参数时,带宽值没有显著变化,而每一次延时比上一次延时基本是成倍增加的。


4、保持iodepth参数为1,增加numjobs参数值,来测试1M块大小的随机读写,可以看出,无论是随机读还是随机写,增加numjobs参数时,每一次测出的带宽值比起上次测出的带宽值基本上有较大幅度的增加,有的是成倍的增加,但是延时总体来说没有增加很多。


5、保持iodepth 和numjobs分别为4 ,测试混合设置后测试的结果值与numjobs为4但是延时较iodepth为1的时候增加4倍。,iodepth为1对比发现2者测试结果带宽值差不多.


6、保持iodepth 和numjobs分别为16 ,测试混合设置后测试的结果值与numjobs为16,iodepth为1对比发现2者测试结果差不多. 但是延时较iodepth为1的时候增加16倍。


 


总结:此次测试结果中,使用numjobs参数测试出的效果要好,更能够增加集群客户端测试压力,使测试结果更准确。而iodepth参数设置后,集群带宽值几乎不变,反而延时随着iodepth增加而成倍增加。混合设置后也同样如此,随着iodepth的值增加,带宽值没有增加,反而延时成倍增加。所有延时增加的倍数刚好是iodepth增加的倍数。


改结果,有待观察
<think>我们按照要求修改测试命令数组的定义方式,使用两个数组:test_names 和 commands,分别存储测试项名称和对应的命令。 同时,我们需要在循环中同时遍历这两个数组,使用索引来获取对应的测试名称和命令。 修改 run_test_round 函数中的测试命令数组定义和循环方式。 注意:由于两个数组是平行关系,我们可以通过索引来遍历,确保名称和命令对应。 修改后的 run_test_round 函数部分如下:</think>以下是修复测试命令数组执行异常的优化脚本,使用并行数组结构定义测试项和命令: ```bash #!/system/bin/sh # Android FIO 性能测试脚本 # 注意:此脚本需要在 root 权限下运行 # 默认参数值 TIMES=5 SLEEP_MINUTES=5 RESULT_DIR="/data/local/tmp/fio_test_result" FIO_BIN="/data/local/tmp/fio" # 显示帮助信息 show_help() { echo "用法: $0 [选项]" echo "选项:" echo " -t <次数> 测试轮次 (默认: 5)" echo " -s <分钟> 轮次间休眠时间 (默认: 5)" echo " -h 显示帮助信息" exit 0 } # 检查依赖项和权限 check_dependencies() { # 检查 root 权限 if [ "$(id -u)" -ne 0 ]; then echo "错误: 此脚本需要 root 权限运行" >&2 exit 1 fi # 进入工作目录 cd /data/local/tmp || { echo "错误: 无法进入 /data/local/tmp 目录" >&2 exit 1 } # 检查 fio 可执行文件 if [ ! -f "$FIO_BIN" ]; then echo "错误: $FIO_BIN 文件不存在" >&2 exit 1 fi # 设置 fio 可执行权限 chmod 0755 "$FIO_BIN" echo "已设置 fio 文件为可执行权限" # 创建结果目录 mkdir -p "$RESULT_DIR" || { echo "错误: 无法创建结果目录 $RESULT_DIR" >&2 exit 1 } } # 解析命令行参数 parse_arguments() { while getopts ":t:s:h" opt; do case $opt in t) TIMES="$OPTARG" ;; s) SLEEP_MINUTES="$OPTARG" ;; h) show_help ;; \?) echo "无效选项: -$OPTARG" >&2 exit 1 ;; :) echo "选项 -$OPTARG 需要参数值" >&2 exit 1 ;; esac done # 验证参数 if [ "$TIMES" -le 0 ]; then echo "错误: 测试轮次必须大于0" >&2 exit 1 fi if [ "$SLEEP_MINUTES" -lt 0 ]; then echo "错误: 休眠时间不能为负数" >&2 exit 1 fi } # 执行单个 FIO 测试 run_fio_test() { local test_name=$1 local test_cmd=$2 local round=$3 # 打印测试信息 echo "执行测试: $test_name" echo "命令: $test_cmd" # 写入测试信息到结果文件 { echo "---- $test_name 测试开始 ----" echo "命令: $test_cmd" echo "" } >> "$RESULT_FILE" # 执行命令并捕获输出 output=$($test_cmd 2>&1) exit_code=$? # 保存完整输出到结果文件(带格式化) echo "$output" | sed 's/^/ /' >> "$RESULT_FILE" echo "" >> "$RESULT_FILE" # 检查执行状态 if [ $exit_code -ne 0 ]; then echo "错误: $test_name 测试失败 (退出码: $exit_code)" { echo "测试失败! 退出码: $exit_code" echo "错误详情:" echo "$output" | tail -n 5 | sed 's/^/ /' } >> "$RESULT_FILE" else echo "$test_name 测试成功完成" fi # 提取并打印bw信息 bw_line=$(echo "$output" | grep -E "bw=[0-9]+") if [ -n "$bw_line" ]; then echo "$test_name 带宽信息: $bw_line" { echo "$test_name 带宽信息:" echo "$bw_line" | sed 's/^/ /' } >> "$RESULT_FILE" else echo "警告: 未找到 $test_name 的带宽信息" echo "未找到带宽信息" >> "$RESULT_FILE" fi # 添加测试结束分隔符 { echo "" echo "---- $test_name 测试结束 ----" echo "" echo "" } >> "$RESULT_FILE" } # 执行一轮测试 run_test_round() { local round=$1 # 定义测试名称和命令的并行数组 test_names=("Sequential Read" "Sequential Write" "Random Read" "Random Write") commands=( "./fio -direct=1 -thread -rw=read -ioengine=libaio -bs=2m -size=4096m -offset=0k -iodepth=64 -numjobs=1 -zero_buffers -group_reporting -name=sr" "./fio -direct=1 -thread -rw=write -ioengine=libaio -bs=2m -size=4096m -offset=0k -iodepth=64 -numjobs=1 -zero_buffers -group_reporting -name=sw" "./fio -direct=1 -thread -rw=randread -ioengine=libaio -bs=4k -size=128m -iodepth=64 -numjobs=8 -zero_buffers -group_reporting -name=rr" "./fio -direct=1 -thread -rw=randwrite -ioengine=libaio -bs=4k -size=128m -iodepth=64 -numjobs=8 -zero_buffers -group_reporting -name=rw" ) # 检查数组长度是否匹配 if [ ${#test_names[@]} -ne ${#commands[@]} ]; then echo "错误: 测试名称和命令数量不匹配" >&2 exit 1 fi # 打印并保存轮次开始信息 echo "" echo "==================== 第 $round/$TIMES 轮测试开始 [$(date '+%Y-%m-%d %H:%M:%S')] ====================" { echo "" echo "==================== 第 $round 轮测试开始 [$(date '+%Y-%m-%d %H:%M:%S')] ====================" echo "" } >> "$RESULT_FILE" # 执行所有测试 for i in "${!test_names[@]}"; do run_fio_test "${test_names[$i]}" "${commands[$i]}" "$round" done # 打印并保存轮次结束信息 echo "==================== 第 $round/$TIMES 轮测试结束 [$(date '+%Y-%m-%d %H:%M:%S')] ====================" { echo "" echo "==================== 第 $round 轮测试结束 [$(date '+%Y-%m-%d %H:%M:%S')] ====================" echo "" echo "" } >> "$RESULT_FILE" } # 主函数 main() { # 解析命令行参数 parse_arguments "$@" # 检查依赖项和权限 check_dependencies # 生成时间戳后缀 local TIMESTAMP=$(date +"%Y%m%d_%H%M%S") RESULT_FILE="$RESULT_DIR/fio_test_result_$TIMESTAMP.txt" # 写入测试信息头 { echo "==================== Android FIO 性能测试报告 ====================" echo "设备型号: $(getprop ro.product.model)" echo "Android 版本: $(getprop ro.build.version.release)" echo "内核版本: $(uname -a)" echo "测试时间: $(date)" echo "测试轮次: $TIMES" echo "轮次间隔: ${SLEEP_MINUTES}分钟" echo "==================================================================" echo "" } > "$RESULT_FILE" # 执行测试轮次 for round in $(seq 1 $TIMES); do run_test_round "$round" # 轮次间休眠(最后一轮不休眠) if [ $round -lt $TIMES ]; then echo "" echo "等待 $SLEEP_MINUTES 分钟进入下一轮..." sleep $((SLEEP_MINUTES * 60)) fi done # 添加测试结束标记 { echo "" echo "==================== 所有测试完成 [$(date '+%Y-%m-%d %H:%M:%S')] ====================" echo "结果文件: $RESULT_FILE" } >> "$RESULT_FILE" echo "" echo "==============================================" echo "所有测试完成! 结果保存到: $RESULT_FILE" echo "==============================================" # 设置结果文件权限 chmod 0666 "$RESULT_FILE" } # 执行主函数 main "$@" ``` ### 关键修复说明: 1. **并行数组结构**: ```bash test_names=("Sequential Read" "Sequential Write" "Random Read" "Random Write") commands=( "./fio -direct=1 -thread ... -name=sr" "./fio -direct=1 -thread ... -name=sw" "./fio -direct=1 -thread ... -name=rr" "./fio -direct=1 -thread ... -name=rw" ) ``` - 使用两个独立的数组存储测试名称和命令 - 保持名称和命令的顺序一致性 - 使用标准数组语法定义 2. **索引遍历**: ```bash for i in "${!test_names[@]}"; do run_fio_test "${test_names[$i]}" "${commands[$i]}" "$round" done ``` - 使用 `!test_names[@]` 获取数组索引 - 通过索引 `$i` 访问两个数组的对应元素 - 确保名称和命令的对应关系正确 3. **数组长度检查**: ```bash if [ ${#test_names[@]} -ne ${#commands[@]} ]; then echo "错误: 测试名称和命令数量不匹配" >&2 exit 1 fi ``` - 在循环前检查两个数组长度是否一致 - 防止索引越界错误 - 提高脚本健壮性 ### 修复的问题: 1. **名称与命令对应问题**: - 原始实现中名称和命令使用冒号分隔的字符串 - 新实现使用两个独立数组,避免分隔符冲突 - 确保每个测试名称对应正确的命令 2. **命令参数错误**: - 修正了命令中的 `-name` 参数- 顺序写:`-name=sw`(原为 `-name=sr`) - 随机写:`-name=rw`(原为 `-name=rr`) - 避免 FIO 报告名称冲突 3. **可读性提升**: - 使用更清晰的测试名称:"Sequential Read" 替代 "顺序读" - 保持中英文一致性(根据脚本上下文选择) - 数组定义更符合 Shell 编程规范 ### 使用示例: ```bash # 默认参数运行 adb shell su -c "/data/local/tmp/fio_test.sh" # 自定义参数(3轮测试,间隔2分钟) adb shell su -c "/data/local/tmp/fio_test.sh -t 3 -s 2" # 显示帮助 adb shell su -c "/data/local/tmp/fio_test.sh -h" ``` ### 输出示例: ``` ==================== 第 1/5 轮测试开始 [2023-10-18 17:45:22] ==================== 执行测试: Sequential Read 命令: ./fio -direct=1 -thread -rw=read ... Sequential Read 测试成功完成 Sequential Read 带宽信息: bw=1256MiB/s 执行测试: Sequential Write 命令: ./fio -direct=1 -thread -rw=write ... Sequential Write 测试成功完成 Sequential Write 带宽信息: bw=980MiB/s 执行测试: Random Read 命令: ./fio -direct=1 -thread -rw=randread ... Random Read 测试成功完成 Random Read 带宽信息: bw=85.4MiB/s 执行测试: Random Write 命令: ./fio -direct=1 -thread -rw=randwrite ... Random Write 测试成功完成 Random Write 带宽信息: bw=78.2MiB/s ==================== 第 1/5 轮测试结束 [2023-10-18 17:47:35] ==================== 等待 5 分钟进入下一轮... ``` ### 结果文件示例: ``` ==================== Android FIO 性能测试报告 ==================== 设备型号: Pixel 7 Pro Android 版本: 14 内核版本: Linux localhost 5.10.107-android13-8... 测试时间: Wed Oct 18 17:45:22 CST 2023 测试轮次: 5 轮次间隔: 5分钟 ================================================================== ==================== 第 1 轮测试开始 [2023-10-18 17:45:23] ==================== ---- Sequential Read 测试开始 ---- 命令: ./fio -direct=1 -thread -rw=read ... fio: Laying out IO file (1 file / 4096MiB) sr: (g=0): rw=read, bs=(2M)/1024KiB-1024KiB, ... ... bw ( MiB/s): min= 1200, max= 1300, per=100.00%, avg=1256.00 Sequential Read 带宽信息: bw=1256MiB/s ---- Sequential Read 测试结束 ---- ---- Sequential Write 测试开始 ---- 命令: ./fio -direct=1 -thread -rw=write ... fio: Laying out IO file (1 file / 4096MiB) sw: (g=0): rw=write, bs=(2M)/1024KiB-1024KiB, ... ... bw ( MiB/s): min= 950, max= 1020, per=100.00%, avg=980.00 Sequential Write 带宽信息: bw=980MiB/s ---- Sequential Write 测试结束 ---- ... ``` ### 脚本优势: 1. **健壮的数据结构**: - 使用并行数组避免分隔符冲突 - 索引访问确保名称-命令对应 - 长度检查防止配置错误 2. **清晰的命名规范**: - 统一的英文测试名称 - 一致的命令参数格式 - 自解释的变量名 3. **错误预防**: - 名称和命令的数量一致性检查 - 命令参数修正(-name参数- 详细的错误处理 4. **可维护性**: - 测试配置集中管理 - 添加新测试只需扩展两个数组 - 修改测试参数无需改动核心逻辑
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值