sysbench1.0.6 初学

Sysbench 1.0.6 实战
本文介绍 Sysbench 1.0.6 的安装及 MySQL 测试流程,包括使用 Lua 脚本进行读写测试的具体命令与参数说明,并展示了测试结果。

sysbench1.0.6 初学

什么是sysbench

sysbench是一个模块化的、跨平台、多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况。目前项目放在https://github.com/akopytov/sysbench下,由于我在学习的时候在网上找到的攻略都是0.5甚至之前的版本,所以写下这篇,记录一下,目前sysbench的最新版本是1.0.6
安装方式请参照git,根据自己的操作系统来安装,还是相当方便
这篇文章目前只记录下了测试mysql的相关记录

如何进行测试

1.0.6版本,sysbench舍弃了--test参数,0.5版本如果希望测试数据库信息,需要使用--test=oltp参数,但是1.0.6版本后不再使用oltp,转为使用oltp*.lua脚本。本人的电脑是mac, 在/usr/local/Cellar/sysbench/1.0.6/share/sysbench路径下有很多oltp脚本可供使用,满足基本的测试需求。

使用的基本命令

sysbench [options]... [testname] [command]
首先给出一条本人实际测试使用的语句:
sysbench oltp_read_write.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-db=test --mysql-user=root --mysql-password=root --table_size=5000000 --tables=10 --threads=300 --time=60 --report-interval=10
不着急来理解这句话的意思,接下来先介绍一下参数,同样的,目前我只能介绍一些mysql相关的参数

参数介绍

--mysql-hostIP
--mysql-port端口号
--mysql-db希望链接的数据库
--mysql-user用户名
--mysql-password密码
--table_size每张表初始化的数据数量
--tables初始化表的数量
--threads启动的线程
--time运行时间
--report-interval运行期间日志,单位为秒

所有的参数,运行 sysbench --help就能查询到,在oltp_common.lua文件中,还有一部分参数可以配置,全部包含在Command line options下。现在是不是能看到上面的语句了,接来下介绍如何测试。

MYSQL测试步骤

  1. 写好上面的语句
  2. 在上面的语句后面加上 prepare,执行
  3. 在上面的语句后面加上 run,执行
  4. 在上面的语句后面加上 cleanup,执行

prepare用于准备测试需要的数据,准备完后执行run来测试,测试完成后不要忘记执行cleanup来清楚测试数据

测试结果

[ 10s ] thds: 30 tps: 238.20 qps: 4792.68 (r/w/o: 3358.75/954.52/479.41) lat (ms,95%): 356.70 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 30 tps: 199.33 qps: 4008.60 (r/w/o: 2808.22/801.72/398.66) lat (ms,95%): 427.07 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 30 tps: 222.18 qps: 4432.67 (r/w/o: 3101.77/886.53/444.37) lat (ms,95%): 411.96 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 30 tps: 217.66 qps: 4351.35 (r/w/o: 3047.18/868.85/435.33) lat (ms,95%): 434.83 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 30 tps: 235.88 qps: 4720.63 (r/w/o: 3304.44/944.43/471.76) lat (ms,95%): 397.39 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 30 tps: 255.40 qps: 5107.68 (r/w/o: 3575.68/1021.50/510.50) lat (ms,95%): 427.07 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 192010
write: 54860
other: 27430
total: 274300
transactions: 13715 (228.31 per sec.)
queries: 274300 (4566.27 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)

General statistics:
total time: 60.0694s
total number of events: 13715

Latency (ms):
min: 3.85
avg: 131.30
max: 1023.83
95th percentile: 397.39
sum: 1800773.83

Threads fairness:
events (avg/stddev): 457.1667/6.22
execution time (avg/stddev): 60.0258/0.02

上面[10s]之类的表示间隔时间的日志,SQL statistics表示总的测试结果


查找lua文件:

[root@centos128 /]# find ./ -name oltp_read_write.lua
./usr/share/sysbench/oltp_read_write.lua
[root@centos128 /]# cd /usr/share/sysbench
[root@centos128 sysbench]# ll
total 60
-rwxr-xr-x 1 root root  1452 May 12 23:49 bulk_insert.lua
-rw-r--r-- 1 root root 13762 May 12 23:49 oltp_common.lua
-rwxr-xr-x 1 root root  1116 May 12 23:49 oltp_delete.lua
-rwxr-xr-x 1 root root  2018 May 12 23:49 oltp_insert.lua
-rwxr-xr-x 1 root root  1265 May 12 23:49 oltp_point_select.lua
-rwxr-xr-x 1 root root  1649 May 12 23:49 oltp_read_only.lua
-rwxr-xr-x 1 root root  1824 May 12 23:49 oltp_read_write.lua
-rwxr-xr-x 1 root root  1118 May 12 23:49 oltp_update_index.lua
-rwxr-xr-x 1 root root  1127 May 12 23:49 oltp_update_non_index.lua
-rwxr-xr-x 1 root root  1440 May 12 23:49 oltp_write_only.lua
-rwxr-xr-x 1 root root  1919 May 12 23:49 select_random_points.lua
-rwxr-xr-x 1 root root  2118 May 12 23:49 select_random_ranges.lua
drwxr-xr-x 4 root root    49 Jul  4 23:59 tests


运用lua文件

[root@centos128 sysbench]# sysbench oltp_read_write.lua   --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-db=qn --mysql-user=root --mysql-password=123456 --table_size=5000000 --tables=10 --threads=300 --time=10 --report-interval=10 prepare
sysbench 1.0.6 (using system LuaJIT 2.0.4)

Initializing worker threads...

Creating table 'sbtest2'...
Creating table 'sbtest1'...
Creating table 'sbtest7'...
Inserting 5000000 records into 'sbtest2'
Creating table 'sbtest4'...
Creating table 'sbtest8'...
Creating table 'sbtest10'...
Creating table 'sbtest3'...
Creating table 'sbtest5'...
Creating table 'sbtest6'...
Creating table 'sbtest9'...
Inserting 5000000 records into 'sbtest7'
Inserting 5000000 records into 'sbtest1'
Inserting 5000000 records into 'sbtest10'
Inserting 5000000 records into 'sbtest4'
Inserting 5000000 records into 'sbtest8'
Inserting 5000000 records into 'sbtest3'
Inserting 5000000 records into 'sbtest9'
Inserting 5000000 records into 'sbtest5'
Inserting 5000000 records into 'sbtest6'



sysbench oltp_read_write.lua   --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-db=qn --mysql-user=root --mysql-password=123456 --table_size=5000000 --tables=10 --threads=300 --time=60 --report-interval=10 run

[root@centos128 sysbench]# sysbench oltp_read_write.lua   --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-db=qn --mysql-user=root --mysql-password=123456 --table_size=5000000 --tables=10 --threads=300 --time=10  --report-interval=10 cleanup
sysbench 1.0.6 (using system LuaJIT 2.0.4)

Dropping table 'sbtest1'...
Dropping table 'sbtest2'...
Dropping table 'sbtest3'...
Dropping table 'sbtest4'...
Dropping table 'sbtest5'...
Dropping table 'sbtest6'...
Dropping table 'sbtest7'...
Dropping table 'sbtest8'...
Dropping table 'sbtest9'...
Dropping table 'sbtest10'...





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值