主页 > 运维运营 > Mysql >
发布时间:2015-06-25 作者:网络 阅读:147次

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

  1. --auto-generate-sql, -a
  2. 自动生成测试表和数据
  3.  
  4. --auto-generate-sql-load-type=type
  5. 测试语句的类型。取值包括:read,key,write,update和mixed(默认)。
  6.  
  7. --number-char-cols=N, -x N
  8. 自动生成的测试表中包含多少个字符类型的列,默认1
  9.  
  10. --number-int-cols=N, -y N
  11. 自动生成的测试表中包含多少个数字类型的列,默认1
  12.  
  13. --number-of-queries=N
  14. 总的测试查询次数(并发客户数×每客户查询次数)
  15.  
  16. --query=name,-q
  17. 使用自定义脚本执行测试,例如可以调用自定义的一个存储过程或者sql语句来执行测试。
  18.  
  19. --create-schema
  20. 测试的schema,MySQL中schema也就是database
  21.  
  22. --commint=N
  23. 多少条DML后提交一次
  24.  
  25. --compress, -C
  26. 如果服务器和客户端支持都压缩,则压缩信息传递
  27.  
  28. --concurrency=N, -c N
  29. 并发量,也就是模拟多少个客户端同时执行select。可指定多个值,以逗号或者–delimiter参数指定的值做为分隔符
  30.  
  31. --engine=engine_name, -e engine_name
  32. 创建测试表所使用的存储引擎,可指定多个,用分隔符隔开。
  33.  
  34. --iterations=N, -i N
  35. 测试执行的迭代次数
  36.  
  37. --detach=N
  38. 执行N条语句后断开重连
  39.  
  40. --debug-info, -T
  41. 打印内存和CPU的信息
  42.  
  43. --only-print
  44. 只打印测试语句而不实际执行
  45.  
  46. --defaults-file
  47. 配置文件存放位置
  48.  
  49. --socket=name,-S
  50. 指定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.  
  3. # /usr/local/webserver/mysql/bin/mysqlslap  -a --concurrency=100,200 --number-of-queries 1000 --debug-info
  4.  
  5. Benchmark
  6. Average number of seconds to run all queries: 0.232 seconds
  7. Minimum number of seconds to run all queries: 0.232 seconds
  8. Maximum number of seconds to run all queries: 0.232 seconds
  9. Number of clients running queries: 100
  10. Average number of queries per client: 10
  11.  
  12. Benchmark
  13. Average number of seconds to run all queries: 0.268 seconds
  14. Minimum number of seconds to run all queries: 0.268 seconds
  15. Maximum number of seconds to run all queries: 0.268 seconds
  16. Number of clients running queries: 200
  17. Average number of queries per client: 5
  18.  
  19.  
  20. User time 0.02, System time 0.49
  21. Maximum resident set size 6100, Integral resident set size 0
  22. Non-physical pagefaults 3165, Physical pagefaults 0, Swaps 0
  23. Blocks in 0 out 0, Messages in 0 out 0, Signals 0
  24. 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.  
  3. Benchmark
  4. Average number of seconds to run all queries: 0.657 seconds
  5. Minimum number of seconds to run all queries: 0.603 seconds
  6. Maximum number of seconds to run all queries: 0.736 seconds
  7. Number of clients running queries: 200
  8. Average number of queries per client: 10
  9.  
  10. Benchmark
  11. Average number of seconds to run all queries: 0.711 seconds
  12. Minimum number of seconds to run all queries: 0.648 seconds
  13. Maximum number of seconds to run all queries: 0.860 seconds
  14. Number of clients running queries: 400
  15. Average number of queries per client: 5
  16.  
  17.  
  18. User time 0.58, System time 9.12
  19. Maximum resident set size 30764, Integral resident set size 0
  20. Non-physical pagefaults 92471, Physical pagefaults 0, Swaps 0
  21. Blocks in 0 out 0, Messages in 0 out 0, Signals 0
  22. 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.  
  3. Benchmark
  4. Average number of seconds to run all queries: 0.740 seconds
  5. Minimum number of seconds to run all queries: 0.678 seconds
  6. Maximum number of seconds to run all queries: 0.827 seconds
  7. Number of clients running queries: 200
  8. Average number of queries per client: 10
  9.  
  10. Benchmark
  11. Average number of seconds to run all queries: 0.696 seconds
  12. Minimum number of seconds to run all queries: 0.661 seconds
  13. Maximum number of seconds to run all queries: 0.775 seconds
  14. Number of clients running queries: 400
  15. Average number of queries per client: 5
  16.  
  17.  
  18. User time 0.62, System time 9.27
  19. Maximum resident set size 33368, Integral resident set size 0
  20. Non-physical pagefaults 89594, Physical pagefaults 0, Swaps 0
  21. Blocks in 0 out 0, Messages in 0 out 0, Signals 0
  22. 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.  
  3. Benchmark
  4. Average number of seconds to run all queries: 0.343 seconds
  5. Minimum number of seconds to run all queries: 0.283 seconds
  6. Maximum number of seconds to run all queries: 0.525 seconds
  7. Number of clients running queries: 500
  8. Average number of queries per client: 1

关键字词: