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. 使用cmd查看Tensorboard的生成图

    代码中"graph_practice7/"文件存放的是生成的神经网络图 现在要查看这个图,使用cmd 进入文件指定目录(我的文件存储地址是E:\workspace\PycharmP ...

  2. Asp.Net MVC中Controller、Action、View是如何激活调用的

    上篇我们介绍了MVC的路由,知道在注册路由的时候会创建一个MvcHandler将其和Url规则一起放入到了RouteCollection中,之后请求通过UrlRoutingModule,根据当前的UR ...

  3. Stack in c#

    public static void SaveStack() { string result = "Hello World"; Stack st = new Stack(); fo ...

  4. 学习React从接受JSX开始

    详情参考官方JSX规范 虽然JSX是扩展到ECMAScript的类XML语法,但是它本身并没有定义任何语义.也就是说它本身不在ECMAScript标准范围之内.它也不会被引擎或者浏览器直接执行.通常会 ...

  5. jmeter 性能插件

    mv jmeter-plugins-manager-0.16.jar /usr/local/Cellar/jmeter/3.1/libexec/lib/ext http://www.cnblogs.c ...

  6. 使用js生成条形码以及二维码

    一.用js生成条形码这种业务场景不是很常见的,最近刚好又接到这种需求 Google一下,发现github还真有这方面的轮子,感谢github,省去了我们很多造轮子的过程, 好了言归正传,首先引入jsb ...

  7. Far Relative’s Problem (贪心 计算来的最多客人)

    Description Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n  ...

  8. 集训第五周动态规划 J题 括号匹配

    Description We give the following inductive definition of a “regular brackets” sequence: the empty s ...

  9. I - DFS(依然是漫水填充)

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

  10. java-得到字符串中出现次数最最多的字符,并打印出字符以及出现次数

    最近面试总被面试到,整理出几种方式(有参考别人的部分) /** * java一个字符串中出现次数最多的字符以及次数 * @param args */ public static void main(S ...