Mysqlslap MySQL 压力测试工具

一、安装Mysqlslap

二、参数说明

[root@mysql01 /]# mysqlslap --help

主要参数:

1) --concurrency代表并发数量,多个可以用逗号隔开,例如:concurrency=10,50,100, 并发连接线程数分别是10、50、100个并发。
2) --engines代表要测试的引擎,可以有多个,用分隔符隔开。
3) --iterations代表要运行这些测试多少次。
4) --auto-generate-sql 代表用系统自己生成的SQL脚本来测试。
5)--auto-generate-sql-load-type 代表要测试的是读还是写还是两者混合的(read,write,update,mixed)
6) --number-of-queries 代表总共要运行多少次查询。每个客户端运行的查询数量可以用查询总数/并发数来计算。
7) --debug-info 代表要额外输出CPU以及内存的相关信息。
8) --number-int-cols :创建测试表的 int 型字段数量
9) --auto-generate-sql-add-autoincrement : 代表对生成的表自动添加auto_increment列,从5.1.18版本开始
10) --number-char-cols 创建测试表的 char 型字段数量。
11) --create-schema 测试的schema,MySQL中schema也就是database。
12) --query  使用自定义脚本执行测试,例如可以调用自定义的一个存储过程或者sql语句来执行测试。
13) --only-print 如果只想打印看看SQL语句是什么,可以用这个选项
EG:
实验基础步骤:
 1.单线程测试
 [root@mysql01 /]# mysqlslap -a --engine=myisam,innodb -h 10.2.3.218 -p3306 -uroot -payilian

Benchmark
        Running for engine myisam
        Average number of seconds to run all queries: 0.014 seconds
        Minimum number of seconds to run all queries: 0.014 seconds
        Maximum number of seconds to run all queries: 0.014 seconds
        Number of clients running queries: 1
        Average number of queries per client: 0

Benchmark
        Running for engine innodb
        Average number of seconds to run all queries: 0.018 seconds
        Minimum number of seconds to run all queries: 0.018 seconds
        Maximum number of seconds to run all queries: 0.018 seconds
        Number of clients running queries: 1
        Average number of queries per client: 0

 2.并在100的用户

[root@mysql01 /]# mysqlslap -a -c100 --engine=innodb -h 10.2.3.218 -p3306 -uroot -payilian
Benchmark
        Running for engine innodb
        Average number of seconds to run all queries: 2.313 seconds
        Minimum number of seconds to run all queries: 2.313 seconds
        Maximum number of seconds to run all queries: 2.313 seconds
        Number of clients running queries: 100
        Average number of queries per client: 0
练习一:
单线程测试。测试做了什么。
>./bin/mysqlslap -a -uroot -p111111
多线程测试。使用--concurrency来模拟并发连接。
> ./bin/mysqlslap -a -c 100 -uroot -p111111
迭代测试。用于需要多次执行测试得到平均值。
> ./bin/mysqlslap -a -i 10 -uroot -p111111

练习二:
> ./bin/mysqlslap -auto-generate-sql-add-autoincrement -a -uroot -p111111
> ./bin/mysqlslap -a -auto-generate-sql-load-type=read -uroot -p111111
> ./bin/mysqlslap -a -auto-generate-secondary-indexes=3 -uroot -p111111
> ./bin/mysqlslap -a -auto-generate-sql-write-number=1000 -uroot -p111111
> ./bin/mysqlslap --create-schema world -q "select count(*) from City" -uroot -p111111
> ./bin/mysqlslap -a -e innodb -uroot -p111111
> ./bin/mysqlslap -a --number-of-queries=10 -uroot -p111111

练习三:
执行一次测试,分别50和100个并发,执行1000次总查询:
> ./bin/mysqlslap -a --concurrency=50,100 --number-of-queries 1000 --debug-info -uroot -p111111

50和100个并发分别得到一次测试结果(Benchmark),并发数越多,执行完所有查询的时间越长。为了准确起见,可以多迭代测试几次:
> ./bin/mysqlslap -a --concurrency=50,100 --number-of-queries 1000 --iterations=5 --debug-info -uroot -p111111

测试同时不同的存储引擎的性能进行对比:
>./bin/mysqlslap -a --concurrency=50,100 --number-of-queries 1000 --iterations=5 --engine=myisam,innodb --debug-info -uroot -p111111

 A.本次主要是在IBM3850,备注本次测试以远程主机10.2.3.218100个并发线程、测试10次,自动生成SQL测试脚本、读、写、更新混合测试、自增长字段、测试引擎为myisam innodb、共运行10次查询,输出cpu资源信息  

[root@mysql01 /]# mysqlslap -a -c 100 -i 10 --engine=myisam,innodb  -h 10.2.3.218 -p3306 -uroot -payilian
Benchmark
        Running for engine myisam
        Average number of seconds to run all queries: 2.305 seconds
        Minimum number of seconds to run all queries: 2.290 seconds
        Maximum number of seconds to run all queries: 2.317 seconds
        Number of clients running queries: 100
        Average number of queries per client: 0

Benchmark
        Running for engine innodb
        Average number of seconds to run all queries: 2.307 seconds
        Minimum number of seconds to run all queries: 2.297 seconds
        Maximum number of seconds to run all queries: 2.323 seconds
        Number of clients running queries: 100
        Average number of queries per client: 0

B.输出100个线程并发,5次迭代,1000个客户端同时进行,增加了--number-of-queries= 200  个

[root@mysql01 /]# mysqlslap -a -c 100 -i 5 --number-of-queries= 1000 --debug-info --engine=myisam,innodb -h 10.2.3.218 -p3306 -uroot -payilian

Benchmark
        Running for engine myisam
        Average number of seconds to run all queries: 2.314 seconds
        Minimum number of seconds to run all queries: 2.301 seconds
        Maximum number of seconds to run all queries: 2.334 seconds
        Number of clients running queries: 100
        Average number of queries per client: 0

Benchmark
        Running for engine innodb
        Average number of seconds to run all queries: 2.306 seconds
        Minimum number of seconds to run all queries: 2.298 seconds
        Maximum number of seconds to run all queries: 2.320 seconds
        Number of clients running queries: 100
        Average number of queries per client: 0


User time 1.03, System time 1.85
Maximum resident set size 13592, Integral resident set size 0
Non-physical pagefaults 21177, Physical pagefaults 0, Swaps 0
Blocks in 0 out 0, Messages in 0 out 0, Signals 0
Voluntary context switches 121332, Involuntary context switches 41

 

你可能感兴趣的:(Mysqlslap MySQL 压力测试工具)