Linux安装之后初步性能测试
sudo yum install sysbench iperf3 fio stress htop -y
CPU 性能测试
# 使用 sysbench 测试 CPU 计算能力
sysbench cpu --cpu-max-prime=20000 --threads=4 run
[root@localhost ~]# sysbench cpu --cpu-max-prime=20000 --threads=4 run
sysbench 1.0.17 (using system LuaJIT 2.0.4)
Running the test with following options:
Number of threads: 4
Initializing random number generator from current time
Prime numbers limit: 20000
Initializing worker threads...
Threads started!
CPU speed:
events per second: 1248.71
General statistics:
total time: 10.0020s
total number of events: 12492
Latency (ms):
min: 3.00
avg: 3.20
max: 21.28
95th percentile: 3.30
sum: 39998.02
Threads fairness:
events (avg/stddev): 3123.0000/11.47
execution time (avg/stddev): 9.9995/0.00
- •
events per second:越高表示 CPU 计算性能越好
内存性能测试
# 测试内存带宽与延迟
sysbench memory \
--memory-block-size=1K \
--memory-total-size=100G \
run
# 使用 stress 模拟高负载
stress --vm 4 --vm-bytes 2G --timeout 300s
[root@localhost ~]# sysbench memory \
> --memory-block-size=1K \
> --memory-total-size=100G \
> run
sysbench 1.0.17 (using system LuaJIT 2.0.4)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Running memory speed test with the following options:
block size: 1KiB
total size: 102400MiB
operation: write
scope: global
Initializing worker threads...
Threads started!
Total operations: 38482740 (3847419.36 per second)
37580.80 MiB transferred (3757.25 MiB/sec)
General statistics:
total time: 10.0001s
total number of events: 38482740
Latency (ms):
min: 0.00
avg: 0.00
max: 0.20
95th percentile: 0.00
sum: 4191.24
Threads fairness:
events (avg/stddev): 38482740.0000/0.00
execution time (avg/stddev): 4.1912/0.00
[root@localhost ~]# stress --vm 4 --vm-bytes 2G --timeout 300s
stress: info: [14253] dispatching hogs: 0 cpu, 0 io, 4 vm, 0 hdd
stress: info: [14253] successful run completed in 301s
- •
MiB transferred和 Operations/s:越高表示内存性能越好 - • 测试期间用
vmstat 1监控是否发生频繁 swap(si/so 列)。
磁盘 I/O 性能测试
# 使用 fio 测试随机读(4K 块大小)
fio \
--filename=/testfile \
--size=1G \
--ioengine=libaio \
--direct=1 \
--rw=randread \
--bs=4k \
--numjobs=4 \
--runtime=60 \
--group_reporting \
--name=randread-test
[root@localhost ~]# fio \
> --filename=/testfile \
> --size=1G \
> --ioengine=libaio \
> --direct=1 \
> --rw=randread \
> --bs=4k \
> --numjobs=4 \
> --runtime=60 \
> --group_reporting \
> --name=randread-test # 添加必填的name参数
randread-test: (g=0): rw=randread, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=libaio, iodepth=1
...
fio-3.7
Starting 4 processes
randread-test: Laying out IO file (1 file / 1024MiB)
Jobs: 4 (f=4): [r(4)][100.0%][r=153MiB/s,w=0KiB/s][r=39.3k,w=0 IOPS][eta 00m:00s]
randread-test: (groupid=0, jobs=4): err= 0: pid=9221: Sat Aug 9 21:32:57 2025
read: IOPS=39.1k, BW=153MiB/s (160MB/s)(4096MiB/26797msec)
slat (usec): min=6, max=170, avg=12.27, stdev= 3.93
clat (usec): min=2, max=9579, avg=85.56, stdev=48.43
lat (usec): min=62, max=9596, avg=98.84, stdev=48.67
clat percentiles (usec):
| 1.00th=[ 60], 5.00th=[ 64], 10.00th=[ 67], 20.00th=[ 75],
| 30.00th=[ 83], 40.00th=[ 85], 50.00th=[ 86], 60.00th=[ 88],
| 70.00th=[ 90], 80.00th=[ 92], 90.00th=[ 97], 95.00th=[ 101],
| 99.00th=[ 123], 99.50th=[ 135], 99.90th=[ 314], 99.95th=[ 742],
| 99.99th=[ 2040]
bw ( KiB/s): min=35752, max=40360, per=25.01%, avg=39140.49, stdev=850.43, samples=212
iops : min= 8938, max=10090, avg=9785.11, stdev=212.59, samples=212
lat (usec) : 4=0.01%, 20=0.01%, 50=0.08%, 100=94.17%, 250=5.63%
lat (usec) : 500=0.06%, 750=0.01%, 1000=0.01%
lat (msec) : 2=0.03%, 4=0.01%, 10=0.01%
cpu : usr=5.83%, sys=19.13%, ctx=1048734, majf=0, minf=143
IO depths : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.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.0%, >=64=0.0%
issued rwts: total=1048576,0,0,0 short=0,0,0,0 dropped=0,0,0,0
latency : target=0, window=0, percentile=100.00%, depth=1
Run status group 0 (all jobs):
READ: bw=153MiB/s (160MB/s), 153MiB/s-153MiB/s (160MB/s-160MB/s), io=4096MiB (4295MB), run=26797-26797msec
Disk stats (read/write):
dm-0: ios=1040413/39, merge=0/0, ticks=86243/236, in_queue=86563, util=99.64%, aggrios=1048580/51, aggrmerge=0/3, aggrticks=87550/235, aggrin_queue=87528, aggrutil=99.54%
sda: ios=1048580/51, merge=0/3, ticks=87550/235, in_queue=87528, util=99.54%
- •
--rw=read/randwrite:测试顺序读/随机写 - •
--numjobs:模拟并发 I/O 任务数。结果关注: - •
IOPS和 BW (MB/s):越高表示磁盘性能越好
网络性能测试
# 服务端启动(目标机器)
iperf3 -s
# 客户端测试(另一台机器)
[root@mypg1 ~]# iperf3 -c 192.168.0.37 -t 5 -P 4
Connecting to host 192.168.0.37, port 5201
[ 4] local 192.168.185.71 port 43184 connected to 192.168.0.37 port 5201
[ 6] local 192.168.185.71 port 43186 connected to 192.168.0.37 port 5201
[ 8] local 192.168.185.71 port 43188 connected to 192.168.0.37 port 5201
[ 10] local 192.168.185.71 port 43190 connected to 192.168.0.37 port 5201
[ ID] Interval Transfer Bandwidth Retr Cwnd
[ 4] 0.00-1.00 sec 3.60 MBytes 30.2 Mbits/sec 0 67.0 KBytes
[ 6] 0.00-1.00 sec 3.08 MBytes 25.8 Mbits/sec 0 65.6 KBytes
[ 8] 0.00-1.00 sec 3.26 MBytes 27.4 Mbits/sec 0 65.6 KBytes
[ 10] 0.00-1.00 sec 3.29 MBytes 27.6 Mbits/sec 0 65.6 KBytes
[SUM] 0.00-1.00 sec 13.2 MBytes 111 Mbits/sec 0
- - - - - - - - - - - - - - - - - - - - - - - - -
[ 4] 1.00-2.00 sec 3.22 MBytes 27.0 Mbits/sec 0 67.0 KBytes
[ 6] 1.00-2.00 sec 1.84 MBytes 15.4 Mbits/sec 0 65.6 KBytes
[ 8] 1.00-2.00 sec 3.22 MBytes 27.0 Mbits/sec 0 65.6 KBytes
[ 10] 1.00-2.00 sec 2.76 MBytes 23.1 Mbits/sec 0 65.6 KBytes
[SUM] 1.00-2.00 sec 11.0 MBytes 92.5 Mbits/sec 0
- - - - - - - - - - - - - - - - - - - - - - - - -
[ 4] 2.00-3.00 sec 3.06 MBytes 25.7 Mbits/sec 0 67.0 KBytes
[ 6] 2.00-3.00 sec 2.30 MBytes 19.3 Mbits/sec 0 65.6 KBytes
[ 8] 2.00-3.00 sec 3.22 MBytes 27.0 Mbits/sec 0 65.6 KBytes
[ 10] 2.00-3.00 sec 2.91 MBytes 24.4 Mbits/sec 0 65.6 KBytes
[SUM] 2.00-3.00 sec 11.5 MBytes 96.4 Mbits/sec 0
- - - - - - - - - - - - - - - - - - - - - - - - -
[ 4] 3.00-4.00 sec 2.91 MBytes 24.4 Mbits/sec 0 67.0 KBytes
[ 6] 3.00-4.00 sec 2.30 MBytes 19.3 Mbits/sec 0 65.6 KBytes
[ 8] 3.00-4.00 sec 3.06 MBytes 25.7 Mbits/sec 0 65.6 KBytes
[ 10] 3.00-4.00 sec 2.76 MBytes 23.1 Mbits/sec 0 65.6 KBytes
[SUM] 3.00-4.00 sec 11.0 MBytes 92.5 Mbits/sec 0
- - - - - - - - - - - - - - - - - - - - - - - - -
[ 4] 4.00-5.00 sec 2.91 MBytes 24.4 Mbits/sec 0 67.0 KBytes
[ 6] 4.00-5.00 sec 2.45 MBytes 20.6 Mbits/sec 0 65.6 KBytes
[ 8] 4.00-5.00 sec 3.06 MBytes 25.7 Mbits/sec 0 65.6 KBytes
[ 10] 4.00-5.00 sec 2.76 MBytes 23.1 Mbits/sec 0 65.6 KBytes
[SUM] 4.00-5.00 sec 11.2 MBytes 93.8 Mbits/sec 0
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth Retr
[ 4] 0.00-5.00 sec 15.7 MBytes 26.3 Mbits/sec 0 sender
[ 4] 0.00-5.00 sec 15.0 MBytes 25.2 Mbits/sec receiver
[ 6] 0.00-5.00 sec 12.0 MBytes 20.1 Mbits/sec 0 sender
[ 6] 0.00-5.00 sec 11.3 MBytes 18.9 Mbits/sec receiver
[ 8] 0.00-5.00 sec 15.8 MBytes 26.5 Mbits/sec 0 sender
[ 8] 0.00-5.00 sec 15.1 MBytes 25.3 Mbits/sec receiver
[ 10] 0.00-5.00 sec 14.5 MBytes 24.3 Mbits/sec 0 sender
[ 10] 0.00-5.00 sec 13.8 MBytes 23.2 Mbits/sec receiver
[SUM] 0.00-5.00 sec 58.0 MBytes 97.2 Mbits/sec 0 sender
[SUM] 0.00-5.00 sec 55.2 MBytes 92.6 Mbits/sec receiver
iperf Done.
Sender/Receiver Bandwidth:接近千兆(1Gbps)为正常
HTTP 服务测试(如部署 Web 服务)
ab -c 100 -n 5000 http://<本地IP>/ # 测试 Apache/Nginx 并发处理能力