压力测试工具之FIO

     针对磁盘的压力性能测试工具有很多,简单的测试可以通过dd命令实现,而比较专业和强大的磁盘IO测试工具,当然首推FIO了。这里针对FIO工具使用做个简单的介绍。介绍前,首先说明下两个概念,顺序读写和随机读写。
     随机读取、写入是根据磁盘数据分布进行随机读写,可能数据的读、写并不在连续的磁盘空间上,因此磁头寻址时间长、负荷大,每段数据都有地址码,通过地址码进行数据段读取。
     顺序读取、写入是根据磁盘数据分布进行连续读写,由于数据分布连续,寻址时间短,中间没有地址码。
     通常 机械硬盘主要是看顺序读写性能SSD主要看随机读写性能

    1)FIO下载
    https://github.com/axboe/fio
    
    2)FIO依赖包安装
    [root@node3 fio-master]# rpm -qa |grep libaio
    [root@node3 fio-master]# yum install libaio libaio-devel -y
    3)FIO源码安装
    [root@node3 yc]# unzip fio-master.zip
    [root@node3 yc]# cd fio-master
    [root@node3 fio-master]# ./configure  --prefix=/usr/local/fio
    [root@node3 fio-master]# make -j 8
    [root@node3 fio-master]# make install
    [root@node3 fio]# cd /usr/local/fio/
    [root@node3 fio]# ln -s /usr/local/fio/bin/* /usr/bin/
    4)FIO使用
    linux block size和page size获取方法:
    [root@node3 fio]# tune2fs -l /dev/sda1|grep "Block size"
    [root@node3 fio]# getconf  PAGE_SIZE
    
    随机读测试:
    [root@node3 fio]# fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=randread -ioengine=psync -bs=4k -size=10G -numjobs=10 -runtime=300 -group_reporting -name=iotest

    随机写测试:
[root@node3 fio]# fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=randwrite -ioengine=psync -bs=4k -size=10G -numjobs=10 -runtime=300 -group_reporting -name=iotest

    顺序读测试:
    [root@node3 fio]# fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=read -ioengine=psync -bs=4k -size=10G -numjobs=10 -runtime=300 -group_reporting -name=iotest

    顺序写测试:
    [root@node3 fio]# fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=write -ioengine=psync -bs=4k -size=10G -numjobs=10 -runtime=300 -group_reporting -name=iotest

    混合随机读写测试:
    [root@node3 fio]# fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=randrw -rwmixread=70 -ioengine=psync -bs=4k -size=10G -numjobs=10 -runtime=300 -group_reporting -name=iotest  -ioscheduler=deadline

    混合顺序读写测试:
    [root@node3 fio]# fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=rw -rwmixread=70 -ioengine=psync -bs=4k -size=10G -numjobs=10 -runtime=300 -group_reporting -name=iotest  -ioscheduler=deadline

    测试参数说明:
    filename=/dev/sda1 测试文件名称,通常选择需要测试的盘的data目录。
    direct=1 测试过程绕过机器自带的buffer,同O_DIRECT效果一样,使测试结果更真实。ZFS和Solaris不支持direct io,在windows同步IO引擎不支持direct io
    iodepth  加于文件之上的保持的IO单元。默认对于每个文件来说是1,可以设置一个更大的值来提供并发度。iodepth大于1不会影响同步IO引擎(除非verify_async这个选项被设置)。even async engines may impose OS restrictions causing the desired depth not to be achieved.这会在Linux使用libaio并且设置direct=1的时候发生,因为buffered io在OS中不是异步的。在外部通过类似于iostat这些工具来观察队列深度来保证这个IO队列深度是我们想要的。
    thread   io默认会使用fork()创建job,如果这个选项设置的话,fio将使用pthread_create来创建线程
    rw=randwrite 测试随机写的I/O
    rw=randrw 测试随机写和读的I/O
    bs=4k 单次io的块文件大小为4k
    bsrange=512-2048 同上,提定数据块的大小范围,可通过tune2fs -l /dev/sda1|grep "Block size" 获取。
    size=10g 本次的测试文件大小为10g,以每次4k的io进行测试。
    numjobs=10 本次的测试线程为10.
    runtime=300 测试时间为300秒,如果不写测试时间,则一直将10g文件分4k每次写完为止。
    ioengine=psync io引擎使用pync方式
    rwmixwrite=30 在混合读写的模式下,写占30%
    rwmixread=70 在混合读写的模式下,读占70%
    group_reporting 关于显示结果的,汇总每个进程的信息。
    lockmem=1g 只使用1g内存进行测试。
    zero_buffers 用0初始化系统buffer。
    nrfiles=8 每个进程生成文件的数量。
    write_bw_log=str 在job file写这个job的带宽日志。可以在他们的生命周期内存储job的带宽数据。内部的fio_generate_plots脚本可以使用gnuplot将这些文本转化成图。

    测试过程中显示数据说明:
    Starting 10 threads
    Jobs: 10 (f=10): [m(10)] [100.0% done] [4512KB/1908KB/0KB /s] [1128/477/0 iops] [eta 00m:00s]

    测试结果数据说明:
    顺序读、写看主要看bw,随机读、写主要看iops
   

    read : io=1183.9MB, bw=4040.7KB/s, iops=1010, runt=300011msec      ##IO数据量读为1183.9MB,带宽为4040.7KB/s,IOPS为1010,运行时间是300011毫秒
   
write: io=518284KB, bw=1727.6KB/s, iops=431, runt=300011msec        ##IO数据量写为518284KB,带宽为1727KB/s,IOPS为431,运行时间是300011毫秒

    Run status group 0 (all jobs):
       READ: io=1183.9MB, aggrb=4040KB/s, minb=4040KB/s, maxb=4040KB/s, mint=300011msec, maxt=300011msec  ##读IO数据量、平均总带宽、最小带宽、最大带宽、线程最短运行时间、线程最长运行时间
      WRITE: io=518284KB, aggrb=1727KB/s, minb=1727KB/s, maxb=1727KB/s, mint=300011msec, maxt=300011msec ##

    Disk stats (read/write):
      sda: ios=303136/129596, merge=18/25, ticks=2943520/45552, in_queue=2989060, util=100.00%  ##所有IO数读为303136/写为129596,IO合并数读为18/写为25,磁盘票据繁忙数读2943520/写45552,磁盘花在队列上的时间为2989060毫秒,磁盘利用率为100%

    输出结果说明参考
    在运行时,fio将打印当前job创建的状态
    Threads: 1: [_r] [24.8% done] [ 13509/  8334 kb/s] [eta 00h:01m:31s]
    生命周期
    P   线程已经启动,还没有启动
    C 线程启动
    I 纯种已经初始化,等待中
    p 线程运行中,预读文件
    R 顺序读
    r 随机读
    W 顺序写
    w 随机写
    M 混合顺序读写
    m 混合随机读写
    F 等待执行fsync()
    V 运行,检验写的数据
    E 线程退出,还没有被主线程获取状态_ Thread reaped, or
    X Thread reaped, exited with an error.
    K Thread reaped, exited due to signal.
    其它的值都是可以自解释的:
    当前正在运行的IO线程数。
    从上次检查之后的IO速度(读速度/写速度)
    估计的完成百分比
    整个group的估计完成时间
    当fio完成的时候(或是通过ctrl-c终止的时候),将会打印每一个线程的数据,每个group的数据,和磁盘数据。
    io= 执行了多少M的IO
    bw= 平均IO带宽
    iops=   IOPS
    runt= 线程运行时间
    slat 提交延迟
    clat 完成延迟
    lat响应时间
    bw 带宽
    cpu利用率
    IO depths=io队列
    IO submit=单个IO提交要提交的IO数
    IO complete= Like the above submit number, but for completions instead.
    IO issued= The number of read/write requests issued, and how many of them were short.
    IO latencies=IO完延迟的分布
    io= 总共执行了多少size的IO
    aggrb= group总带宽
    minb= 最小平均带宽.
    maxb= 最大平均带宽.
    mint= group中线程的最短运行时间.
    maxt= group中线程的最长运行时间.
    ios= 所有group总共执行的IO数.
    merge= 总共发生的IO合并数.
    ticks= Number of ticks we kept the disk busy.
    io_queue= 花费在队列上的总共时间.
    util= 磁盘利用率

    5)FIO附录
    5-1)fio命令选项:
    --debug            Enable some debugging options (see below)
    --parse-only        Parse options only, don't start any IO
    --output        Write output to file                将输出内容写入指定文件中
    --runtime        Runtime in seconds                fio测试时间,单位是秒
    --bandwidth-log        Generate per-job bandwidth logs
    --minimal        Minimal (terse) output
    --output-format=type    Output format (terse,json,json+,normal)        输出文件格式,默认是normal
    --terse-version=type    Terse version output format (default 3, or 2 or 4).
    --version        Print version info and exit
    --help            Print this page
    --cpuclock-test        Perform test/validation of CPU clock
    --crctest[=test]    Test speed of checksum functions
    --cmdhelp=cmd        Print command help, "all" for all of them
    --enghelp=engine    Print ioengine help, or list available ioengines FIO支持的引擎,默认有
    --enghelp=engine,cmd    Print help for an ioengine cmd
    --showcmd        Turn a job file into command line options
    --readonly        Turn on safety read-only checks, preventing
                writes
    --eta=when        When ETA estimate should be printed
                May be "always", "never" or "auto"
    --eta-newline=time    Force a new line for every 'time' period passed
    --status-interval=t    Force full status dump every 't' period passed
    --section=name        Only run specified section in job file.
                Multiple sections can be specified.
    --alloc-size=kb        Set smalloc pool to this size in kb (def 1024)
    --warnings-fatal    Fio parser warnings are fatal
    --max-jobs        Maximum number of threads/processes to support
    --server=args        Start backend server. See Client/Server section.
    --client=host        Connect to specified backend(s).
    --remote-config=file    Tell fio server to load this local file
    --idle-prof=option    Report cpu idleness on a system or percpu basis
                (option=system,percpu) or run unit work
                calibration only (option=calibrate).
    --inflate-log=log    Inflate and output compressed log
    --trigger-file=file    Execute trigger cmd when file exists
    --trigger-timeout=t    Execute trigger af this time
    --trigger=cmd        Set this command as local trigger
    --trigger-remote=cmd    Set this command as remote trigger
    --aux-path=path        Use this path for fio state generated files
    
    5-2)单盘IOPS计算:
    常见磁盘平均物理寻道时间为:
    7200转/分的STAT硬盘平均物理寻道时间是9ms
    10000转/分的STAT硬盘平均物理寻道时间是6ms
    15000转/分的SAS硬盘平均物理寻道时间是4ms

    常见硬盘的旋转延迟时间为:
    7200   rpm的磁盘平均旋转延迟大约为60*1000/7200/2 = 4.17ms
    10000 rpm的磁盘平均旋转延迟大约为60*1000/10000/2 = 3ms,
    15000 rpm的磁盘其平均旋转延迟约为60*1000/15000/2 = 2ms。

    最大IOPS的理论计算方法
    --------------------------------------
    IOPS = 1000 ms/ (寻道时间 + 旋转延迟)。可以忽略数据传输时间。

    7200  rpm的磁盘 IOPS = 1000 / (9 + 4.17)  = 76 IOPS
    10000 rpm的磁盘IOPS = 1000 / (6+ 3) = 111 IOPS
    15000 rpm的磁盘IOPS = 1000 / (4 + 2) = 166 IOPS

    5-3)ioengine=str定义job向文件发起IO的方式
    sync 基本的read,write.lseek用来作定位
    psync 基本的pread,pwrite
    vsync 基本的readv,writev
    libaio Linux专有的异步IO。Linux仅支持非buffered IO的队列行为。
    posixaio glibc posix异步IO
    solarisaio solaris独有的异步IO
    windowsaio windows独有的异步IO
    mmap 文件通过内存映射到用户空间,使用memcpy写入和读出数据
    splice 使用splice和vmsplice在用户空间和内核之间传输数据
    syslet-rw 使用syslet 系统调用来构造普通的read/write异步IO
    sg SCSI generic sg v3 io.可以是使用SG_IO ioctl来同步,或是目标是一个sg字符设备,我们使用read和write执行异步IO
    null 不传输任何数据,只是伪装成这样。主要用于训练使用fio,或是基本debug/test的目的。
    net 根据给定的host:port通过网络传输数据。根据具体的协议,hostname,port,listen,filename这些选项将被用来说明建立哪种连接,协议选项将决定哪种协议被使用。
    netsplice 像net,但是使用splic/vmsplice来映射数据和发送/接收数据。
    cpuio 不传输任何的数据,但是要根据cpuload=和cpucycle=选项占用CPU周期.e.g. cpuload=85将使用job不做任何的实际IO,但要占用85%的CPU周期。在SMP机器上,使用numjobs=<no_of_cpu>来获取需要的CPU,因为cpuload仅会载入单个CPU,然后占用需要的比例。
    5-4)dd命令
    dd命令语法:
    CODE:[Copy to clipboard]dd 〔选项〕
    选项:
    if =输入文件(或设备名称)。
    of =输出文件(或设备名称)。
    ibs = bytes 一次读取bytes字节,即读入缓冲区的字节数。
    skip = blocks 跳过读入缓冲区开头的ibs*blocks块。
    obs = bytes 一次写入bytes字节,即写 入缓冲区的字节数。
    bs = bytes 同时设置读/写缓冲区的字节数(等于设置obs和obs)。
    cbs = bytes 一次转换bytes字节。
    count = blocks 只拷贝输入的blocks块。
    conv = ASCII 把EBCDIC码转换为ASCII码。
    conv = ebcdic 把ASCII码转换为EBCDIC码。
    conv = ibm 把ASCII码转换为alternate EBCDIC码。
    conv = blick 把变动位转换成固定字符。
    conv = ublock 把固定们转换成变动位
    conv = ucase 把字母由小写变为大写。
    conv = lcase 把字母由大写变为小写。
    conv = notrunc 不截短输出文件。
    conv = swab 交换每一对输入字节。
    conv = noerror 出错时不停止处理。
    conv = sync 把每个输入记录的大小都调到ibs的大小(用ibs填充)。

    查看os系统块的大小
    tune2fs -l /dev/sda1 |grep 'Block size'
    Block size:               4096

    查看os系统页的大小
    getconf PAGESIZE

    磁盘管理
    (1)得到最恰当的block size
    通过比较dd指令输出中所显示的命令执行时间,即可确定系统最佳的block size大小:
    dd if=/dev/zero bs=1024 count=1000000 of=/root/1Gb.file
    dd if=/dev/zero bs=4096 count=250000 of=/root/1Gb.file
    dd if=/dev/zero bs=8192 count=125000 of=/root/1Gb.file
    (2)测试硬盘读写速度
    通过两个命令输出的执行时间,可以计算出测试硬盘的读/写速度:
    dd if=/root/1Gb.file bs=64k of=/dev/null
    dd if=/dev/zero of=/root/1Gb.file bs=1024 count=1000000
    (3)修复硬盘
    当硬盘较长时间(比如一两年年)放置不使用后,磁盘上会产生magnetic flux point。当磁头读到
    这些区域时会遇到困难,并可能导致I/O错误。当这种情况影响到硬盘的第一个扇区时,可能导致
    硬盘报废。下面的命令有可能使这些数据起死回生。且这个过程是安全,高效的。
    dd if=/dev/sda of=/dev/sda





来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27067062/viewspace-2124079/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/27067062/viewspace-2124079/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值