项目背景:
我们在公司中需要对自己服务器的硬盘的I/O有清晰的认识,对数据库的性能有清楚的认识。以便我们可以做出有利于公司业务发展的一些决策。
试验环境:
vmware workstation 11
centos6.5的系统下
服务器:ip:192.168.0.27
SecureCRT (ssh远程连接软件)
软件介绍:
NOTE: the project has been moved to http://github.com/akopytov/sysbench #github上软件连接地址
sysbench是一个模块化的、跨平台、多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况。
它具有的测试方式
1、cpu性能测试
2、磁盘I/O性能
3、调度程序性能
4、内存分配及传输速度
5、POSIX线程性能
6、数据库性能测试(OLTP基准测试)
目前sysbench主要支持 MySQL,pgsql,oracle 这3种数据库。不仅仅是前面的几种数据库,但是前面列出的三个是最常见的。
常用的命令:
Sysbench拥有6种磁盘I/O测试模式:
seqwr(顺序写)seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)等6种模式
--test=fileio 表示测试的是磁盘I/O
--file-total-size=5G 表示生成的测试文件做那个的大小是5G
--file-num=16 表示文件个数是16
--oltp_tables_count=10 表示会生成 10 个测试表
--oltp-table-size=100000 表示每个测试表填充数据量为 100000
--rand-init=on 表示每个测试表都是用随机数据来填充的
--num-threads=8 表示发起 8个并发连接
--oltp-read-only=off 表示不要进行只读测试,也就是会采用读写混合模式测试
--report-interval=10 表示每10秒输出一次测试进度报告
--rand-type=uniform 表示随机类型为固定模式,其他几个可选随机模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累托)
--max-time=120 表示最大执行时长为 120秒
--max-requests=0 表示总请求数为 0,因为上面已经定义了总执行时长,所以总请求数可以设定为 0;也可以只设定总请求数,不设定最大执行时长
--percentile=99 表示设定采样比例,默认是 95%,即丢弃1%的长请求,在剩余的99%里取最大值
--test=tests/db/oltp.lua 表示调用 tests/db/oltp.lua 脚本进行 oltp 模式测试
实验流程:
一、软件安装
直接用yum安装
[root@real_server01 ~]# yum install -y sysbench
二、磁盘I/O性能测试
分为三个阶段:
1、prepare阶段
[root@real_server01 ~]# sysbench --test=fileio --file-num=16 --file-total-size=5G prepare
sysbench 0.4.12: multi-threaded system evaluation benchmark
16 files, 327680Kb each, 5120Mb total
Creating files for the test...
2、run阶段(主菜!!!!)
[root@real_server01 ~]# sysbench --test=fileio --file-total-size=5G --file-test-mode=rndrd --max-time=180 --max-requests=100000000 --num-threads=16 --init-rng=on --file-num=16 --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=16384 run
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 16
Initializing random number generator from timer.
Extra file open flags: 16384
16 files, 320Mb each
5Gb total file size
Block size 16Kb
Number of random requests for random IO: 100000000
Read/Write ratio for combined random IO test: 1.50
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random read test
Threads started!
Time limit exceeded, exiting...
(last message repeated 15 times)
Done.
Operations performed: 24015 Read, 0 Write, 0 Other = 24015 Total
Read 375.23Mb Written 0b Total transferred 375.23Mb (2.0813Mb/sec)
133.20 Requests/sec executed
Test execution summary:
total time: 180.2860s
total number of events: 24015
total time taken by event execution: 2883.2663
per-request statistics:
min: 0.45ms
avg: 120.06ms
max: 946.44ms
approx. 95 percentile: 305.53ms
Threads fairness:
events (avg/stddev): 1500.9375/33.54
execution time (avg/stddev): 180.2041/0.04
随机读性能:2.0813Mb/sec 随机写性能:133.20 Requests/sec
3、clean阶段(把我们用来测试的文件都删掉!)
三、cpu性能测试:
CPU测试使用64位整数,测试计算素数直到某个最大值所需要的时间
[root@real_server01 ~]# sysbench --test=cpu --cpu-max-prime=30000 run
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 1
Doing CPU performance benchmark
Threads started!
Done.
Maximum prime number checked in CPU test: 30000
Test execution summary:
total time: 278.4829s
total number of events: 10000
total time taken by event execution: 278.4602 #看这里
per-request statistics:
min: 10.82ms
avg: 27.85ms
max: 199.93ms
approx. 95 percentile: 36.39ms
Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 278.4602/0.00
我们只需要关心测试的总时间(total time)即可。
四、测试线程调度器的性能
[root@real_server01 ~]# sysbench --test=threads --num-threads=128 run
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 128 #线程数128
Doing thread subsystem performance test
Thread yields per test: 1000 Locks used: 8
Threads started!
Done.
Test execution summary:
total time: 15.0155s
total number of events: 10000
total time taken by event execution: 1905.5345 #看着点!!!!!
per-request statistics:
min: 0.57ms
avg: 190.55ms
max: 2109.31ms
approx. 95 percentile: 446.71ms
Threads fairness:
events (avg/stddev): 78.1250/6.40
execution time (avg/stddev): 14.8870/0.09
五、测试互斥锁的性能,方式是模拟所有线程在同一时刻并发运行,并都短暂请求互斥锁。
[root@real_server01 ~]# sysbench --test=mutex --num-threads=16 --mutex-num=2048 \
> --mutex-locks=1000000 --mutex-loops=5000 run
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 16
Doing mutex performance test
Threads started!
Done.
Test execution summary:
total time: 1.8814s
total number of events: 16
total time taken by event execution: 29.2105
per-request statistics:
min: 1716.45ms
avg: 1825.66ms
max: 1874.11ms
approx. 95 percentile: 1873.28ms
Threads fairness:
events (avg/stddev): 1.0000/0.00
execution time (avg/stddev): 1.8257/0.05
六、内存测试
[root@real_server01 ~]# sysbench --test=memory --memory-block-size=16K --memory-total-size=2G --num-threads=16 run
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 16
Doing memory operations speed test
Memory block size: 16K
Memory transfer size: 2048M
Memory operations type: write
Memory scope type: global
Threads started!
Done.
Operations performed: 131072 (173441.21 ops/sec)
2048.00 MB transferred (2710.02 MB/sec) #吞吐量
Test execution summary:
total time: 0.7557s
total number of events: 131072
total time taken by event execution: 10.8236
per-request statistics:
min: 0.00ms
avg: 0.08ms
max: 439.96ms
approx. 95 percentile: 0.00ms
Threads fairness:
events (avg/stddev): 8192.0000/1137.43
execution time (avg/stddev): 0.6765/0.04
内存测试测试了内存的连续读写性能~~~~~~~~~
本篇博客我没有介绍对数据库的压力测试,我打算过一段时间单独把它拿住来讲一下,谢谢。
项目总结:
sysbench性能测试软件是一款优秀的开源软件,它对于我们的生产环境多个重要的方面都有强大的性能测试功能,对于我们系统管理员来说不可或缺。相信大家会在生活中爱不释手,对于它的使用能更加灵活,谢谢大家 希望大家都有所得!!!如果有什么问题,可以在下面问我。