官方压测工具mysqlslap介绍及使用

发布时间:2020-08-09 14:02:08 作者:kunlunzhiying
来源:ITPUB博客 阅读:184
mysqlslap是官方的一款做压力测试的工具,可以模拟多个客户端进行并发测试。
比如可以模拟多少并发,执行多少次,针对某个存储引擎……等等


比如对myisam引擎做并发量为100,查询次数为1000
--concurrency用于指定并发量,--number-of-queries=1000用于指定查询次数,--engine用于指定存储引擎
-a则是自动生成SQL(当未提供file或command时)
  1. [op@sAno1y ~]$ mysqlslap -a --concurrency=100 --number-of-queries=1000 --engine=myisam -uroot -proot
  2. Warning: Using a password on the command line interface can be insecure.
  3. Benchmark
  4. Running for engine myisam
  5. Average number of seconds to run all queries: 0.167 seconds
  6. Minimum number of seconds to run all queries: 0.167 seconds
  7. Maximum number of seconds to run all queries: 0.167 seconds
  8. Number of clients running queries: 100
  9. Average number of queries per client: 10
  10. Benchmark
  11. Running for engine myisam
  12. Average number of seconds to run all queries: 0.170 seconds
  13. Minimum number of seconds to run all queries: 0.170 seconds
  14. Maximum number of seconds to run all queries: 0.170 seconds
  15. Number of clients running queries: 200
  16. Average number of queries per client: 5

当然可以做迭代,在一次测试中输出:
其中--concurrency可以写作--concurrency=128,256,512诸如此类,而--engine也可以迭代写作--engine=innodb,myisam,memory等。
比如:
多加了的--debug-info参数可以使测试结果变得更加详尽。
  1. [op@sAno1y ~]$ mysqlslap -a --concurrency=100,200 --iterations=1 --number-of-queries=1000 --engine=myisam,innodb,memory --debug-info -uroot -proot
  2. Warning: Using a password on the command line interface can be insecure.
  3. Benchmark
  4. Running for engine myisam
  5. Average number of seconds to run all queries: 0.160 seconds
  6. Minimum number of seconds to run all queries: 0.160 seconds
  7. Maximum number of seconds to run all queries: 0.160 seconds
  8. Number of clients running queries: 100
  9. Average number of queries per client: 10
  10. Benchmark
  11. Running for engine myisam
  12. Average number of seconds to run all queries: 0.164 seconds
  13. Minimum number of seconds to run all queries: 0.164 seconds
  14. Maximum number of seconds to run all queries: 0.164 seconds
  15. Number of clients running queries: 200
  16. Average number of queries per client: 5
  17. Benchmark
  18. Running for engine innodb
  19. Average number of seconds to run all queries: 0.787 seconds
  20. Minimum number of seconds to run all queries: 0.787 seconds
  21. Maximum number of seconds to run all queries: 0.787 seconds
  22. Number of clients running queries: 100
  23. Average number of queries per client: 10
  24. Benchmark
  25. Running for engine innodb
  26. Average number of seconds to run all queries: 1.154 seconds
  27. Minimum number of seconds to run all queries: 1.154 seconds
  28. Maximum number of seconds to run all queries: 1.154 seconds
  29. Number of clients running queries: 200
  30. Average number of queries per client: 5
  31. Benchmark
  32. Running for engine memory
  33. Average number of seconds to run all queries: 0.140 seconds
  34. Minimum number of seconds to run all queries: 0.140 seconds
  35. Maximum number of seconds to run all queries: 0.140 seconds
  36. Number of clients running queries: 100
  37. Average number of queries per client: 10
  38. Benchmark
  39. Running for engine memory
  40. Average number of seconds to run all queries: 0.159 seconds
  41. Minimum number of seconds to run all queries: 0.159 seconds
  42. Maximum number of seconds to run all queries: 0.159 seconds
  43. Number of clients running queries: 200
  44. Average number of queries per client: 5
  45. User time 0.23, System time 0.25
  46. Maximum resident set size 12788, Integral resident set size 0
  47. Non-physical pagefaults 11916, Physical pagefaults 0, Swaps 0
  48. Blocks in 0 out 0, Messages in 0 out 0, Signals 0
  49. Voluntary context switches 25055, Involuntary context switches 99
其中Average number of queries per client = number-of-queries / concurrency 
即平均一个client的查询 = 总查询 ÷ 并发

另外--auto-general-sql-load-type这个参数也可以选填,默认为mixed。
其他可选项为:update、write、key、read。

附录:
mysqlslap option:

  1. mysqlslap Ver 1.0 Distrib 5.6.26, for Linux (x86_64)
  2. Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
  3. Oracle is a registered trademark of Oracle Corporation and/or its
  4. affiliates. Other names may be trademarks of their respective
  5. owners.
  6. Run a query multiple times against the server.
  7. Usage: mysqlslap [OPTIONS]
  8. Default options are read from the following files in the given order:
  9. /etc/my.cnf /etc/mysql/my.cnf /home/op/softwares/mysql/etc/my.cnf ~/.my.cnf
  10. The following groups are read: mysqlslap client
  11. The following options may be given as the first argument:
  12. --print-defaults Print the program argument list and exit.
  13. --no-defaults Don't read default options from any option file,
  14. except for login file.
  15. --defaults-file=# Only read default options from the given file #.
  16. --defaults-extra-file=# Read this file after the global files are read.
  17. --defaults-group-suffix=#
  18. Also read groups with concat(group, suffix)
  19. --login-path=# Read this path from the login file.
  20. -?, --help Display this help and exit.
  21. -a, --auto-generate-sql
  22. Generate SQL where not supplied by file or command line.
  23. --auto-generate-sql-add-autoincrement
  24. Add an AUTO_INCREMENT column to auto-generated tables.
  25. --auto-generate-sql-execute-number=#
  26. Set this number to generate a set number of queries to
  27. run.
  28. --auto-generate-sql-guid-primary
  29. Add GUID based primary keys to auto-generated tables.
  30. --auto-generate-sql-load-type=name
  31. Specify test load type: mixed, update, write, key, or
  32. read; default is mixed.
  33. --auto-generate-sql-secondary-indexes=#
  34. Number of secondary indexes to add to auto-generated
  35. tables.
  36. --auto-generate-sql-unique-query-number=#
  37. Number of unique queries to generate for automatic tests.
  38. --auto-generate-sql-unique-write-number=#
  39. Number of unique queries to generate for
  40. auto-generate-sql-write-number.
  41. --auto-generate-sql-write-number=#
  42. Number of row inserts to perform for each thread (default
  43. is 100).
  44. --commit=# Commit records every X number of statements.
  45. -C, --compress Use compression in server/client protocol.
  46. -c, --concurrency=name
  47. Number of clients to simulate for query to run.
  48. --create=name File or string to use create tables.
  49. --create-schema=name
  50. Schema to run tests in.
  51. --csv[=name] Generate CSV output to named file or to stdout if no file
  52. is named.
  53. -#, --debug[=#] This is a non-debug version. Catch this and exit.
  54. --debug-check Check memory and open file usage at exit.
  55. -T, --debug-info Print some debug info at exit.
  56. --default-auth=name Default authentication client-side plugin to use.
  57. -F, --delimiter=name
  58. Delimiter to use in SQL statements supplied in file or
  59. command line.
  60. --detach=# Detach (close and reopen) connections after X number of
  61. requests.
  62. --enable-cleartext-plugin
  63. Enable/disable the clear text authentication plugin.
  64. -e, --engine=name Storage engine to use for creating the table.
  65. -h, --host=name Connect to host.
  66. -i, --iterations=# Number of times to run the tests.
  67. --no-drop Do not drop the schema after the test.
  68. -x, --number-char-cols=name
  69. Number of VARCHAR columns to create in table if
  70. specifying --auto-generate-sql.
  71. -y, --number-int-cols=name
  72. Number of INT columns to create in table if specifying
  73. --auto-generate-sql.
  74. --number-of-queries=#
  75. Limit each client to this number of queries (this is not
  76. exact).
  77. --only-print Do not connect to the databases, but instead print out
  78. what would have been done.
  79. -p, --password[=name]
  80. Password to use when connecting to server. If password is
  81. not given it's asked from the tty.
  82. --plugin-dir=name Directory for client-side plugins.
  83. -P, --port=# Port number to use for connection.
  84. --post-query=name Query to run or file containing query to execute after
  85. tests have completed.
  86. --post-system=name system() string to execute after tests have completed.
  87. --pre-query=name Query to run or file containing query to execute before
  88. running tests.
  89. --pre-system=name system() string to execute before running tests.
  90. --protocol=name The protocol to use for connection (tcp, socket, pipe,
  91. memory).
  92. -q, --query=name Query to run or file containing query to run.
  93. --secure-auth Refuse client connecting to server if it uses old
  94. (pre-4.1.1) protocol.
  95. (Defaults to on; use --skip-secure-auth to disable.)
  96. -s, --silent Run program in silent mode - no output.
  97. -S, --socket=name The socket file to use for connection.
  98. --ssl Enable SSL for connection (automatically enabled with
  99. other flags).
  100. --ssl-ca=name CA file in PEM format (check OpenSSL docs, implies
  101. --ssl).
  102. --ssl-capath=name CA directory (check OpenSSL docs, implies --ssl).
  103. --ssl-cert=name X509 cert in PEM format (implies --ssl).
  104. --ssl-cipher=name SSL cipher to use (implies --ssl).
  105. --ssl-key=name X509 key in PEM format (implies --ssl).
  106. --ssl-crl=name Certificate revocation list (implies --ssl).
  107. --ssl-crlpath=name Certificate revocation list path (implies --ssl).
  108. --ssl-verify-server-cert
  109. Verify server's "Common Name" in its cert against
  110. hostname used when connecting. This option is disabled by
  111. default.
  112. -u, --user=name User for login if not current user.
  113. -v, --verbose More verbose output; you can use this multiple times to
  114. get even more verbose output.
  115. -V, --version Output version information and exit.



mysqlslap的缺点还是挺明显的,比如,不可以设置持续时间,比如24小时,表的数目不能指定等。
其最明显的优点是可以对不同的存储引擎做出对比。

作者公众号(持续更新)
官方压测工具mysqlslap介绍及使用
推荐阅读:
  1. mysql中自带压力测试工具mysqlslap介绍
  2. cassandra-stress 压测使用介绍

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mysqlslap 介绍 使用

上一篇:Python爬虫学习教程:天猫商品数据爬虫

下一篇:Mysql 5.7 Gtid内部学习(四) mysql.gtid_executed表Previous gtid Event的改变

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》