您的位置:首页 > 编程语言 > PHP开发

sysbench 0.5 oltp测试笔记

2016-03-16 11:04 543 查看
sysbench 0.5相比0.4版本的主要变化是,oltp测试结合了lua脚本,不需要修改源码,通过自定义lua脚本就可以实现不同业务类型的测试。同时0.5相比0.4需要消耗更多的cpu资源。
1、查看帮助
sysbench --help
sysbench --test=fileio help

可以查看fileio、cpu、memory、threads、mutex的详细参数,0.4版本还可以查看oltp的参数

2、初始化测试表
创建单表,c和pad包含随机字符,k列是1到oltp-table-size的随机整数:

sysbench --test=/local/sysbenchtest/sysbench-0.5/sysbench/tests/db/oltp.lua --oltp-table-
size=1000000 --mysql-table-engine=innodb --mysql-user=root --mysql-port=3306 --mysql-

host=localhost --mysql-db=test prepare

参数说明:
--oltp-table-size:指定表的大小,即表的行数
--mysql-table-engine:指定存储引擎,如myisam,innodb,heap,ndbcluster,bdb,maria,falcon,pbxt
--mysql-db:指定在哪个数据库创建测试表,默认为sbtest库,需要提前创建好
--test:指定Lua脚本,参数选项大部分同老版本的--test=oltp help
--db-driver:指定驱动,默认为Mysql
--myisam-max-rows:指定Myisam表的MAX_ROWS选项
--oltp-secondary:测试表将使用二级索引KEY xid (ID) 替代 PRIMARY KEY (ID),innodb引擎内部为每个表创建唯一6字节的主键索引
--oltp-auto-inc:设置id列为auto-incremental,值为on或off,默认为on

创建多个表,使用--oltp-tables-count指定,默认为1:
./sysbench --test=tests/db/oltp.lua --oltp-tables-count=25 prepare

使用多线程创建多表,节省准备时间:
./sysbench --test=tests/db/parallel_prepare.lua --oltp-tables-count=64 --num-threads=8 run

--oltp-tables-count的数量应该是--num-threads的倍数。

3、进行oltp测试
单表:
sysbench --test=/local/sysbenchtest/sysbench-0.5/sysbench/tests/db/oltp.lua --oltp-table-size=1000000 --mysql-table-engine=innodb --mysql-user=root --mysql-port=3306 --mysql-host=localhost --mysql-db=test --max-requests=0 --max-time=600 --num-threads=512 --report-interval=10 run

如果使用--max-time(这里设置600s),需要设置--max-request为0,默认是10000(总请求数)
--num-threads:指定并发线程数,每个线程将选择一个随机的表
--oltp-dist-type:指定随机取样类型,默认为special,允许的值:uniform、gauss、special
--oltp-dist-pct:记录读取百分比
--oltp-dist-res:分配的概率
--oltp-read-only:执行仅仅SELECT测试,默认off

多表:
./sysbench --test=tests/db/oltp.lua --oltp-tables-count=25 --num-threads=5 run

创建表从sbtest1到sbtest25。

SELECT测试:
./sysbench --test=tests/db/select.lua --oltp-table-size=1000000 --mysql-table-engine=innodb --mysql-user=sysbench --mysql-password=sysbench --mysql-port=3306 --mysql-host=10.0.37.123 --mysql-db=test --max-requests=0 --max-time=600 --oltp-tables-count=20 --report-interval=10 run

另外有两个独立脚本可以进行Point select查询和Range查询的脚本:select_random_points.lua、select_random_ranges.lua

可选参数:
--oltp-point-selects:在一个事务里面Point select的数量,默认为10
--oltp-range-size:range查询的范围大小,默认100,应该小于oltp-table-size
--oltp-simple-ranges:在一个事务里面简单range查询的数量,默认1
--oltp-sum-ranges:在一个事务里面SUM range查询的数量,默认1
--oltp-order-ranges:在一个事务里面ORDER range查询的数量,默认1
--oltp-distinct-ranges:在一个事务里面DISTINCT range查询的数量,默认1

UPDATE测试:
同时有两个独立脚本可以进行update测试:update_index.lua、update_non_index.lua
./sysbench --test=tests/db/update_index.lua --oltp-table-size=1000000 --mysql-table-engine=innodb --mysql-user=sysbench --mysql-password=sysbench --mysql-port=3306 --mysql-host=10.0.37.123 --mysql-db=test --max-requests=0 --max-time=600 --oltp-tables-count=20 --report-interval=10 --num_threads=512 run

可选参数:
--oltp-index-updates:在单个事务中index update的数量,默认1;
--oltp-non-index-updates:在单个事务中non-index update的数量,默认1;

4、清除表
./sysbench --test=tests/db/oltp.lua --oltp-tables-count=25 --num-threads=5 cleanup

5、oltp测试结果

sysbench 0.5: multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 512 #测试线程数量,当前为512
Report intermediate results every 10 second(s) #每10秒打印下信息
Random number generator seed is 0 and will be ignored

Threads started!

[ 10s] threads: 512, tps: 2169.58, reads/s: 30860.50, writes/s: 8706.12, response time: 456.99ms (95%)
[ 20s] threads: 512, tps: 2233.20, reads/s: 31197.05, writes/s: 8929.02, response time: 469.47ms (95%)
[ 30s] threads: 512, tps: 2249.30, reads/s: 31496.60, writes/s: 8995.40, response time: 445.78ms (95%)
[ 40s] threads: 512, tps: 2202.50, reads/s: 30844.00, writes/s: 8807.40, response time: 481.42ms (95%)
[ 50s] threads: 512, tps: 2263.60, reads/s: 31680.90, writes/s: 9052.30, response time: 441.13ms (95%)
[ 60s] threads: 512, tps: 2259.20, reads/s: 31616.80, writes/s: 9042.50, response time: 441.92ms (95%)
[ 70s] threads: 512, tps: 2276.20, reads/s: 31923.20, writes/s: 9115.90, response time: 444.04ms (95%)
[ 80s] threads: 512, tps: 2276.30, reads/s: 31850.90, writes/s: 9100.90, response time: 443.78ms (95%) #tps表示10s内的平均事务数,reads/s表示select语句在10s内平均的执行数量,writes/s表示update、insert、delete语句在10s内平均的执行数量,response time表示95%语句的平均响应时间
...
OLTP test statistics:
queries performed:
read: 19057346 #总select语句数量
write: 5444956 #总update、insert、delete语句数量
other: 2722478#为commit、unlock tables以及其他mutex的数量
total: 27224780
transactions: 1361239 (2268.17 per sec.) #通常需要关注的数字(TPS)
deadlocks: 0 (0.00 per sec.) #整个测试过程中发生死锁次数
read/write requests: 24502302 (40827.01 per sec.)
other operations: 2722478 (4536.33 per sec.)

General statistics:
total time: 600.1494s #总执行时间,如果使用了max-request参数,可以关注下这个结果
total number of events: 1361239
total time taken by event execution: 307190.3628s
response time:
min: 7.13ms
avg: 225.67ms
max: 1471.84ms #最大响应时间
approx. 95 percentile: 440.34ms #95%的语句的平均响应时间

Threads fairness:
events (avg/stddev): 2658.6699/50.08
execution time (avg/stddev): 599.9812/0.29

在源码文件db_driver.c和sb_fileio.c中有对各参数值进行定义。

同时测试时使用orzdba工具统计的数据部分如下:

-------- -------------------------io-usage----------------------- -QPS- -TPS-
time | r/s w/s rkB/s wkB/s queue await svctm %util| ins upd del sel iud|
20:04:29| 0.0 2475.2 0.0 16002.0 0.1 0.1 0.0 8.7| 2166 4330 2165 30326 8661|
20:04:39| 0.0 2670.6 0.0 16738.0 0.1 0.1 0.0 9.1| 2156 4313 2156 30187 8626|
20:04:49| 0.0 2356.0 0.0 14956.9 0.1 0.1 0.0 9.2| 2172 4344 2171 30423 8688|
20:04:59| 0.0 2725.8 0.0 15563.3 0.1 0.1 0.0 9.4| 2168 4336 2169 30356 8675|
20:05:09| 0.0 2569.7 0.0 15425.1 0.1 0.1 0.0 8.7| 2165 4333 2165 30327 8663|
20:05:19| 0.0 2640.6 0.0 15377.1 0.2 0.1 0.0 9.7| 2170 4338 2170 30401 8679|
20:05:30| 0.0 2376.1 0.0 14424.9 0.1 0.1 0.0 8.2| 2180 4357 2179 30495 8717|
20:05:40| 0.0 2553.4 0.0 15090.8 0.1 0.1 0.0 8.8| 2164 4333 2166 30297 8664|
20:05:50| 0.0 2416.2 0.0 15587.6 0.1 0.1 0.0 8.5| 2174 4345 2173 30447 8693|
20:06:00| 0.0 2422.9 0.0 15534.9 0.1 0.1 0.0 8.0| 2172 4344 2172 30404 8690|
20:06:10| 0.1 2499.2 0.4 15285.3 0.1 0.1 0.0 9.1| 2167 4337 2167 30360 8672|
20:06:20| 0.0 2364.3 0.0 14850.4 0.2 0.1 0.0 9.4| 2167 4333 2168 30354 8669|
20:06:30| 0.0 2645.1 0.0 15898.7 0.1 0.1 0.0 9.1| 2166 4334 2167 30330 8668|
20:06:40| 0.0 2276.3 0.0 15125.8 0.1 0.1 0.0 7.9| 2168 4333 2167 30323 8669|
20:06:50| 0.0 2482.1 0.0 16110.2 0.1 0.1 0.0 9.5| 2167 4336 2167 30346 8671|

可以对比出sysbench的输出值含义。

参考:
1、"白​皮​书​ ​M​y​S​Q​L​ ​性​能​基​准​测​试":http://wenku.baidu.com/view/c10eea360b4c2e3f57276314.html
2、"服​务​器​性​能​测​试​利​器​_​之​三​_​平​台​处​理​性​能​工​具​S​Y​S​B​E​N​C​H":http://wenku.baidu.com/view/0b3e6ed45022aaea998f0f93.html
3、"Sysbench with support of multi-tables workload":http://www.mysqlperformanceblog.com/2011/04/29/sysbench-with-support-of-multi-tables-workload/
4、"Using Lua-enabled sysbench":https://blog.mariadb.org/using-lua-enabled-sysbench/
5、"oltp.lua":http://www.percona.com/docs/wiki/benchmark:sysbench:olpt.lua
6、https://github.com/jayjanssen/sysbench-graphing-tests
7、http://wiki.gentoo.org/wiki/Sysbench
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: