更新时间:2026-09-03 GMT+08:00
分享

本地盘性能测试指导

操作场景

本文用于指导如何测试本地盘性能,用于获取本地盘随机写IOPS、随机读IOPS、顺序写带宽、顺序读带宽、随机写时延以及随机读时延等性能指标。

环境准备

  1. 远程登录云服务器实例。

    详细操作,请参见Linux BMS登录方式概述

  2. 执行以下命令,查询本地盘的设备名称。
    sudo fdisk -lu

    若出现如下执行结果,表示该云服务器有4块本地盘,每块本地盘大小为6.99 TiB。

    图1 查询结果
  3. 执行以下命令,安装libaio库和测试工具FIO。

    HCE OS或CentOS操作系统:

    sudo yum install libaio libaio-devel fio -y

    Ubuntu操作系统:

    sudo apt-get update
    sudo apt-get install libaio* fio -y

本地盘性能测试

下面的测试步骤为示例内容,取值仅供参考,实际测试时请根据实际情况进行替换。命令中的/dev/your_device需根据实际情况,替换为步骤2中获取的待测试块存储名称。

例如,

  • 如果需要测试的本地盘设备名为/dev/nvme0n1,则需将以下示例命令中的/dev/your_device替换为/dev/nvme0n1。
  • 如果需要测试多块盘的性能,则在后面加上多块盘名称,比如测试四块盘,将-name /dev/your_device替换成: -name /dev/nvme0n1 -name /dev/nvme1n1 -name /dev/nvme2n1 -name /dev/nvme3n1 。
  1. 执行以下命令,测试本地盘的随机写IOPS。
    sudo fio -ioengine=libaio -thread -direct=1 -ramp_time=5 -bs=4k -rw=randwrite -iodepth=32 -numjobs=8 -size=0 -runtime=2400 -time_based -norandommap -randrepeat=0 -name /dev/your_device
  2. 执行以下命令,测试本地盘的随机读IOPS。
    sudo fio -ioengine=libaio -thread -direct=1 -ramp_time=5 -bs=4k -rw=randread -iodepth=128 -numjobs=8 -size=0 -runtime=120 -time_based -norandommap -randrepeat=0 -name /dev/your_device
  3. 执行以下命令,测试本地盘的顺序写带宽。
    fio -ioengine=libaio -thread -direct=1 -ramp_time=5 -bs=1024k -rw=write -iodepth=8 -size=0 -runtime=2400 -time_based -norandommap -randrepeat=0 -name /dev/your_device
  4. 执行以下命令,测试本地盘的顺序读带宽。
    fio -ioengine=libaio -thread -direct=1 -ramp_time=5 -bs=1024k -rw=read -iodepth=8 -size=0 -runtime=120 -time_based -norandommap -randrepeat=0 -name /dev/your_device
  5. 执行以下命令,测试本地盘的随机写时延。
    sudo fio -ioengine=libaio -thread -direct=1 -ramp_time=5 -bs=4k -rw=randwrite -iodepth=1 -size=0 -runtime=300 -time_based -norandommap -randrepeat=0 -name /dev/your_device
  6. 执行以下命令,测试本地盘的随机读时延。
    sudo fio -ioengine=libaio -thread -direct=1 -ramp_time=5 -bs=4k -rw=randread -iodepth=1 -size=0 -runtime=120 -time_based -norandommap -randrepeat=0 -name /dev/your_device

查看性能测试结果

  • IOPS相关测试结果请参考IOPS=***内容。

    以下为fio随机写(Rand_Write)测试结果示例,其中write行的IOPS=2301为随机写性能关键指标。

    Starting 1 process
    Jobs: 1 (f=0): [f(1)][100.0%][w=9061KiB/s][w=2265 IOPS][eta 00m:00s]
    Rand_Write Testing: (groupid=0, jobs=1): err= 0: pid=15900: Tue Nov 19 11:28:24 2024
      write: IOPS=2301, BW=9206KiB/s (9427kB/s)(1024MiB/113896msec); 0 zone resets
        slat (usec): min=2, max=1718, avg= 5.43, stdev= 7.98
        clat (usec): min=382, max=119809, avg=55606.05, stdev=7040.12
        lat (usec): min=394, max=119812, avg=55611.49, stdev=7039.41
        clat percentiles (msec):
         |  1.00th=[    9],  5.00th=[   51], 10.00th=[   51], 20.00th=[   51],
         | 30.00th=[   51], 40.00th=[   57], 50.00th=[   60], 60.00th=[   61],
         | 70.00th=[   61], 80.00th=[   61], 90.00th=[   61], 95.00th=[   61],
         | 99.00th=[   63], 99.50th=[   65], 99.90th=[   67], 99.95th=[   77],
         | 99.99th=[  101]
       bw (  KiB/s): min= 9000, max=28976, per=100.00%, avg=9213.14, stdev=1317.97, samples=227
       iops        : min= 2250, max= 7244, avg=2303.28, stdev=329.49, samples=227
      lat (usec)   : 500=0.01%, 750=0.01%, 1000=0.01%
      lat (msec)   : 2=0.03%, 4=0.45%, 10=0.52%, 20=0.04%, 50=0.82%
      lat (msec)   : 100=98.11%, 250=0.01%
  • 吞吐量相关测试结果请参考BW=***内容。

    如下所示BW=130MB/s为带宽关键指标。

    Jobs: 1 (f=1): [W(1)][100.0%][w=85.0MiB/s][w=85 IOPS][eta 00m:00s]
    Write_PPS_Testing: (groupid=0, jobs=1): err= 0: pid=17934: Tue Nov 19 11:32:19 2024
      write: IOPS=124, BW=124MiB/s (130MB/s)(1024MiB/8229msec); 0 zone resets
        slat (usec): min=27, max=4026, avg=94.51, stdev=125.97
        clat (msec): min=4, max=1154, avg=513.48, stdev=208.14
         lat (msec): min=4, max=1154, avg=513.57, stdev=208.15
        clat percentiles (msec):
         |  1.00th=[   17],  5.00th=[   75], 10.00th=[   93], 20.00th=[  567],
         | 30.00th=[  584], 40.00th=[  584], 50.00th=[  584], 60.00th=[  584],
         | 70.00th=[  584], 80.00th=[  584], 90.00th=[  592], 95.00th=[  693],
         | 99.00th=[ 1062], 99.50th=[ 1099], 99.90th=[ 1133], 99.95th=[ 1150],
         | 99.99th=[ 1150]
       bw (  KiB/s): min=30720, max=356352, per=96.43%, avg=122881.25, stdev=65548.59, samples=16
       iops        : min=   30, max=  348, avg=120.00, stdev=64.01, samples=16
      lat (msec)   : 10=0.49%, 20=0.68%, 50=2.15%, 100=10.74%, 250=1.86%
      lat (msec)   : 500=3.22%, 750=76.46%, 1000=2.73%, 2000=1.66%
      cpu          : usr=0.89%, sys=0.45%, ctx=1025, majf=0, minf=10
      IO depths    : 1=0.1%, 2=0.2%, 4=0.4%, 8=0.8%, 16=1.6%, 32=3.1%, >=64=93.8%
         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=99.9%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.1%, >=64=0.0%
         issued rwts: total=0 1024 0 0 short=0 0 0 0 dropped=0 0 0 0
  • 时延相关测试结果请参考lat(usec)内容。

    延迟相关测试结果请参考总延迟统计行lat (usec): min=254, max=169188, avg=432.25, stdev=487.95,平均延迟约432微秒。

    Jobs: 1 (f=1): [w(1)][100.0%][w=9169KiB/s][w=2292 IOPS][eta 00m:00s]
    Rand_Write_Latency_Testing: (groupid=0, jobs=1): err= 0: pid=19530: Tue Nov 19 11:38:31 2024
      write: IOPS=2301, BW=9206KiB/s (9427kB/s)(1024MiB/113903msec); 0 zone resets
        slat (usec): min=2, max=19160, avg= 8.68, stdev=40.53
        clat (usec): min=3, max=169175, avg=423.57, stdev=486.23
         lat (usec): min=254, max=169188, avg=432.25, stdev=487.95
        clat percentiles (usec):
         |  1.00th=[  334],  5.00th=[  343], 10.00th=[  347], 20.00th=[  351],
         | 30.00th=[  355], 40.00th=[  359], 50.00th=[  367], 60.00th=[  371],
         | 70.00th=[  379], 80.00th=[  396], 90.00th=[  465], 95.00th=[  562],
         | 99.00th=[ 1614], 99.50th=[ 2671], 99.90th=[ 5735], 99.95th=[ 6194],
         | 99.99th=[ 7439]
       bw (  KiB/s): min= 5840, max=10416, per=100.00%, avg=9211.26, stdev=495.72, samples=227
       iops        : min= 1460, max= 2604, avg=2302.80, stdev=123.94, samples=227
      lat (usec)   : 4=0.01%, 10=0.01%, 50=0.01%, 100=0.01%, 250=0.01%
      lat (usec)   : 500=93.01%, 750=4.06%, 1000=0.97%
      lat (msec)   : 2=1.23%, 4=0.42%, 10=0.30%, 20=0.01%, 50=0.01%
      lat (msec)   : 250=0.01%
      cpu          : usr=0.84%, sys=3.00%, ctx=262469, majf=0, minf=10
  • 由于部分fio numjob较多,为方便统计,建议测试指令输入完毕后,直接在云服务器上查看测试数据。

    执行以下命令:

    iostat -xm 1

    其中,rMB/s为读带宽,wMB/s为写带宽,r/s为读IOPS,w/s为写IOPS。

FIO参数说明

测试命令中FIO各参数含义如表1所示。
表1 FIO参数说明

参数

说明

direct

表示是否使用direct I/O。

  • 1:表示使用direct I/O,忽略I/O缓存,数据直接写入。
  • 0:表示不使用direct I/O。

默认值:1。

iodepth

表示测试时的IO队列深度。例如-iodepth=128表示FIO控制请求中的I/O最大个数为128。

rw

表示测试时的读写策略。

  • randwrite:随机写。
  • randread:随机读。
  • read:顺序读。
  • write:顺序写。
  • randrw:混合随机读写。

ioengine

表示测试时FIO选择哪种I/O引擎,通常选择libaio,更符合日常应用模式,更多的选择请查阅FIO官方文档。

bs

表示I/O单元的块大小(block size)。读取和写入的值可以以read、write格式单独指定,其中任何一个都可以为空以将该值保留为其默认值。

默认值:4 KiB。

size

表示测试文件大小。

FIO会将指定的文件大小全部读/写完成,然后才停止测试,除非受到其他选项(例如运行时)的限制。如果未指定该参数,FIO将使用给定文件或设备的完整大小。也可以将大小作为1到100之间的百分比给出。

例如指定size=20%,FIO将使用给定文件或设备完整大小的20%空间。

numjobs

表示测试的并发线程数。

默认值:1。

runtime

表示测试时间,即FIO运行时长。

如果未指定该参数,则FIO会持续将上述size指定大小的文件,以每次bs值为块大小读/写完成。

group_reporting

表示测试结果显示模式。

如果指定该参数,测试结果会汇总每个进程的统计信息,而不是以不同任务来统计信息。

filename

表示待测试的对象路径,路径可以是云盘设备名称或者一个文件地址。本文中的FIO测试全部是以整盘为测试对象,不含文件系统,即裸盘测试。同时为了避免误测试到其他盘导致数据被破坏,本示例地址为/dev/your_device,请您正确替换。

name

表示测试任务名称,可以随意设定。例如本示例的Rand_Write_Testing。

相关文档