1 一款数据库压测工具
2 基于sysbench构造测试表和测试数据
sysbench
—db-driver=mysql 设置驱动为mysql。
—time=200 设置时间为200s运行
—threads=10 设置运行时线程数10个
—report-interval=1 设置打印日志的时间间隔为1s
—mysql-host=127.0.0.1 设置mysql的ip为127.0.0.1
—mysql-port=3306 设置端口号为3306
—mysql-user=test 设置用户名
—mysql-password=test 设置密码
—mysql-db=test_db 设置数据库名称
—tables=20 设置20张表
—tables-size=1000000 设置每张表的数据量为1000000
oltp_read_write 这个是标志测的是什么
—db-ps-mode=dispable 禁止ps模式
prepare 设表示参照这个以上的设置去生成我们需要的数据。
其中参数 prepare这里 如果替换成run 则表示开始压测。
如果是cleanup,就表示清理数据。
3 对数据库进行全方位测试
测试数据库的综合读写TPS,使用oltp_read_write模式。
sysbench —db-driver=mysql —time=300 —threads=10 —report-interval=1 —mysql-host=172.16.49.150 —mysql-port=3306 —mysql-user=amc_w —mysql-password=sdfcerts4amc —mysql-db=test —tables=20 —table_size=1000000 oltp_read_write —db-ps-mode=disable run
测试数据库的只读性能,使用oltp_read_only模式。
sysbench —db-driver=mysql —time=300 —threads=10 —report-interval=1 —mysql-host=172.16.49.150 —mysql-port=3306 —mysql-user=amc_w —mysql-password=sdfcerts4amc —mysql-db=test —tables=20 —table_size=1000000 oltp_read_only —db-ps-mode=disable run
测试数据库的删除性能,使用oltp_delete模式
sysbench —db-driver=mysql —time=300 —threads=10 —report-interval=1 —mysql-host=172.16.49.150 —mysql-port=3306 —mysql-user=amc_w —mysql-password=sdfcerts4amc —mysql-db=test —tables=20 —table_size=1000000 oltp_delete —db-ps-mode=disable run
测试数据库的更新索引字段性能,使用oltp_update_index模式
sysbench —db-driver=mysql —time=300 —threads=10 —report-interval=1 —mysql-host=172.16.49.150 —mysql-port=3306 —mysql-user=amc_w —mysql-password=sdfcerts4amc —mysql-db=test —tables=20 —table_size=1000000 oltp_update_index —db-ps-mode=disable run
测试数据库的更新非索引字段的性能,使用oltp_update_non_index模式。
sysbench —db-driver=mysql —time=300 —threads=10 —report-interval=1 —mysql-host=172.16.49.150 —mysql-port=3306 —mysql-user=amc_w —mysql-password=sdfcerts4amc —mysql-db=test —tables=20 —table_size=1000000 oltp_update_non_index —db-ps-mode=disable run
测试数据库的插入性能,使用oltp_insert模式
sysbench —db-driver=mysql —time=300 —threads=10 —report-interval=1 —mysql-host=172.16.49.150 —mysql-port=3306 —mysql-user=amc_w —mysql-password=sdfcerts4amc —mysql-db=test —tables=20 —table_size=1000000 oltp_insert —db-ps-mode=disable run
测试数据库的写入性能,使用oltp_write_only模式
sysbench —db-driver=mysql —time=300 —threads=10 —report-interval=1 —mysql-host=172.16.49.150 —mysql-port=3306 —mysql-user=amc_w —mysql-password=sdfcerts4amc —mysql-db=test —tables=20 —table_size=1000000 oltp_write_only —db-ps-mode=disable run
4 压测结果分析
按照我们上面的配置,一般每秒都会输出一条数据
[ 155s ] thds: 10 tps: 44.88 qps: 935.43 (r/w/o: 668.17/177.51/89.75) lat (ms,95%): 235.74 err/s: 0.00 reconn/s: 0.00
解释一下
thds:10 表示有是个线程在压测。
tps:44.88 表示每秒执行了44.88个事务。
qps:935.43 表示每秒执行了935.43个请求。
(r/w/o: 668.17/177.51/89.75) 表示在每秒935.43个请求中,668.17为读请求,117.51为写请求,89.75为其他请求。
lat(ms,95%):235.74 表示95%的请求都在235.43ms以下。
err/s:0.00 每秒有0个请求失败。
reconn/s:每秒有0次网络重连。
压测完后还有总报告
SQL statistics:
queries performed:
read:1480084 //这个是说300s的压测时期间执行了148w多次的读请求。
write:298457 //表示这么久内执行了这么多次写请求
other:10000 //表示这么久内执行了这么多次其他请求
total:1000000 //表示一共执行了多少请求
//这里是说一共执行了10w多事务,每秒执行350多个事务。
transactions:100020(350.6 per sec.)
//这里是说一共执行了210多万次请求,每秒执行7000+次请求
queries:2109920(7013.23 per sec.)
ignored errors:0(0.00 per sec.)
reconnects:0(0.00 per sec.)
//下面就是说,一共执行了300s压测,执行了10w以上的事务
General staticstics:
total time:300.25s
total number of events:105103
Latency(ms)
min:4.32 //请求中延迟最小的是4.32ms
avg:13.42 //所有请求平均延迟13.42ms
max:45.56 //延迟最大请求的是45.56ms
95th percentile:21.33 //95%的请求延迟都在21.33ms以内
