4. 测试
4.1 测试 CPU
$ sysbench --test=cpu --cpu-max-prime=2000 run WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options. sysbench 1.0.11 (using system LuaJIT 2.1.0-beta3) Running the test with following options: Number of threads: 1 Initializing random number generator from current time Prime numbers limit: 2000 Initializing worker threads... Threads started! CPU speed: events per second: 7290.82 General statistics: total time: 10.0017s total number of events: 72939 Latency (ms): min: 0.09 avg: 0.14 max: 20.14 95th percentile: 0.24 sum: 9907.92 Threads fairness: events (avg/stddev): 72939.0000/0.00 execution time (avg/stddev): 9.9079/0.00
4.2 测试线程
$ sysbench --test=threads --num-threads=500 --thread-yields=100 --thread-locks=4 run WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options. WARNING: --num-threads is deprecated, use --threads instead sysbench 1.0.11 (using system LuaJIT 2.1.0-beta3) Running the test with following options: Number of threads: 500 Initializing random number generator from current time Initializing worker threads... Threads started! General statistics: total time: 10.1607s total number of events: 59317 Latency (ms): min: 0.05 avg: 84.75 max: 2438.83 95th percentile: 337.94 sum: 5027365.00 Threads fairness: events (avg/stddev): 118.6340/83.13 execution time (avg/stddev): 10.0547/0.05
4.3 测试 IO
--num-threads
开启的线程 --file-total-size
总的文件大小
- prepare阶段,生成需要的测试文件,完成后会在当前目录下生成很多小文件。
sysbench --test=fileio --num-threads=16 --file-total-size=2G --file-test-mode=rndrw prepare
- run阶段
sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw run
- 清理测试时生成的文件
sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw cleanup
4.4 测试内存
$ sysbench --test=memory --memory-block-size=8k --memory-total-size=1G run WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options. sysbench 1.0.11 (using system LuaJIT 2.1.0-beta3) Running the test with following options: Number of threads: 1 Initializing random number generator from current time Running memory speed test with the following options: block size: 8KiB total size: 1024MiB operation: write scope: global Initializing worker threads... Threads started! Total operations: 131072 (599444.59 per second) 1024.00 MiB transferred (4683.16 MiB/sec) General statistics: total time: 0.2148s total number of events: 131072 Latency (ms): min: 0.00 avg: 0.00 max: 4.26 95th percentile: 0.00 sum: 159.78 Threads fairness: events (avg/stddev): 131072.0000/0.00 execution time (avg/stddev): 0.1598/0.00
4.5 测试 mutex
略
4.6 测试 OLTP
- prepare阶段,生成需要的测试表
sysbench --test=oltp --mysql-table-engine=innodb --mysql-host=192.168.X.X --mysql-db=test --oltp-table-s
- run阶段
sysbench --num-threads=16 --test=oltp --mysql-table-engine=innodb --mysql-host=192.168.x.x --mysql-db=test --oltp
- 清理测试时生成的测试表
sysbench --num-threads=16 --test=oltp --mysql-table-engine=innodb --mysql-host=192.168.x.x --mysql-db=test --oltp-table-
4.7 测试OLTP 结合lua脚本
$ dpkg -L sysbench /. /usr /usr/bin /usr/bin/sysbench /usr/share /usr/share/doc /usr/share/doc/sysbench /usr/share/doc/sysbench/README.md.gz /usr/share/doc/sysbench/changelog.Debian.gz /usr/share/doc/sysbench/copyright /usr/share/doc/sysbench/manual.html /usr/share/doc-base /usr/share/doc-base/sysbench-manual /usr/share/man /usr/share/man/man1 /usr/share/man/man1/sysbench.1.gz /usr/share/sysbench /usr/share/sysbench/bulk_insert.lua /usr/share/sysbench/oltp_common.lua /usr/share/sysbench/oltp_delete.lua /usr/share/sysbench/oltp_insert.lua /usr/share/sysbench/oltp_point_select.lua /usr/share/sysbench/oltp_read_only.lua /usr/share/sysbench/oltp_read_write.lua /usr/share/sysbench/oltp_update_index.lua /usr/share/sysbench/oltp_update_non_index.lua /usr/share/sysbench/oltp_write_only.lua /usr/share/sysbench/select_random_points.lua /usr/share/sysbench/select_random_ranges.lua
参数
--test=tests/db/oltp.lua 表示调用 tests/db/oltp.lua 脚本进行 oltp 模式测试
--mysql-table-engine=innodb 表示选择测试表的存储引擎
--oltp_tables_count=10 表示会生成 10 个测试表
--oltp-table-size=100000 表示每个测试表填充数据量为 100000
--rand-init=on 表示每个测试表都是用随机数据来填充的
--num-threads=8 表示发起 8个并发连接
--oltp-read-only=off 表示不要进行只读测试,也就是会采用读写混合模式测试
--report-interval=10 表示每10秒输出一次测试进度报告
--rand-type=uniform 表示随机类型为固定模式,其他几个可选随机模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累托)
--max-time=120 表示最大执行时长为 120秒
--max-requests=0 表示总请求数为 0,因为上面已经定义了总执行时长,所以总请求数可以设定为 0;也可以只设定总请求数,不设定最大执行时长
--percentile=99 表示设定采样比例,默认是 95%,即丢弃1%的长请求,在剩余的99%里取最大值
如果在本机,也可以使用 –mysql-socket 指定 socket 文件来连接。加载测试数据时长视数据量而定,若过程比较久需要稍加耐心等待。
初始化数据:prepare
在本地数据库的dba_test库中,初始化三张表(sbtest1、sbtest2、sbtest3),存储引擎是innodb,每张表50万数据。
sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua --mysql-table-engine=innodb --mysql-host=127.0.0.1 --mysql-db=dba_test --oltp-table-size=500000 --oltp_tables_count=3 --rand-init=on --mysql-user=zjy --mysql-password=zjy prepare
如果是本机测试,所以也可以使用–mysql-socket指定socket文件来连接。
- 测试:run
模拟对3个表并发OLTP测试,每个表50万行记录,持续压测时间为5分钟。
sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua --mysql-table-engine=innodb --mysql-host=127.0.0.1 --mysql-db=dba_test --num-threads=8 --oltp-table-size=500000 --oltp_tables_count=3 --oltp-read-only=off --report-interval=10 --rand-type=uniform --max-time=600 --max-requests=0 --percentile=99 --mysql-user=zjy --mysql-password=zjy run
结果:
#每10秒钟报告一次测试结果,tps、每秒读、每秒写、95%以上的响应时长统计 [ 10s] threads: 8, tps: 66.60, reads: 943.67, writes: 269.62, response time: 431.72ms (95%), errors: 0.00, reconnects: 0.00 [ 20s] threads: 8, tps: 34.30, reads: 480.20, writes: 137.20, response time: 598.28ms (95%), errors: 0.00, reconnects: 0.00 [ 30s] threads: 8, tps: 36.60, reads: 512.40, writes: 146.40, response time: 494.87ms (95%), errors: 0.00, reconnects: 0.00 OLTP test statistics: queries performed: read: 941248 #读总数 write: 268928 #写总数 other: 134464 #其他操作总数(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等) total: 1344640 #全部总数 transactions: 67232 (112.04 per sec.) #总事务数(每秒事务数) read/write requests: 1210176 (2016.73 per sec.) #读写总数(每秒读写次数) other operations: 134464 (224.08 per sec.) #其他操作总数(每秒其他操作次数) ignored errors: 0 (0.00 per sec.) reconnects: 0 (0.00 per sec.) General statistics: total time: 600.0698s #总耗时 total number of events: 67232 #共发生多少事务数 total time taken by event execution: 4799.8569s # 所有事务耗时相加(不考虑并行因素) response time: min: 2.09ms #最小耗时 avg: 71.39ms #平均耗时 max: 839.32ms #最大耗时 approx. 95 percentile: 309.40ms 超过95%平均耗时 Threads fairness: events (avg/stddev): 8404.0000/17.56 execution time (avg/stddev): 599.9821/0.02
- 清理数据:cleanup
sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua --mysql-table-engine=innodb --mysql-host=127
参考: