下载sysbench
[root@localhost /]# yum install bzr [root@localhost /]# bzr branch lp:~sysbench-developers/sysbench/0.5 sysbench [root@localhost /]# cd sysbench/
yum安装automake,libtool
[root@bogon sysbench]# ./autogen.sh [root@bogon sysbench]# ./configure --prefix=/usr/local/sysbench --with-mysql-includes=/usr/include/mysql/ \ > --with-mysql-libs=/usr/lib64/mysql/ [root@bogon sysbench]# make && make install
将bin目录加入到环境变量,需重启系统生效;(centos 7.1)
[root@bogon sysbench]#vim /etc/profile
补充:查看CPU核数的方法
1)查看物理cpu个数
grep "physical id" /proc/cpuinfo | sort -u | wc -l
2)查看核心数量
grep "core id" /proc/cpuinfo | sort -u | wc -l
3)查看线程数量
grep "processor" /proc/cpuinfo | sort -u | wc -l
在sysbench的测试中,--num-threads取值为"线程数量"即可,再大的值没有什么意义,对测试结果也没有什么影响。
正式测试及分析
1)CPU---根据官网的介绍可知:CPU测试使用64位整数,测试计算素数直到某个最大值所需要的时间。下面的测试配置为双核双线程,因此指定了两个线程;该测试只需关心花费的总时间即可;
[pikaqiu@localhost ~]$ sysbench --test=cpu --cpu-max-prime=20000 --num-threads=2 run sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 2 Random number generator seed is 0 and will be ignored Primer numbers limit: 20000 Threads started! General statistics: total time: 13.2732s //计算花费的总时间 total number of events: 10000 total time taken by event execution: 26.5317s response time: min: 2.59ms avg: 2.65ms max: 8.70ms approx. 95 percentile: 2.66ms Threads fairness: events (avg/stddev): 5000.0000/4.00 execution time (avg/stddev): 13.2658/0.00
2)内存连续读写性能----指定一次读写的块大小为16K,测试总大小为2G,线程数为两个,线程数1和2结果差不多;该测试只需关心吞吐量即可;
[pikaqiu@localhost ~]$ sysbench --test=memory --memory-block-size=16K --memory-total-size=2G --num-threads=2 run sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 2 Random number generator seed is 0 and will be ignored Threads started! Operations performed: 131072 (192904.65 ops/sec) 2048.00 MB transferred (3014.14 MB/sec)//吞吐量为3014.14MB/sec General statistics: total time: 0.6795s total number of events: 131072 total time taken by event execution: 1.0034s response time: min: 0.00ms avg: 0.01ms max: 0.18ms approx. 95 percentile: 0.02ms Threads fairness: events (avg/stddev): 65536.0000/12176.00 execution time (avg/stddev): 0.5017/0.01
3)磁盘测试------创建10G的测试内容;附:读取规则参数:(1)seqwr 顺序写入;(2)seqrewr 顺序重写;(3)seqrd 顺序读取;(4)rndrd 随机读取;(5)rndwr 随机写入;(6)rndrw 混合随机读/写;
[pikaqiu@localhost ~]$ sysbench --test=fileio --file-total-size=10G prepare sysbench 0.5: multi-threaded system evaluation benchmark 128 files, 81920Kb each, 10240Mb total Creating files for the test... Extra file open flags: 0 Creating file test_file.0 Creating file test_file.1 Creating file test_file.2 Creating file test_file.3 ...... Creating file test_file.125 Creating file test_file.126 Creating file test_file.127 10737418240 bytes written in 227.80 seconds (44.95 MB/sec).
4)磁盘测试-----顺序读取,读取规则为顺序读,大小为10G,关心每次读取的块大小和读取速度;
[pikaqiu@localhost ~]$ sysbench --test=fileio --file-total-size=10G --file-test-mode=seqrd run sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 1 Random number generator seed is 0 and will be ignored Extra file open flags: 0 128 files, 80Mb each 10Gb total file size Block size 16Kb //块大小为16K Periodic FSYNC enabled, calling fsync() each 100 requests. Calling fsync() at the end of test, Enabled. Using synchronous I/O mode Doing sequential read test Threads started! Operations performed: 10000 reads, 0 writes, 0 Other = 10000 Total Read 156.25Mb Written 0b Total transferred 156.25Mb (49.137Mb/sec)//读取速度为49.137MB/sec 3144.78 Requests/sec executed General statistics: total time: 3.1799s total number of events: 10000 total time taken by event execution: 3.1465s response time: min: 0.01ms avg: 0.31ms max: 70.86ms approx. 95 percentile: 1.99ms Threads fairness: events (avg/stddev): 10000.0000/0.00 execution time (avg/stddev): 3.1465/0.00
5)磁盘测试-----随机读取,读取规则为顺序读,大小为10G,关心每次读取的块大小和读取速度;
[pikaqiu@localhost ~]$ sysbench --test=fileio --file-total-size=10G --file-test-mode=rndrd run sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 1 Random number generator seed is 0 and will be ignored Extra file open flags: 0 128 files, 80Mb each 10Gb total file size Block size 16Kb //一次读取的块大小为16K Number of IO requests: 10000 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 read test Threads started! Operations performed: 10000 reads, 0 writes, 0 Other = 10000 Total Read 156.25Mb Written 0b Total transferred 156.25Mb (1.5145Mb/sec)//读取速度为1.5145MB/ 96.93 Requests/sec executed General statistics: total time: 103.1714s total number of events: 10000 total time taken by event execution: 103.0658s response time: min: 0.01ms avg: 10.31ms max: 328.99ms approx. 95 percentile: 21.91ms Threads fairness: events (avg/stddev): 10000.0000/0.00 execution time (avg/stddev): 103.0658/0.00
6)清除测试文件
[pikaqiu@localhost ~]$ sysbench --test=fileio --fil-total-size=10G cleanup sysbench 0.5: multi-threaded system evaluation benchmark Removing test files...
速度对比,块大小为16K,内存吞吐量为3014.14MB/sec,硬盘顺序读为49.137MB/sec,硬盘随机读为1.5145MB/sec;
结论:内存的顺序读取速度比硬盘快50倍左右,硬盘的顺序读比随机读快32倍左右;