系统压力测试工具之 sysbench
sysbench
是一个模块化的、跨平台、多线程、流行的开源基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况
安装软件版本: sysbench-1.0.20-6.el7.x86_64
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
yum -y install sysbench
命令选项
sysbench --help
--time # 压测时间
--threads # 压测线程数
--events # 请求数, 0 无限制
--rate # 请求速率, 0 无限制
--tables # 压测表数量
--table_size # 压测的单表大小,单位行
prepare # 准备测试数据
run # 开始压测
cleanup # 清除压测数据
report-interval # 每多少秒钟报告一次测试结果
File IO 压测
# 查看 fileio 测试模块下的帮助信息
sysbench fileio help
# 准备测试数据, 生成多个测试文件
sysbench fileio --file-total-size=5G prepare
# 运行测试
sysbench fileio --file-total-size=5G --file-test-mode=rndrw --time=30 --events=0 run
# 清除测试数据
sysbench fileio --file-total-size=5G cleanup
测试结果如下:
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Extra file open flags: (none)
128 files, 40MiB each
5GiB total file size
Block size 16KiB
Number of IO requests: 0
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 r/w test
Initializing worker threads...
Threads started!
File operations: # 磁盘io操作
reads/s: 47.68
writes/s: 31.79
fsyncs/s: 104.27
Throughput: # 磁盘吞吐量
read, MiB/s: 0.75
written, MiB/s: 0.50
General statistics: # 测试时间30s, 总请求数 5421
total time: 30.1950s
total number of events: 5421
Latency (ms): # 延迟
min: 0.01
avg: 5.53
max: 181.94
95th percentile: 20.74
sum: 29988.08
Threads fairness:
events (avg/stddev): 5421.0000/0.00
execution time (avg/stddev): 29.9881/0.00
MySQL 压测
读写测试: 3 个表、每个表 1000 行,测试时间 120s, 请求数及请求频率无限制,12 个线程 首次测试 准备测试数据
sysbench --test=/usr/share/sysbench/oltp_read_write.lua \
--mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=root \
--mysql-db=db01 --db-driver=mysql --report-interval=30 \
--time=120 --threads=12 --events=0 --rate=0 --table_size=1000 --tables=3 \
prepare
# 输出如下
Creating table 'sbtest3'...
Creating table 'sbtest1'...
Creating table 'sbtest2'...
Inserting 1000 records into 'sbtest3'
Inserting 1000 records into 'sbtest2'
Inserting 1000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
Creating a secondary index on 'sbtest2'...
Creating a secondary index on 'sbtest3'...
开始压测
sysbench --test=/usr/share/sysbench/oltp_read_write.lua \
--mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=root \
--mysql-db=db01 --db-driver=mysql --report-interval=30 \
--time=120 --threads=12 --events=0 --rate=0 --table_size=1000 --tables=3 \
run
# 输出如下
[ 30s ] thds: 12 tps: 15.73 qps: 326.69 (r/w/o: 230.50/63.99/32.20) lat (ms,95%): 1771.29 err/s: 0.33 reconn/s: 0.00
[ 60s ] thds: 12 tps: 17.90 qps: 366.32 (r/w/o: 257.61/72.40/36.30) lat (ms,95%): 1678.14 err/s: 0.50 reconn/s: 0.00
[ 90s ] thds: 12 tps: 17.13 qps: 345.72 (r/w/o: 242.66/68.60/34.47) lat (ms,95%): 1618.78 err/s: 0.20 reconn/s: 0.00
[ 120s ] thds: 12 tps: 17.37 qps: 356.20 (r/w/o: 250.13/70.83/35.23) lat (ms,95%): 1561.52 err/s: 0.50 reconn/s: 0.00
SQL statistics:
queries performed:
read: 29428
write: 8292
other: 4158
total: 41878
transactions: 2056 (17.04 per sec.)
queries: 41878 (346.99 per sec.)
ignored errors: 46 (0.38 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 120.6877s
total number of events: 2056
Latency (ms):
min: 132.72
avg: 702.06
max: 3397.70
95th percentile: 1678.14
sum: 1443438.80
Threads fairness:
events (avg/stddev): 171.3333/9.13
execution time (avg/stddev): 120.2866/0.21
清除压测数据
sysbench --test=/usr/share/sysbench/oltp_read_write.lua \
--mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=root \
--mysql-db=db01 --db-driver=mysql --report-interval=30 \
--time=120 --threads=12 --events=0 --rate=0 --table_size=1000 --tables=3 \
cleanup