Ubuntu 性能测试实操指南
一 测试前准备与通用原则
二 快速上手 CPU 与内存测试
sudo apt-get install sysbench -y;执行:sysbench cpu --cpu-max-prime=20000 run(数值越大越耗时,适合对比不同机器/内核)。gcc -O -funroll-loops -fomit-frame-pointer pi_fftcs.c fftsg_h.c -lm -o pi_css5;计算67108864位耗时:./pi_css5 $((1<<26))(时间越短单线程越强)。sudo apt-get install stress-ng rt-tests -y;长时实时性:sudo cyclictest -t $(nproc) -p 80 -i 1000 -D 2h(线程数=CPU线程数,持续2小时)。sudo apt-get install mbw -y;示例:mbw -q -n 10 245760(测试约240GB,输出 MEMCPY/DUMB/MCBLOCK 的带宽,关注 AVG)。memtester 240G 10(先 free -h 确认可用内存,避免 OOM;用于稳定性验证,非纯带宽基准)。三 磁盘 I O 与文件系统测试
sudo hdparm -Tt /dev/sdX(区分缓存读-T与设备读-t)。time dd if=/dev/zero of=testfile bs=1M count=1024 oflag=direct;读:time dd if=testfile of=/dev/null bs=1M count=1024 iflag=direct(oflag/iflag=direct 尽量绕过页缓存)。sudo ioping -c 100 -b 4K /path 或 -b 1M 观察不同块大小的延迟分布。fio --name=seqread --ioengine=sync --rw=read --bs=1M --size=1G --numjobs=1 --direct=1 --group_reportingfio --name=seqwrite --ioengine=sync --rw=write --bs=1M --size=1G --numjobs=1 --direct=1 --group_reportingfio --name=randread --ioengine=libaio --rw=randread --bs=4k --size=1G --numjobs=1 --direct=1 --iodepth=64 --runtime=60 --group_reportingfio --name=randwrite --ioengine=libaio --rw=randwrite --bs=4k --size=1G --numjobs=1 --direct=1 --iodepth=64 --runtime=60 --group_reportingdirect=1(绕过缓存)、ioengine=libaio(异步 I/O)、iodepth(队列深度,SSD/高端 NVMe 可适当增大)、bs(块大小)、size(数据量,建议≥内存2倍以减少缓存影响)、runtime(持续时间)。四 图形 GPU 与综合测试
sudo apt-get install mesa-utils -y;运行 glxgears(仅作入门参考,不代表游戏/专业负载)。sudo apt-get install phoronix-test-suite -y;可一键执行处理器/磁盘等项目并在线对比,适合做回归与横向评测。五 网络测试与结果记录
iperf3 -s,客户端测试:iperf3 -c <server_ip> -t 30 -P 4(并发4流,持续30秒);如需 UDP:iperf3 -c <server_ip> -u -b 1G -t 30。