使用mysqlslap进行MySQL压力测试

MySQL从5.1.4版开始带有一个压力测试工具mysqlslap,通过模拟多个并发客户端访问mysql来执行测试,使用起来非常的简单。通过mysqlslap �Chelp可以获得可用的选项,这里列一些主要的参数,更详细的说明参考官方手册。

  1. --auto-generate-sql, -a

  2. 自动生成测试表和数据


  3. --auto-generate-sql-load-type=type

  4. 测试语句的类型。取值包括:read,key,write,update和mixed(默认)。


  5. --number-char-cols=N, -x N

  6. 自动生成的测试表中包含多少个字符类型的列,默认1


  7. --number-int-cols=N, -y N

  8. 自动生成的测试表中包含多少个数字类型的列,默认1


  9. --number-of-queries=N

  10. 总的测试查询次数(并发客户数×每客户查询次数)


  11. --query=name,-q

  12. 使用自定义脚本执行测试,例如可以调用自定义的一个存储过程或者sql语句来执行测试。


  13. --create-schema

  14. 测试的schema,MySQL中schema也就是database


  15. --commint=N

  16. 多少条DML后提交一次


  17. --compress, -C

  18. 如果服务器和客户端支持都压缩,则压缩信息传递


  19. --concurrency=N, -c N

  20. 并发量,也就是模拟多少个客户端同时执行select。可指定多个值,以逗号或者�Cdelimiter参数指定的值做为分隔符


  21. --engine=engine_name, -e engine_name

  22. 创建测试表所使用的存储引擎,可指定多个,用分隔符隔开。


  23. --iterations=N, -i N

  24. 测试执行的迭代次数


  25. --detach=N

  26. 执行N条语句后断开重连


  27. --debug-info, -T

  28. 打印内存和CPU的信息


  29. --only-print

  30. 只打印测试语句而不实际执行


  31. --defaults-file

  32. 配置文件存放位置


  33. --socket=name,-S

  34. 指定socket文件位置

一些实例
  用自动生成的测试数据进行测试,且只打印实际的测试过程。

  1. # /usr/local/webserver/mysql/bin/mysqlslap  -a --only-print

  2. DROP SCHEMA IF EXISTS `mysqlslap`;

  3. CREATE SCHEMA `mysqlslap`;

  4. use mysqlslap;

  5. CREATE TABLE `t1` (intcol1 INT(32) ,charcol1 VARCHAR(128));

  6. INSERT INTO t1 VALUES (1804289383,'mxvtvmC9127qJNm06sGB8R92q2j7vTiiITRDGXM9ZLzkdekbWtmXKwZ2qG1llkRw5m9DHOFilEREk3q7oce8O3BEJC0woJsm6uzFAEynLH2xCsw1KQ1lT4zg9rdxBL');

  7. INSERT INTO t1 VALUES (822890675,'97RGHZ65mNzkSrYT3zWoSbg9cNePQr1bzSk81qDgE4Oanw3rnPfGsBHSbnu1evTdFDe83ro9w4jjteQg4yoo9xHck3WNqzs54W5zEm92ikdRF48B2oz3m8gMBAl11W');

  8. ......

  9. INSERT INTO t1 VALUES (100669,'qnMdipW5KkXdTjGCh2PNzLoeR0527frpQDQ8uw67Ydk1K06uuNHtkxYBxT5w8plb2BbpzhwYBgPNYX9RmICWGkZD6fAESvhMzH3yqzMtXoH4BQNylbK1CmEIPGYlC6');

  10. SELECT intcol1,charcol1 FROM t1;

  11. INSERT INTO t1 VALUES (73673339,'BN3152Gza4GW7atxJKACYwJqDbFynLxqc0kh30YTwgz3FktQ43XTrqJ4PQ25frn7kXhfXD8RuzN1j8Rf3y8ugKy6es3IbqPJM6ylCyD6xS7YcQCfHKZxYNvB7yTahm');

  12. DROP SCHEMA IF EXISTS `mysqlslap`;

分别100和200个并发,执行1000次总查询

  1. $mysqlslap -a --concurrency=50,100 --number-of-queries 1000 --debug-info


  2. # /usr/local/webserver/mysql/bin/mysqlslap  -a --concurrency=100,200 --number-of-queries 1000 --debug-info


  3. Benchmark

  4. Average number of seconds to run all queries: 0.232 seconds

  5. Minimum number of seconds to run all queries: 0.232 seconds

  6. Maximum number of seconds to run all queries: 0.232 seconds

  7. Number of clients running queries: 100

  8. Average number of queries per client: 10


  9. Benchmark

  10. Average number of seconds to run all queries: 0.268 seconds

  11. Minimum number of seconds to run all queries: 0.268 seconds

  12. Maximum number of seconds to run all queries: 0.268 seconds

  13. Number of clients running queries: 200

  14. Average number of queries per client: 5



  15. User time 0.02, System time 0.49

  16. Maximum resident set size 6100, Integral resident set size 0

  17. Non-physical pagefaults 3165, Physical pagefaults 0, Swaps 0

  18. Blocks in 0 out 0, Messages in 0 out 0, Signals 0

  19. Voluntary context switches 3102, Involuntary context switches 7541

分别200和400个并发,执行2000次总查询并迭代8次

  1. # /usr/local/webserver/mysql/bin/mysqlslap -a   --concurrency=200,400 --number-of-queries 2000 --iterations=8  --debug-info


  2. Benchmark

  3. Average number of seconds to run all queries: 0.657 seconds

  4. Minimum number of seconds to run all queries: 0.603 seconds

  5. Maximum number of seconds to run all queries: 0.736 seconds

  6. Number of clients running queries: 200

  7. Average number of queries per client: 10


  8. Benchmark

  9. Average number of seconds to run all queries: 0.711 seconds

  10. Minimum number of seconds to run all queries: 0.648 seconds

  11. Maximum number of seconds to run all queries: 0.860 seconds

  12. Number of clients running queries: 400

  13. Average number of queries per client: 5



  14. User time 0.58, System time 9.12

  15. Maximum resident set size 30764, Integral resident set size 0

  16. Non-physical pagefaults 92471, Physical pagefaults 0, Swaps 0

  17. Blocks in 0 out 0, Messages in 0 out 0, Signals 0

  18. Voluntary context switches 99629, Involuntary context switches 157741

同时测试不同的存储引擎

  1. # /usr/local/webserver/mysql/bin/mysqlslap -a   --concurrency=200,400 --number-of-queries 2000 --iterations=8  --engine=myisam,innodb  --debug-info


  2. Benchmark

  3. Average number of seconds to run all queries: 0.740 seconds

  4. Minimum number of seconds to run all queries: 0.678 seconds

  5. Maximum number of seconds to run all queries: 0.827 seconds

  6. Number of clients running queries: 200

  7. Average number of queries per client: 10


  8. Benchmark

  9. Average number of seconds to run all queries: 0.696 seconds

  10. Minimum number of seconds to run all queries: 0.661 seconds

  11. Maximum number of seconds to run all queries: 0.775 seconds

  12. Number of clients running queries: 400

  13. Average number of queries per client: 5



  14. User time 0.62, System time 9.27

  15. Maximum resident set size 33368, Integral resident set size 0

  16. Non-physical pagefaults 89594, Physical pagefaults 0, Swaps 0

  17. Blocks in 0 out 0, Messages in 0 out 0, Signals 0

  18. Voluntary context switches 98328, Involuntary context switches 153787

指定数据库的测试

  1. # /usr/local/webserver/mysql/bin/mysqlslap  --concurrency=500 --iterations=8 --create-schema=test --query=/root/test.sql


  2. Benchmark

  3. Average number of seconds to run all queries: 0.343 seconds

  4. Minimum number of seconds to run all queries: 0.283 seconds

  5. Maximum number of seconds to run all queries: 0.525 seconds

  6. Number of clients running queries: 500

  7. Average number of queries per client: 1

转自:http://www.mike.org.cn/articles/mysql-stress-tests-conducted-by-mysqlslap/


你可能感兴趣的:(mysqlslap)