mysql sysbench基准测试
git项目地址:
https://github.com/akopytov/sysbench
利用sysbench很容易对mysql做性能基准测试(当然这个工具很强大,除了测试主流数据库性能,还能测试其它方面,详情自己看官网项目文档)
Linux上的用法:
一、安装
yum install -y sysbench
二、先在mysql上创建一个专门的测试数据库,比如sbtest
FATAL: unable to connect to MySQL server, aborting...
FATAL: error 1049: Unknown database 'sbtest' |
FATAL: failed to connect to database server! |
... |
错误提示说:mysql连接不上, sbtest库没找到。 需要创建一个sbtest库!
sysbench /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua --db-driver=mysql --mysql-host=192.168.60.165 --mysql-port=18604 --mysql-user=root --mysql-password=cc.123 --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 prepare
--test=tests/db/oltp.lua 表示调用 tests/db/oltp.lua 脚本进行 oltp 模式测试
--oltp_tables_count=10 表示会生成 10 个测试表
--oltp-table-size=100000 表示每个测试表填充数据量为 100000
--rand-init=on 表示每个测试表都是用随机数据来填充的
真实测试场景中,数据表建议不低于10个,单表数据量不低于500万行,当然了,要视服务器硬件配置而定。如果是配备了SSD或者PCIE SSD这种高IOPS设备的话,则建议单表数据量最少不低于1亿行。
真实测试场景中,建议持续压测时长不小于30分钟,否则测试数据可能不具参考意义。
三、利用sysbench先生成测试数据
sysbench /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua --db-driver=mysql --mysql-host=192.168.60.165 --mysql-port=18604 --mysql-user=root --mysql-password=cc.123 --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 run >> /home/mysysbench.log
sysbench : multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 8 Report intermediate results every 10 second(s) Random number generator seed is 0 and will be ignored Threads started! -- 每10秒钟报告一次测试结果,tps、每秒读、每秒写、99%以上的响应时长统计 [ 10s] threads: 8, tps: 1111.51, reads/s: 15568.42, writes/s: 4446.13, response time: 9.95ms (99%) [ 20s] threads: 8, tps: 1121.90, reads/s: 15709.62, writes/s: 4487.80, response time: 9.78ms (99%) [ 30s] threads: 8, tps: 1120.00, reads/s: 15679.10, writes/s: 4480.20, response time: 9.84ms (99%) [ 40s] threads: 8, tps: 1114.20, reads/s: 15599.39, writes/s: 4456.30, response time: 9.90ms (99%) [ 50s] threads: 8, tps: 1114.00, reads/s: 15593.60, writes/s: 4456.70, response time: 9.84ms (99%) [ 60s] threads: 8, tps: 1119.30, reads/s: 15671.60, writes/s: 4476.50, response time: 9.99ms (99%) OLTP test statistics: queries performed: read: 938224 -- 读总数 write: 268064 -- 写总数 other: 134032 -- 其他操作总数(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等) total: 1340320 -- 全部总数 transactions: 67016 (1116.83 per sec.) -- 总事务数(每秒事务数) deadlocks: 0 (0.00 per sec.) -- 发生死锁总数 read/write requests: 1206288 (20103.01 per sec.) -- 读写总数(每秒读写次数) other operations: 134032 (2233.67 per sec.) -- 其他操作总数(每秒其他操作次数) General statistics: -- 一些统计结果 total time: 60.0053s -- 总耗时 total number of events: 67016 -- 共发生多少事务数 total time taken by event execution: 479.8171s -- 所有事务耗时相加(不考虑并行因素) response time: -- 响应时长统计 min: 4.27ms -- 最小耗时 avg: 7.16ms -- 平均耗时 max: 13.80ms -- 最长耗时 approx. 99 percentile: 9.88ms -- 超过99%平均耗时 Threads fairness: events (avg/stddev): 8377.0000/44.33 execution time (avg/stddev): 59.9771/0.00