MySQL Study之--MySQL压力測试工具mysqlslap
一、Mysqlslap介绍
    mysqlslap是MySQL5.1之后自带的benchmark基准測试工具,类似Apache Bench负载产生工具。生成schema。装载数据,运行benckmark和查询数据。语法简单,灵活。easy使用。该工具可以模拟多个client同一时候并发的向server发出查询更新,给出了性能測试数据并且提供了多种引擎的性能比較。mysqlslap为mysql性能优化前后提供了直观的验证根据。笔者建议系统运维人员应该掌握一些常见的压力測试工具,这样才干较为准确的掌握线上系统可以支撑的用户流量上限及其抗压性等问题。

www.2cto.com

二、用法介绍
能够使用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 代表总共要执行多少次查询。每一个client执行的查询数量能够用查询总数/并发数来计算。
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语句是什么,能够用这个选项。

二、案例分析
[root@mysrv ~]# mysqlslap -V
mysqlslap Ver 1.0 Distrib 5.1.66, for redhat-linux-gnu (x86_64)
[root@mysrv ~]# mysqlslap --help
mysqlslap Ver 1.0 Distrib 5.1.66, for redhat-linux-gnu (x86_64)
Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Run a query multiple times against the server.
Usage: mysqlslap [OPTIONS]
Default options are read from the following files in the given order:
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf
The following groups are read: mysqlslap client
The following options may be given as the first argument:
--print-defaults Print the program argument list and exit.
--no-defaults Don't read default options from any option file.
--defaults-file=# Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.
-? , --help Display this help and exit.
-a, --auto-generate-sql
Generate SQL where not supplied by file or command line.
--auto-generate-sql-add-autoincrement
Add an AUTO_INCREMENT column to auto-generated tables.
--auto-generate-sql-execute-number=#
Set this number to generate a set number of queries to
run.
--auto-generate-sql-guid-primary
Add GUID based primary keys to auto-generated tables.
--auto-generate-sql-load-type=name
Specify test load type: mixed, update, write, key, or
read; default is mixed.
--auto-generate-sql-secondary-indexes=#
Number of secondary indexes to add to auto-generated
tables.
--auto-generate-sql-unique-query-number=#
Number of unique queries to generate for automatic tests.
--auto-generate-sql-unique-write-number=#
Number of unique queries to generate for
auto-generate-sql-write-number.
--auto-generate-sql-write-number=#
Number of row inserts to perform for each thread (default
is 100).
--commit=# Commit records every X number of statements.
-C, --compress Use compression in server/client protocol.
-c, --concurrency=name
Number of clients to simulate for query to run.
--create=name File or string to use create tables.
--create-schema=name
Schema to run tests in.
--csv[=name] Generate CSV output to named file or to stdout if no file
is named.
-#, --debug[=#] This is a non-debug version. Catch this and exit.
--debug-check Check memory and open file usage at exit.
-T, --debug-info Print some debug info at exit.
-F, --delimiter=name
Delimiter to use in SQL statements supplied in file or
command line.
--detach=# Detach (close and reopen) connections after X number of
requests.
-e, --engine=name Storage engine to use for creating the table.
-h, --host=name Connect to host.
-i, --iterations=# Number of times to run the tests.
--no-drop Do not drop the schema after the test.
-x, --number-char-cols=name
Number of VARCHAR columns to create in table if
specifying --auto-generate-sql.
-y, --number-int-cols=name
Number of INT columns to create in table if specifying
--auto-generate-sql.
--number-of-queries=#
Limit each client to this number of queries (this is not
exact).
--only-print Do not connect to the databases, but instead print out
what would have been done.
-p, --password[=name]
Password to use when connecting to server. If password is
not given it's asked from the tty.
-P, --port=# Port number to use for connection.
--post-query=name Query to run or file containing query to execute after
tests have completed.
--post-system=name system() string to execute after tests have completed.
--pre-query=name Query to run or file containing query to execute before
running tests.
--pre-system=name system() string to execute before running tests.
--protocol=name The protocol to use for connection (tcp, socket, pipe,
memory).
-q, --query=name Query to run or file containing query to run.
-s, --silent Run program in silent mode - no output.
-S, --socket=name The socket file to use for connection.
--ssl Enable SSL for connection (automatically enabled with
other flags).Disable with --skip-ssl.
--ssl-ca=name CA file in PEM format (check OpenSSL docs, implies
--ssl).
--ssl-capath=name CA directory (check OpenSSL docs, implies --ssl).
--ssl-cert=name X509 cert in PEM format (implies --ssl).
--ssl-cipher=name SSL cipher to use (implies --ssl).
--ssl-key=name X509 key in PEM format (implies --ssl).
--ssl-verify-server-cert
Verify server's "Common Name" in its cert against
hostname used when connecting. This option is disabled by
default.
-u, --user=name User for login if not current user.
-v, --verbose More verbose output; you can use this multiple times to
get even more verbose output.
-V, --version Output version information and exit.

案例一:

[root@mysrv ~]#  mysqlslap -uroot -poracle --concurrency=100 --iterations=1 --auto-generate-sql --auto-generate-sql-load-type=mixed --auto-generate-sql-add-autoincrement --engine=myisam --number-of-queries=10 --debug-info</span></strong>

測试信息:

Benchmark

        Running for engine myisam

        Average number of seconds to run all queries: 0.473 seconds

        Minimum number of seconds to run all queries: 0.473 seconds

        Maximum number of seconds to run all queries: 0.473 seconds

        Number of clients running queries: 100

        Average number of queries per client: 0

User time 0.04, System time 0.14

Maximum resident set size 6732, Integral resident set size 0

Non-physical pagefaults 1333, Physical pagefaults 0, Swaps 0

Blocks in 0 out 0, Messages in 0 out 0, Signals 0

Voluntary context switches 2389, Involuntary context switches 48

备注:本次測试以100个并发线程、測试1次。自己主动生成SQL測试脚本、读、写、更新混合測试、自增长字段、測试引擎为myisam、共执行10次查询。输出cpu资源信息

案例二:
[root@mysrv ~]# mysqlslap -h127.0.0.1 -P3306 -u root -poracle --concurrency=100 --iterations=1 --create-schema='prod' --query='select * from t1;' --number-of-queries=10
-e innodb --debug-info 
測试信息:

Benchmark

        Running for engine innodb

        Average number of seconds to run all queries: 1.455 seconds

        Minimum number of seconds to run all queries: 1.455 seconds

        Maximum number of seconds to run all queries: 1.455 seconds

        Number of clients running queries: 100

        Average number of queries per client: 0

User time 0.03, System time 0.12

Maximum resident set size 5420, Integral resident set size 0

Non-physical pagefaults 1273, Physical pagefaults 0, Swaps 0

Blocks in 0 out 0, Messages in 0 out 0, Signals 0

Voluntary context switches 536, Involuntary context switches 151

备注:使用mysqlslap指定sql语句进行測试
案例三:
[root@mysrv ~]# mysqlslap --concurrency=50,100,200 --iterations=20 --number-int-cols=4 --number-char-cols=35 --auto-generate-sql --auto-generate-sql-add-autoincrement --auto-generate-sql-load-type=read
--engine=myisam,innodb --number-of-queries=200 --verbose --socket=/tmp/mysql.sock -uroot -poracle
測试信息:
Benchmark

        Running for engine myisam

        Average number of seconds to run all queries: 1.521 seconds

        Minimum number of seconds to run all queries: 1.397 seconds

        Maximum number of seconds to run all queries: 2.092 seconds

        Number of clients running queries: 50

        Average number of queries per client: 4
Benchmark

        Running for engine myisam

        Average number of seconds to run all queries: 1.465 seconds

        Minimum number of seconds to run all queries: 1.279 seconds

        Maximum number of seconds to run all queries: 1.996 seconds

        Number of clients running queries: 100

        Average number of queries per client: 2

Benchmark

        Running for engine myisam

        Average number of seconds to run all queries: 1.367 seconds

        Minimum number of seconds to run all queries: 1.260 seconds

        Maximum number of seconds to run all queries: 1.576 seconds

        Number of clients running queries: 200

        Average number of queries per client: 1
Benchmark

        Running for engine innodb

        Average number of seconds to run all queries: 1.198 seconds

        Minimum number of seconds to run all queries: 1.084 seconds

        Maximum number of seconds to run all queries: 1.301 seconds

        Number of clients running queries: 50

        Average number of queries per client: 4
Benchmark

        Running for engine innodb

        Average number of seconds to run all queries: 1.423 seconds

        Minimum number of seconds to run all queries: 1.238 seconds

        Maximum number of seconds to run all queries: 1.761 seconds

        Number of clients running queries: 100

        Average number of queries per client: 2

Benchmark

        Running for engine innodb

        Average number of seconds to run all queries: 1.389 seconds

        Minimum number of seconds to run all queries: 1.268 seconds

        Maximum number of seconds to run all queries: 1.653 seconds

        Number of clients running queries: 200

        Average number of queries per client: 1

备注:

   #系统脚本測试,添加int型 4列char 型35列,測试2种引擎myisam,innodb读的性能。分别用50,100。200个client对server进行測试总共200个查询语句 运行20次查询

MySQL Study之--MySQL压力測试工具mysqlslap的更多相关文章

  1. php性能优化(一)压力測试工具篇

    ab使用 Apache附带的压力測试工具ab,很easy使用,而且全然能够摸你各种条件对Webserver发起測试请求.ab能够直接在Webserver本地发起測试请求.这对于须要了解server的处 ...

  2. ubuntu 14.04 LTS 安装webbentch压力測试工具

    近期在做 压力測试工具,除了apache的ab測试工具外,发现webbentch工具也不错,这里简介下这两个工具. 一.webbentch安装: wget http://blog.s135.com/s ...

  3. webbench压力測试工具

    apache的測试工具ab 在并发100个以上后会出现错误.网上也有非常多改ab源代码来解禁的. 只是还是推荐一款比較好用的压力測试工具webbench wget http://blog.zyan.c ...

  4. CentOS6.5 64位站点压力測试工具webbench

    在Apache中有自带的ab命令能够測试服务的压力,而nginx没有自带的命令,必需要採用第三方软件来測试.今天就简介一下webbench对nginx的压力測试,压力測试是对系统管理员和运维人员必须的 ...

  5. 学习使用Jmeter做压力測试(一)--压力測试基本概念

    一.性能測试的概念         性能測试是通过自己主动化的測试工具模拟多种正常峰值及异常负载条件来对系统的各项性能指标进行測试.负载測试和压力測试都属于性能測试,两者能够结合进行. 通过负载測试, ...

  6. Android开发之按键、触摸屏和手势输入专业压力測试方法

    按键输入.触摸屏输入和手势笔画输入等功能是Android开发的基本功能.其稳定性和健壮性对移动应用系统开发很重要.按键.触摸屏和手势输入专业压力測试方法能够使用Monkey,相应用程序进行压力測试,检 ...

  7. MySQL Study之--MySQL下图形工具的使用(MySQL Administrator)

    MySQL Study之--MySQL下图形工具的使用(MySQL Administrator) 系统环境:     操作系统: Windows  7(64) 下载地址:http://www.soft ...

  8. 移动測试技术保护源码!解码全球首款移动端白盒測试工具ThreadingTest (文章转自己主动点科技)

    作者 智晓锋 - 2014/07/14 自从斯诺登曝光美监听丑闻事件之后,我国政府就将信息安全问题上升到了国家安全的高度.基于此.国内的一家创业公司推出了智能型Android真机白盒測试以及开发辅助类 ...

  9. 站点系统压力測试Jmeter+Badboy

    近期项目须要压力測试,因此搜了几款试用,首选的是LoadRunner这款大名鼎鼎的測试软件: LoadRunner11 下载请猛戳这里 传送门LoadRunner破解文件 下载请猛戳这里 传送门Loa ...

随机推荐

  1. 从mysql全库备份中恢复指定库和指定表

    需求:开发要求导入某天某个表的数据,而我们的数据是全库备份 例如:  从newbei_2017-08-31_402793782.tar.bz2中恢复表:bei_table 的数据 一.备份策略 备份全 ...

  2. PHP 数组使用之道

    本文首发于 PHP 数组使用之道,转载请注明出处. 这个教程我将通过一些实用的实例和最佳实践的方式列举出 PHP 中常用的数组函数.每个 PHP 工程师都应该掌握它们的使用方法,以及如何通过组合使用来 ...

  3. 集训第六周 数学概念与方法 J题 数论,质因数分解

    Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all g ...

  4. 集训第四周(高效算法设计)J题 (中途相遇法)

    Description   The SUM problem can be formulated as follows: given four lists A, B, C, D<tex2html_ ...

  5. prometheus监控mysql

    创建一个用于mysqld_exporter连接到MySQL的用户并赋予所需的权限 mysql> GRANT REPLICATION CLIENT, PROCESS ON *.* TO '; my ...

  6. Leetcode 166.分数到小数

    分数到小数 给定两个整数,分别表示分数的分子 numerator 和分母 denominator,以字符串形式返回小数. 如果小数部分为循环小数,则将循环的部分括在括号内. 示例 1: 输入: num ...

  7. POJ-2594 Treasure Exploration floyd传递闭包+最小路径覆盖,nice!

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8130   Accepted: 3 ...

  8. expdp,impdp,include,exclude

    The examples below are based on:- the demo schema SCOTT that is created with script: $ORACLE_HOME/rd ...

  9. oracle基于归档的增量异地恢复 --异地新增数据文件问题

    1 rac异地基于归档文件的增量恢复   2 遇到在主库新增数据文件 后 日志恢复出现路径问题 .   错误如下 : creating datafile fno=20 name=+DATA/dataf ...

  10. [BZOJ2462] [BeiJing2011]矩阵模板(二维Hash)

    传送门 二维哈希即可. 注意质数选的大一些,不然会超时. 还有插入的时候不判重居然比判重要快.. ——代码 #include <cstdio> int main() { ; ") ...