Help us learn about your current experience with the documentation. Take the survey.

文件系统性能基准测试

  • 版本:Free, Premium, Ultimate
  • 产品:GitLab Self-Managed

文件系统性能对 GitLab 的整体性能影响巨大,尤其是在读写 Git 仓库的操作中。本文档旨在帮助您将文件系统的性能与已知表现良好和不佳的实际系统进行基准测试对比。

谈及文件系统性能时,网络文件系统 (NFS) 是最主要的关注点。但即便是一些本地磁盘,其 I/O 性能也可能很慢。本页面的信息对这两种场景都适用。

执行基准测试

使用 fio 进行基准测试

您应该使用 Fio 来测试 I/O 性能。此测试应在 NFS 服务器以及与 NFS 服务器通信的应用程序节点上运行。

安装方法:

  • 在 Ubuntu 上:apt install fio
  • 在使用 yum 的环境中:yum install fio

然后运行以下命令:

fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --bs=4k --iodepth=64 --readwrite=randrw --rwmixread=75 --size=4G --filename=/path/to/git-data/testfile

这会在 /path/to/git-data/testfile 创建一个 4 GB 的文件。它会以 75%/25% 的读写比例对文件执行 4 KB 的读写操作,同时运行 64 个操作。测试完成后,请务必删除该文件。

输出内容会根据安装的 fio 版本而有所不同。以下是在网络固态硬盘 (SSD) 上运行的 fio v2.2.10 的示例输出:

test: (g=0): rw=randrw, bs=4K-4K/4K-4K/4K-4K, ioengine=libaio, iodepth=64
    fio-2.2.10
    Starting 1 process
    test: Laying out IO file(s) (1 file(s) / 1024MB)
    Jobs: 1 (f=1): [m(1)] [100.0% done] [131.4MB/44868KB/0KB /s] [33.7K/11.3K/0 iops] [eta 00m:00s]
    test: (groupid=0, jobs=1): err= 0: pid=10287: Sat Feb  2 17:40:10 2019
      read : io=784996KB, bw=133662KB/s, iops=33415, runt=  5873msec
      write: io=263580KB, bw=44880KB/s, iops=11219, runt=  5873msec
      cpu          : usr=6.56%, sys=23.11%, ctx=266267, majf=0, minf=8
      IO depths    : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=0.1%, 32=0.1%, >=64=100.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.1%, >=64=0.0%
         issued    : total=r=196249/w=65895/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0
         latency   : target=0, window=0, percentile=100.00%, depth=64

    Run status group 0 (all jobs):
       READ: io=784996KB, aggrb=133661KB/s, minb=133661KB/s, maxb=133661KB/s, mint=5873msec, maxt=5873msec
      WRITE: io=263580KB, aggrb=44879KB/s, minb=44879KB/s, maxb=44879KB/s, mint=5873msec, maxt=5873msec

请注意此输出中的 iops 值。在此示例中,该 SSD 每秒执行了 33,415 次读取操作和 11,219 次写入操作。而一块机械硬盘每秒可能只能产生 2,000 次读取和 700 次写入操作。

简单基准测试

此测试方法比较简单,适用于系统上没有安装 fio 的情况。需要注意的是,即使此测试结果良好,由于读取速度及其他多种因素,实际性能可能仍然不佳。

以下单行命令可快速对文件系统的写入和读取性能进行基准测试。它会向执行命令的目录中写入 1,000 个小文件,然后再读取这 1,000 个文件。

  1. 切换到相应的 仓库存储路径 的根目录。

  2. 为测试创建一个临时目录,以便稍后可以将其删除:

    mkdir test; cd test
  3. 运行命令:

    time for i in {0..1000}; do echo 'test' > "test${i}.txt"; done
  4. 要对读取性能进行基准测试,请运行命令:

    time for i in {0..1000}; do cat "test${i}.txt" > /dev/null; done
  5. 删除测试文件:

    cd ../; rm -rf test

time for ... 命令的输出类似于以下内容。其中重要的指标是 real(实际)时间。

$ time for i in {0..1000}; do echo 'test' > "test${i}.txt"; done

real    0m0.116s
user    0m0.025s
sys     0m0.091s

$ time for i in {0..1000}; do cat "test${i}.txt" > /dev/null; done

real    0m3.118s
user    0m1.267s
sys 0m1.663s

根据与多位客户的经验,此任务应在 10 秒内完成,以表明文件系统性能良好。