使用sysbench进行MySQL压力测试

1. 安装 sysbench

[root@benchserver ~]# yum install sysbench


[root@benchserver ~]# rpm -ql sysbench-1.0.17-2.el7.x86_64 | grep lua$

sysbench使用lua脚本编写,所以最终测试都需要调用lua脚本。


[root@benchserver ~]# sysbench --help

实际使用中参数不多,核心参数如下:

General options:

  --config-file=FILENAME          File containing command line options

  --threads=N                     number of threads to use [1]

  --time=N                        limit for total execution time in seconds [10]

  --report-interval=N             periodically report intermediate statistics with a specified interval in seconds.


  --db-driver=STRING  specifies database driver to use [mysql]

Compiled-in database drivers:

  mysql - MySQL driver

  pgsql - PostgreSQL driver

  

mysql options:

  --mysql-host=[LIST,...]          MySQL server host [localhost]

  --mysql-port=[LIST,...]          MySQL server port [3306]

  --mysql-user=STRING              MySQL user [sbtest]

  --mysql-password=STRING          MySQL password []

  --mysql-db=STRING                MySQL database name [sbtest]



2. MySQL数据库创建压力测试用账号

(root@localhost 18:38) [(none)]> create user 'admin'@'10.9.82.187' identified by 'oracle';

(root@localhost 18:39) [(none)]> flush privileges;

(root@localhost 18:39) [(none)]> create database sbtest;

(root@localhost 18:39) [(none)]> grant all on sbtest.* to 'admin'@'10.9.82.187';


3. 压力测试主机测试远程登录

[root@benchserver ~]# mysql -h 10.9.59.32 -u admin -poracle -D sbtest


4. 创建压力测试脚本

[root@benchserver ~]# mkdir sysbench

[root@benchserver ~]# cd sysbench/

[root@benchserver sysbench]# vi mysql_config


mysql-host=10.9.59.32

mysql-port=3306

mysql-user=admin

mysql-password=oracle

mysql-db=sbtest

time=6000

threads=8

report-interval=1

db-driver=mysql


5. 数据初始化

[root@benchserver sysbench]# sysbench --config-file=mysql_config oltp_point_select --tables=16 --table-size=100000 prepare

prepare 为初始化测试


6. 压力测试

[root@benchserver sysbench]# sysbench --config-file=mysql_config oltp_point_select --tables=16 --table-size=100000 run | tee oltp_point_select.rpt

run 为实际压力测试


Initializing worker threads...

Threads started!


[ 1s ] thds: 16 tps: 25021.07 qps: 25021.07 (r/w/o: 25021.07/0.00/0.00) lat (ms,95%): 0.90 err/s: 0.00 reconn/s: 0.00

[ 24s ] thds: 16 tps: 26823.29 qps: 26823.29 (r/w/o: 26823.29/0.00/0.00) lat (ms,95%): 0.84 err/s: 0.00 reconn/s: 0.00



上一篇:sysbench测试mysql性能


下一篇:Linux 性能测试工具 sysbench 的安装与简单使用