当前位置:首页 > 技术 > 正文内容

云平台与分布式存储的性能测试实践

访客 技术 2026年7月30日 1

在云平台运维和分布式存储部署过程中,性能评估是至关重要的一环。本文将介绍我在实际项目中使用的性能测试方法,涵盖虚拟机各项性能指标以及Ceph对象存储的基准测试。

性能测试的关键指标

性能测试涵盖多个维度,就我参与的项目而言,主要包括两类场景:云平台虚拟机能性能评估和Ceph分布式存储性能验证。

虚拟机性能测试指标:

  • 网络吞吐能力:跨物理主机部署的两台虚拟机之间的网络带宽上限
  • 存储I/O性能:虚拟磁盘的IOPS和吞吐量表现
  • 处理器计算能力:虚拟机可获得的CPU计算资源
  • 内存访问带宽:虚拟机内存读写的数据传输速率

Ceph存储性能指标:

  • 吞吐量:系统每秒能够处理的I/O请求数量
  • 延迟:单个请求的平均响应时长
  • 并发承载力:系统稳定运行时的最大并发连接数

虚拟机性能测试详解

网络带宽测试

使用iperf3工具可以测量网络链路的最大带宽。测试时需要准备两台位于不同物理宿主机上的虚拟机,分别作为服务端和客户端。

服务端配置:

# iperf3 -s -p 5001
-----------------------------------------------------------
Server listening on 5001
-----------------------------------------------------------

客户端配置:

# iperf3 -c 192.168.0.20 -p 5001 -t 60
-----------------------------------------------------------
Connecting to host 192.168.0.20, port 5001
[  4] local 192.168.0.15 port 48792 connected to 192.168.0.20 port 5001
[ ID] Interval           Transfer     Bandwidth
[  4]   0.00-60.00  sec  11.2 GBytes  1.60 Gbits/sec
-----------------------------------------------------------

完整的网络性能评估应包含三组对比数据:

测试场景内网带宽
虚拟机间(跨宿主机)
虚拟机与宿主机间
宿主机之间

通过对比可以计算虚拟化层的网络性能损耗:

网络性能损耗 = (宿主机间带宽 - 虚拟机间带宽) / 宿主机间带宽 × 100%

磁盘I/O性能测试

fio是专业的磁盘I/O基准测试工具,支持多达19种I/O引擎模式。

为虚拟机添加第二块虚拟磁盘(vdc),执行fio测试:

# fio -name="storage_perf_test" -ioengine=libaio -direct=1 -thread \
  -filename=/dev/vdc -time_based -runtime=60 -bs=4k -iodepth=32 -rw=randread

storage_perf_test: (g=0): rw=randread, bs=4K-4K/4K-4K/4K-4K, ioengine=libaio, iodepth=32
fio-3.30
Starting 4 threads
Jobs: 4 (f=4): [r(4)][100.0% done] [256.8MB/0KB/0KB /s] [65.7K/0/0 iops] [eta 00m:00s]
storage_perf_test: (groupid=0, jobs=4): err= 0: pid=8291: Thu Jun  2 10:15:22 2022
  read : io=15483MB, bw=264512KB/s, iops=66128, runt= 60001msec
    slat (usec): min=3, max=892, avg= 8.42, stdev= 5.17
    clat (usec): min=412, max=185420, avg=1923.51, stdev=1531.28
     lat (usec): min=718, max=185425, avg=1932.18, stdev=1531.15
    clat percentiles (usec):
     |  1.00th=[ 1712],  5.00th=[ 1784], 10.00th=[ 1824], 20.00th=[ 1856],
     | 30.00th=[ 1888], 40.00th=[ 1920], 50.00th=[ 1952], 60.00th=[ 1984],
     | 70.00th=[ 2016], 80.00th=[ 2048], 90.00th=[ 2128], 95.00th=[ 2176],
     | 99.00th=[ 2912], 99.50th=[ 3008], 99.90th=[ 3488], 99.95th=[ 3712],
     | 99.99th=[ 7520]
    bw (KB  /s): min=58240, max=71168, per=25.00%, avg=66128.00, stdev=3251.42
    lat (usec) : 500=0.01%, 750=0.02%, 1000=0.01%
    lat (msec) : 2=68.42%, 4=31.56%, 10=0.01%, 250=0.01%
  cpu          : usr=12.35%, sys=28.41%, ctx=192845, majf=0, minf=68
  IO depths    : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=0.1%, 32=99.8%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.1%, >=64=0.0%
     issued    : total=r=3969021/w=0/d=0, short=r=0/w=0/d=0
     latency   : target=0, window=0, percentile=100.00%, depth=32
Run status group 0 (all jobs):
   READ: io=15483MB, aggrb=264512KB/s, minb=264512KB/s, maxb=264512KB/s, mint=60001msec, maxt=60001msec
Disk stats (read/write):
  vdc: ios=3969021/0, merge=0/0, ticks=7638451/0, in_queue=7632158, util=98.12%

关键参数说明:

  • -ioengine:I/O引擎类型,libaio为Linux原生异步I/O
  • -direct:设为1时绕过系统缓存,直接与磁盘交互
  • -filename:指定测试的块设备路径
  • -runtime:测试持续时间(秒)
  • -bs:单次I/O操作的块大小
  • -iodepth:I/O队列深度,影响并发能力
  • -rw:读写模式(read/write/randread/randwrite)

重点关注指标:bw(带宽)和iops(每秒I/O次数)。通常随机读性能优于顺序读,顺序写性能优于随机写。

CPU性能测试

采用UnixBench进行综合性能评估。该工具是开源的Unix系统基准测试套件,能够全面评估主机系统的计算能力。

UnixBench的测试结果反映的是系统综合性能,与CPU、内存、存储和操作系统都有关系,但CPU影响最为显著。测试时需要分别在虚拟机和宿主机上运行,通过对比评估虚拟化性能开销。

测试项目概览:

  • Dhrystone 2:整数运算性能测试,主要考察字符串处理能力
  • Whetstone:浮点运算性能测试,包含数学函数和数组操作
  • Execl Throughput:进程创建和执行能力
  • File Copy:文件读写复制性能
  • Pipe Throughput:进程间管道通信能力
  • Context Switching:进程上下文切换性能
  • Shell Scripts:shell脚本并发执行能力
  • System Call Overhead:系统调用开销

虚拟机测试配置: 2核CPU / 4GB内存 / 40GB磁盘

# ./Run -c 2
------------------------------------------------------------------------
Benchmark Run: 四 6月  2 2022 09:20:15 - 09:48:32
2 CPUs in system; running 2 parallel copies of tests
Dhrystone 2 using register variables       48235491.6 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     5834.7 MWIPS (9.9 s, 7 samples)
Execl Throughput                               5412.3 lps   (29.9 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks       1287654.2 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          342187.5 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       3298471.8 KBps  (30.0 s, 2 samples)
Pipe Throughput                             2318472.5 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                 428563.7 lps   (10.0 s, 7 samples)
Process Creation                              18472.6 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   3205.4 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                    812.6 lpm   (60.2 s, 2 samples)
System Call Overhead                        2589371.4 lps   (10.0 s, 7 samples)
System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   48235491.6   4133.2
Double-Precision Whetstone                       55.0       5834.7   1060.8
Execl Throughput                                 43.0       5412.3   1258.7
File Copy 1024 bufsize 2000 maxblocks          3960.0    1287654.2   3251.7
File Copy 256 bufsize 500 maxblocks            1655.0     342187.5   2067.6
File Copy 4096 bufsize 8000 maxblocks          5800.0    3298471.8   5687.0
Pipe Throughput                               12440.0    2318472.5   1863.7
Pipe-based Context Switching                   4000.0     428563.7   1071.4
Process Creation                                126.0      18472.6   1466.2
Shell Scripts (1 concurrent)                     42.4       3205.4    755.9
Shell Scripts (8 concurrent)                      6.0        812.6   1354.3
System Call Overhead                          15000.0    2589371.4   1726.2
                                                                   ========
System Benchmarks Index Score                                        1789.5

宿主机测试结果对比:

# ./Run -c 2
... ...
------------------------------------------------------------------------
Benchmark Run: 四 6月  2 2022 16:45:20 - 17:13:41
12 CPUs in system; running 2 parallel copies of tests
Dhrystone 2 using register variables       51872635.8 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     6415.2 MWIPS (9.9 s, 7 samples)
Execl Throughput                               5871.5 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        958472.6 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          254813.9 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       2816452.7 KBps  (30.0 s, 2 samples)
Pipe Throughput                             2738195.8 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                 265482.3 lps   (10.0 s, 7 samples)
Process Creation                              17358.4 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                  11854.7 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                   4298.2 lpm   (60.0 s, 2 samples)
System Call Overhead                        2948271.6 lps   (10.0 s, 7 samples)
System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   51872635.8   4444.9
Double-Precision Whetstone                       55.0       6415.2   1166.4
Execl Throughput                                 43.0       5871.5   1365.5
File Copy 1024 bufsize 2000 maxblocks          3960.0     958472.6   2420.4
File Copy 256 bufsize 500 maxblocks            1655.0     254813.9   1539.6
File Copy 4096 bufsize 8000 maxblocks          5800.0    2816452.7   4855.9
Pipe Throughput                               12440.0    2738195.8   2201.1
Pipe-based Context Switching                   4000.0     265482.3    663.7
Process Creation                                126.0      17358.4   1377.6
Shell Scripts (1 concurrent)                     42.4      11854.7   2795.9
Shell Scripts (8 concurrent)                      6.0       4298.2   7163.7
System Call Overhead                          15000.0    2948271.6   1965.5
                                                                   ========
System Benchmarks Index Score                                        2187.3

性能损耗计算:(2187.3 - 1789.5) / 2187.3 × 100% = 18.19%

内存性能测试

使用mbw工具测试内存拷贝带宽,评估用户空间程序的内存访问性能。

虚拟机内存测试:

# mbw 1024
Long uses 8 bytes. Allocating 2*134217728 elements = 2147483648 bytes of memory.
Using 262144 bytes as blocks for memcpy block copy test.
Getting down to business... Doing 10 runs per test.
0       Method: MEMCPY  Elapsed: 0.42581        MiB: 1024.00000 Copy: 2405.182 MiB/s
1       Method: MEMCPY  Elapsed: 0.42634        MiB: 1024.00000 Copy: 2401.467 MiB/s
2       Method: MEMCPY  Elapsed: 0.42592        MiB: 1024.00000 Copy: 2404.715 MiB/s
3       Method: MEMCPY  Elapsed: 0.42658        MiB: 1024.00000 Copy: 2399.124 MiB/s
4       Method: MEMCPY  Elapsed: 0.42547        MiB: 1024.00000 Copy: 2407.382 MiB/s
5       Method: MEMCPY  Elapsed: 0.42621        MiB: 1024.00000 Copy: 2402.847 MiB/s
6       Method: MEMCPY  Elapsed: 0.42568        MiB: 1024.00000 Copy: 2406.524 MiB/s
7       Method: MEMCPY  Elapsed: 0.42645        MiB: 1024.00000 Copy: 2400.328 MiB/s
8       Method: MEMCPY  Elapsed: 0.42539        MiB: 1024.00000 Copy: 2408.125 MiB/s
9       Method: MEMCPY  Elapsed: 0.42612        MiB: 1024.00000 Copy: 2403.516 MiB/s
AVG     Method: MEMCPY  Elapsed: 0.42594        MiB: 1024.00000 Copy: 2403.921 MiB/s
0       Method: DUMB    Elapsed: 0.23892        MiB: 1024.00000 Copy: 4286.845 MiB/s
1       Method: DUMB    Elapsed: 0.23914        MiB: 1024.00000 Copy: 4281.427 MiB/s
2       Method: DUMB    Elapsed: 0.23876        MiB: 1024.00000 Copy: 4288.124 MiB/s
3       Method: DUMB    Elapsed: 0.23928        MiB: 1024.00000 Copy: 4278.315 MiB/s
4       Method: DUMB    Elapsed: 0.23853        MiB: 1024.00000 Copy: 4292.476 MiB/s
5       Method: DUMB    Elapsed: 0.23885        MiB: 1024.00000 Copy: 4287.218 MiB/s
6       Method: DUMB    Elapsed: 0.23901        MiB: 1024.00000 Copy: 4284.512 MiB/s
7       Method: DUMB    Elapsed: 0.23935        MiB: 1024.00000 Copy: 4277.084 MiB/s
8       Method: DUMB    Elapsed: 0.23869        MiB: 1024.00000 Copy: 4289.347 MiB/s
9       Method: DUMB    Elapsed: 0.23848        MiB: 1024.00000 Copy: 4293.815 MiB/s
AVG     Method: DUMB    Elapsed: 23891        MiB: 1024.00000 Copy: 4287.106 MiB/s
0       Method: MCBLOCK Elapsed: 0.15782        MiB: 1024.00000 Copy: 6489.724 MiB/s
1       Method: MCBLOCK Elapsed: 0.15824        MiB: 1024.00000 Copy: 6471.258 MiB/s
2       Method: MCBLOCK Elapsed: 0.15796        MiB: 1024.00000 Copy: 6482.415 MiB/s
3       Method: MCBLOCK Elapsed: 0.15841        MiB: 1024.00000 Copy: 6464.927 MiB/s
4       Method: MCBLOCK Elapsed: 0.15768        MiB: 1024.00000 Copy: 6492.176 MiB/s
5       Method: MCBLOCK Elapsed: 0.15813        MiB: 1024.00000 Copy: 6475.384 MiB/s
6       Method: MCBLOCK Elapsed: 0.15789        MiB: 1024.00000 Copy: 6483.271 MiB/s
7       Method: MCBLOCK Elapsed: 0.15835        MiB: 1024.00000 Copy: 6467.512 MiB/s
8       Method: MCBLOCK Elapsed: 0.15772        MiB: 1024.00000 Copy: 6491.283 MiB/s
9       Method: MCBLOCK Elapsed: 0.15828        MiB: 1024.00000 Copy: 6468.927 MiB/s
AVG     Method: MCBLOCK Elapsed: 0.15805        MiB: 1024.00000 Copy: 6478.738 MiB/s

宿主机内存测试结果:

# mbw 1024
... ...
AVG     Method: MEMCPY  Elapsed: 0.38742        MiB: 1024.00000 Copy: 2642.851 MiB/s
AVG     Method: DUMB    Elapsed: 0.21563        MiB: 1024.00000 Copy: 4748.926 MiB/s
AVG     Method: MCBLOCK Elapsed: 0.14125        MiB: 1024.00000 Copy: 7248.372 MiB/s

性能对比汇总:

测试方法虚拟机 (MiB/s)宿主机 (MiB/s)
MEMCPY2403.9212642.851
DUMB4287.1064748.926
MCBLOCK6478.7387248.372

内存性能损耗分析:

MEMCPY损耗 = (2642.851 - 2403.921) / 2642.851 × 100% = 9.04%
DUMB损耗   = (4748.926 - 4287.106) / 4748.926 × 100% = 9.73%
MCBLOCK损耗= (7248.372 - 6478.738) / 7248.372 × 100% = 10.62%

Ceph对象存储性能测试

COSBench测试工具

COSBench是Intel开源的分布式对象存储基准测试工具,支持多种云存储接口。

组件架构:

  • Driver节点:负责生成测试负载,向目标存储发起I/O操作并收集性能数据。访问地址:http://[driver-host]:18088/driver/index.html
  • Controller节点:协调各Driver节点执行测试,汇总运行状态和测试结果。访问地址:http://[controller-host]:19088/controller/index.html

配置文件结构:

配置文件位于conf/目录,使用XML格式。以Ceph S3接口为例,配置文件模板为conf/s3-config-sample.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<workload name="ceph-s3-benchmark" description="Ceph S3 performance test">
  <storage type="s3" config="accesskey=TESTKEY;secretkey=TESTSECRET;endpoint=http://ceph-cluster:7480" />
  <workflow>
    <workstage name="init_bucket">
      <work type="init" workers="2" config="cprefix=benchdata;containers=r(1,4)" />
    </workstage>
    <workstage name="prepare_objects">
      <work type="prepare" workers="4" config="cprefix=benchdata;containers=r(1,4);objects=r(1,20);sizes=c(128)KB" />
    </workstage>
    <workstage name="main_test">
      <work name="mixed_workload" workers="16" runtime="120">
        <operation type="read" ratio="70" config="cprefix=benchdata;containers=u(1,4);objects=u(1,20)" />
        <operation type="write" ratio="30" config="cprefix=benchdata;containers=u(1,4);objects=u(21,40);sizes=c(128)KB" />
      </work>
    </workstage>
    <workstage name="cleanup">
      <work type="cleanup" workers="2" config="cprefix=benchdata;containers=r(1,4);objects=r(1,40)" />
    </workstage>
    <workstage name="dispose">
      <work type="dispose" workers="2" config="cprefix=benchdata;containers=r(1,4)" />
    </workstage>
  </workflow>
</workload>

配置项说明:

  • storage.type:存储类型,Ceph使用s3
  • storage.config:认证信息(accesskey、secretkey)和集群endpoint
  • workstage:测试阶段
    • init:创建测试用的bucket
    • prepare:预创建测试对象
    • main:主测试阶段,支持read/write/delete/filewrite操作
    • cleanup:清理测试对象
    • dispose:清理测试bucket

执行方式: 登录Controller节点Web界面,上传配置文件即可启动测试。也可通过界面配置生成器创建自定义测试场景。

并发能力测试

对于最大并发数的测试,常用工具包括:

  • Apache JMeter:功能全面的负载测试工具,支持分布式部署和远程启动,配备图形化界面
  • http_load:轻量级HTTP基准测试工具
  • webbench:简单的Web压力测试工具

JMeter适合复杂场景的深度测试,支持多种协议,可组成集群进行大规模压力测试。具体使用方法可参考官方文档。

标签: iperf3

相关文章

Linux crontab 详解

1) crontab 是什么cron 是 Linux 的定时任务守护进程;crontab 是用来编辑/查看“按时间周期执行命令”的表(cron table)。常见两类:用户 crontab:每个用户一份(crontab -e 编辑)系统级 crontab / cron.d:可指定执行用户(/etc/crontab、/etc/cron.d/*)2) crontab 时间...

富文本里可以允许的 HTML 属性

一、所有标签默认允许的安全属性(极少)class        (可选)id           (通常建议禁用)title️ 注意:id 容易被滥用做锚点注入,很多系统直接禁用class 允许的话最好只允许固定前缀(如 editor-*)二、a 标签允许属性<a href="" t...

Mac 安装 Node.js 指南

方法一:通过官网安装包(最简单,适合初学者)如果你只是想快速安装并开始使用,这是最直接的方法。访问 Node.js 官网。页面会显示两个版本:LTS (Recommended For Most Users):长期支持版,最稳定。建议选这个。Current:最新特性版,包含最新功能但可能不够稳定。下载 .pkg 安装包并运行。按照安装向导点击“下一步”即可完成。方法二:使用 Homebrew 安装(...

Dom\HTML_NO_DEFAULT_NS 的副作用:自动加闭合标签

在使用Dom\HTMLDocument时,Dom\HTML_NO_DEFAULT_NS 将禁止在解析过程中设置元素的命名空间, 此设置是为了与DOMDocument向后兼容而存在的。当使用它时,已知的一个副作用就是:自动加闭合标签例如 </img> 为什么会这样?当你使用:Dom\HTML_NO_DEFAULT_NS文档会变成 无命名空间模式,此时内部更接近 XML...

Laravel 事件和监听器创建

在 Laravel 中,使用 Artisan 命令创建 Events(事件) 和 Listeners(监听器) 是非常高效的。你可以通过以下几种方式来实现:1. 手动创建单个 Event如果你只想创建一个事件类,可以使用 make:event 命令:Bashphp artisan make:event UserRegistered执行后,文件将生成在 app/Even...

自定义域名解析神器 dnsmasq

什么是 dnsmasq?dnsmasq 是一个轻量级、功能强大的网络服务工具,专为小型和中等规模网络设计。它是一个综合的网络基础设施解决方案[1]。dnsmasq 能做什么?功能说明应用场景DNS 转发与缓存将 DNS 查询转发到上游服务器(ISP、Google DNS 等),并在本地缓存结果加快 DNS 查询速度,减少外部 DNS 流量本地 DNS解析本地网络设备的主机名,无需编辑&n...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。