运行测试
接下来就是真正意义上的测试了,这里你需要先使用MySQL标准客户端连接 TiDB
> mysql -h 120.92.150.39 -P 4000 -u root -D test
> create database sbtest1;
然后你就需要用到刚刚获取的beanch的代码了:
> cd ~/tidb-bench-master/sysbench
修改conf.sh:
> cat conf.sh
. ./conf.sh
host=127.0.0.1
port=4000
user=root
password=
tcount=16
tsize=1000000
threads=256
dbname=sbtest1
interval=10
maxtime=600
requests=2000000000
driver=mysql
详解:
- —test=tests/db/oltp.lua 表示调用 tests/db/oltp.lua 脚本进行 oltp 模式测试.
- —oltp_tables_count=16 表示会生成16张测试表 .
- —oltp-table-size=500000 表示每张测试表填充数据量为500000 —rand-init=on 表示每张测试表都是用随机数据来填充的.
如果在本机,也可以使用 –mysql-socket 指定 socket 文件来连接。加载测试数据时长视数据量而定,若过程比较久需要稍加耐心等待。 真实测试场景中,数据表建议不低于10个,单表数据量不低于500万行,当然了,要视服务器硬件配置而定。如果是配备了SSD或者PCIE SSD这种高IOPS设备的话,则建议单表数据量最少不低于1亿行。
测试运行:
> ./prepare.sh
执行完成后,生成16张测试表,每张表500000条数据。
开始测试 OLTP,这里解释写关于里面的参数:
- —num-threads=256 表示发起 256 个并发连接.
- —oltp-read-only=off 表示不要进行只读测试也就是会采用读写混合模式测试.
- —report-interval=10 表示每10秒输出一次测试进度报告.
- —rand-type=uniform 表示随机类型为固定模式,其他几个可选随机模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累托).
- —max-time=600 表示最大执行时长为 600 秒.
- —max-requests=0 表示总请求数为 0,因为上面已经定义了总执行时长,所以总请求数可以设定为 0;也可以只设定总请求数,不设定最大执行时长.
- —percentile=95 表示设定采样比例,默认是 95%,即丢弃5%的长请求,在剩余的95%里取最大值.
模拟 对256个表并发OLTP测试,每个表500000行记录,持续压测时间为10分钟。 真实测试场景中,建议持续压测时长不小于30分钟,否则测试数据可能不具参考意义。
> ./oltp.sh
+ sysbench --test=./lua-tests/db/oltp.lua --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=4000 --mysql-user=root --mysql-password= --mysql-db=sbtest1 --oltp-tables-count=16 --oltp-table-size=1000000 --num-threads=256 --max-requests=2000000000 --oltp-read-only=off --report-interval=10 --rand-type=uniform --max-time=600 --percentile=95 run
oltp 测试结果如下:
sysbench 1.0.9 (using system LuaJIT 2.0.4)
Running the test with following options:
Number of threads: 256
Report intermediate results every 10 second(s)
Initializing random number generator from current time
-- 每10秒钟报告一次测试结果,tps、每秒读、每秒写、99%以上的响应时长统计
[ 580s ] thds: 256 tps: 721.70 qps: 14451.55 (r/w/o: 10116.46/2890.59/1444.49) lat (ms,95%): 404.61 err/s: 0.00 reconn/s: 0.00
[ 590s ] thds: 256 tps: 717.67 qps: 14343.25 (r/w/o: 10038.02/2869.89/1435.35) lat (ms,95%): 427.07 err/s: 0.00 reconn/s: 0.00
[ 600s ] thds: 256 tps: 731.61 qps: 14657.79 (r/w/o: 10265.53/2931.24/1461.02) lat (ms,95%): 404.61 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 5846120 -- 读总数
write: 1670320 -- 写总数
other: 835160 -- 其他操作总数(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等)
total: 8351600 -- 全部总数
transactions: 417580 (693.25 per sec.) -- 总事务数(每秒事务数)
queries: 8351600 (13864.98 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 602.3476s -- 总耗时
total number of events: 417580 -- 共发生多少事务数
Latency (ms):
min: 25.62 -- 最小耗时
avg: 367.90 -- 平均耗时
max: 5886.23 -- 最长耗时
95th percentile: 442.73
sum: 153666263.39
Threads fairness:
events (avg/stddev): 749.0078/2.01
execution time (avg/stddev): 600.2588/0.17
测试 select:
> ./select.sh
+ sysbench --test=./lua-tests/db/select.lua --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=4000 --mysql-user=root --mysql-password= --mysql-db=sbtest1 --oltp-tables-count=16 --oltp-table-size=1000000 --num-threads=256 --report-interval=10 --max-requests=2000000000 --percentile=95 --max-time=600 run
select 测试结果如下:
[ 550s ] thds: 256 tps: 9072.09 qps: 9072.09 (r/w/o: 9072.09/0.00/0.00) lat (ms,95%): 51.94 err/s: 0.00 reconn/s: 0.00
[ 560s ] thds: 256 tps: 7348.60 qps: 7348.60 (r/w/o: 7348.60/0.00/0.00) lat (ms,95%): 69.29 err/s: 0.00 reconn/s: 0.00
[ 570s ] thds: 256 tps: 7644.35 qps: 7644.35 (r/w/o: 7644.35/0.00/0.00) lat (ms,95%): 63.32 err/s: 0.00 reconn/s: 0.00
[ 580s ] thds: 256 tps: 7989.24 qps: 7989.24 (r/w/o: 7989.24/0.00/0.00) lat (ms,95%): 61.08 err/s: 0.00 reconn/s: 0.00
[ 590s ] thds: 256 tps: 8266.79 qps: 8266.79 (r/w/o: 8266.79/0.00/0.00) lat (ms,95%): 58.92 err/s: 0.00 reconn/s: 0.00
[ 600s ] thds: 256 tps: 8126.22 qps: 8126.22 (r/w/o: 8126.22/0.00/0.00) lat (ms,95%): 61.08 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 5071951
write: 0
other: 0
total: 5071951
transactions: 5071951 (8451.70 per sec.)
queries: 5071951 (8451.70 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 600.1084s
total number of events: 5071951
Latency (ms):
min: 2.87
avg: 30.28
max: 369.50
95th percentile: 55.82
sum: 153576184.73
Threads fairness:
events (avg/stddev): 19812.3086/50.79
execution time (avg/stddev): 599.9070/0.04
测试 insert:
> ./insert.sh
+ sysbench --test=./lua-tests/db/insert.lua --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=4000 --mysql-user=root --mysql-password= --mysql-db=sbtest1 --oltp-tables-count=16 --oltp-table-size=1000000 --num-threads=256 --report-interval=10 --max-requests=2000000000 --percentile=95 --max-time=600 run
insert 测试结果如下:
[ 550s ] thds: 256 tps: 3084.73 qps: 3084.73 (r/w/o: 0.00/3084.73/0.00) lat (ms,95%): 110.66 err/s: 0.00 reconn/s: 0.00
[ 560s ] thds: 256 tps: 3164.70 qps: 3164.70 (r/w/o: 0.00/3164.70/0.00) lat (ms,95%): 104.84 err/s: 0.00 reconn/s: 0.00
[ 570s ] thds: 256 tps: 3118.42 qps: 3118.42 (r/w/o: 0.00/3118.42/0.00) lat (ms,95%): 108.68 err/s: 0.00 reconn/s: 0.00
[ 580s ] thds: 256 tps: 3251.01 qps: 3251.01 (r/w/o: 0.00/3251.01/0.00) lat (ms,95%): 101.13 err/s: 0.00 reconn/s: 0.00
[ 590s ] thds: 256 tps: 3109.42 qps: 3109.42 (r/w/o: 0.00/3109.42/0.00) lat (ms,95%): 106.75 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 0
write: 1765555
other: 0
total: 1765555
transactions: 1765555 (2942.26 per sec.)
queries: 1765555 (2942.26 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 600.0653s
total number of events: 1765555
Latency (ms):
min: 34.19
avg: 86.99
max: 927.90
95th percentile: 114.72
sum: 153582581.05
Threads fairness:
events (avg/stddev): 6896.6992/13.22
execution time (avg/stddev): 599.9320/0.05
测试 delete:
> ./delete.sh
+ sysbench --test=./lua-tests/db/delete.lua --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=4000 --mysql-user=root --mysql-password= --mysql-db=sbtest1 --oltp-tables-count=16 --oltp-table-size=1000000 --num-threads=256 --report-interval=10 --max-requests=2000000000 --max-time=600 --percentile=95 run
delete 测试结果如下:
[ 550s ] thds: 256 tps: 6291.62 qps: 6291.62 (r/w/o: 0.00/1284.15/5007.48) lat (ms,95%): 99.33 err/s: 0.00 reconn/s: 0.00
[ 560s ] thds: 256 tps: 6294.83 qps: 6294.83 (r/w/o: 0.00/1278.81/5016.02) lat (ms,95%): 99.33 err/s: 0.00 reconn/s: 0.00
[ 570s ] thds: 256 tps: 6161.33 qps: 6161.33 (r/w/o: 0.00/1252.58/4908.75) lat (ms,95%): 97.55 err/s: 0.00 reconn/s: 0.00
[ 580s ] thds: 256 tps: 6190.38 qps: 6190.48 (r/w/o: 0.00/1244.62/4945.86) lat (ms,95%): 97.55 err/s: 0.00 reconn/s: 0.00
[ 590s ] thds: 256 tps: 6278.86 qps: 6278.76 (r/w/o: 0.00/1279.15/4999.61) lat (ms,95%): 99.33 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 0
write: 887497
other: 2589396
total: 3476893
transactions: 3476893 (5793.68 per sec.)
queries: 3476893 (5793.68 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 600.1166s
total number of events: 3476893
Latency (ms):
min: 5.06
avg: 44.17
max: 5644.54
95th percentile: 102.97
sum: 153575902.59
Threads fairness:
events (avg/stddev): 13581.6133/78.13
execution time (avg/stddev): 599.9059/0.05