混合随机读/写:(如果执行出错,需要重新prepare数据)
sysbench fileio --file-total-size=40G --file-test-mode=rndrw --max-time=100 --max-requests=0 run
#测试结果:
File operations:
reads/s: 338.98
writes/s: 225.99
fsyncs/s: 722.23
Throughput:
read, MiB/s: 5.30
written, MiB/s: 3.53
General statistics:
total time: 100.0007s
total number of events: 128727
Latency (ms):
min: 0.00
avg: 0.78
max: 43.01
95th percentile: 2.97
sum: 99785.92
Threads fairness:
events (avg/stddev): 128727.0000/0.00
execution time (avg/stddev): 99.7859/0.00
清除测试数据:
sysbench fileio --file-total-size=40G cleanup
OLTP基准测试
OLTP基准测试模拟了一个简单的事务处理系统的工作负载。若要对数据库性能进行测试就要使用OLTP相关的脚本。
在/usr/share/sysbench/目录下有相关的lua脚本:
bulk_insert.lua
oltp_common.lua
oltp_delete.lua
oltp_insert.lua
oltp_point_select.lua
oltp_read_only.lua
oltp_read_write.lua
oltp_update_index.lua
oltp_update_non_index.lua
oltp_write_only.lua
select_random_points.lua
select_random_ranges.lua
对于未知的测试参数,可以通过 sysbench scripts-name help 来查看。
创建测试数据:
sysbench oltp_common --table-size=1000000 --db-driver=mysql \
--mysql-db=test --mysql-user=root --mysql-password=123456 prepare
Creating table 'sbtest1'...
Inserting 1000000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
执行run命令进行测试:(只读)
sysbench oltp_read_only --table-size=1000000 --db-driver=mysql \
--mysql-db=test --mysql-user=root --mysql-password=123456 --time=60 --max-requests=0 --threads=8 run
#测试结果
Running the test with following options:
Number of threads: 8
Initializing random number generator from current time
Initializing worker threads...
Threads started!
SQL statistics:
queries performed:
read: 1679174
write: 0
other: 239882
total: 1919056
transactions: 119941 (1998.81 per sec.)
queries: 1919056 (31980.95 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 60.0047s
total number of events: 119941
Latency (ms):
min: 0.32
avg: 4.00
max: 56.17
95th percentile: 8.13
sum: 479830.78
Threads fairness:
events (avg/stddev): 14992.6250/116.75
execution time (avg/stddev): 59.9788/0.00
除了使用read_only测试,我们还可以测试数据库的写性能: