如果我们有不同的机器或者虚机,有时候需要比较一下机器性能。比如cpu和磁盘io。该如何做呢?

很简单,用sysbench

安装:

yum install sysbench  

比较cpu的话,首先查看有几个cpu

cat /proc/cpuinfo|grep processor|wc -l  
40  

有多少cpu,就发多少线程测试

sysbench --test=cpu --cpu-max-prime=20000 --num-threads=40 run  

测试结果:

sysbench --test=cpu --cpu-max-prime=20000 --num-threads=40 run  
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Running the test with following options:  
Number of threads: 40

Doing CPU performance benchmark

Threads started!  
Done.

Maximum prime number checked in CPU test: 20000


Test execution summary:  
    total time:                          0.9058s
    total number of events:              10000
    total time taken by event execution: 36.1068
    per-request statistics:
         min:                                  3.05ms
         avg:                                  3.61ms
         max:                                 22.50ms
         approx.  95 percentile:               3.47ms

Threads fairness:  
    events (avg/stddev):           250.0000/29.17
    execution time (avg/stddev):   0.9027/0.00

结果中total time是我们要的数据,0.9058s。

再测测虚机,cpu是虚拟4个,total time是7.1010s 测试结果明显差了不少,注意,以上如果不指定num-threads的话,就是测试单个线程,那么如果是同一台机器上的虚机和实机,测出的结果基本是一样的,那毫无意义,加上num-threads才是正确的。

测试硬盘比较麻烦,分3步走:

  • 第一步:准备数据,注意文件大小要超出内存限制,以便排除缓存的干扰
sysbench --test=fileio --file-total-size=20G prepare  
  • 第二步:测试速度
sysbench --test=fileio --file-total-size=20G --file-test-mode=rndrw --init-rng=on --max-time=300 --max-requests=0 run  

结果如下:

sysbench 0.4.12:  multi-threaded system evaluation benchmark

Running the test with following options:  
Number of threads: 1  
Initializing random number generator from timer.


Extra file open flags: 0  
128 files, 160Mb each  
20Gb total file size  
Block size 16Kb  
Number of random requests for random IO: 0  
Read/Write ratio for combined random IO test: 1.50  
Periodic FSYNC enabled, calling fsync() each 100 requests.  
Calling fsync() at the end of test, Enabled.  
Using synchronous I/O mode  
Doing random r/w test  
Threads started!  
Time limit exceeded, exiting...  
Done.

Operations performed:  38633 Read, 25755 Write, 82304 Other = 146692 Total  
Read 603.64Mb  Written 402.42Mb  Total transferred 1006.1Mb  (3.3535Mb/sec)  
  214.62 Requests/sec executed

Test execution summary:  
    total time:                          300.0075s
    total number of events:              64388
    total time taken by event execution: 159.2430
    per-request statistics:
         min:                                  0.00ms
         avg:                                  2.47ms
         max:                                325.54ms
         approx.  95 percentile:               8.81ms

Threads fairness:  
    events (avg/stddev):           64388.0000/0.00
    execution time (avg/stddev):   159.2430/0.00

结果中(3.3535Mb/sec)是我们要的数据,3.3535Mb/sec,可以用来跟其他机器比较。

  1. 清理测试数据
sysbench --test=fileio cleanup  

ok,得到数据然后用图表画出来就比较直观了。

comments powered by Disqus