天天看点

【原创】mysqlslap 使用总结

      mysqlslap 可以用于模拟服务器的负载,并输出计时信息。其被包含在 mysql 5.1 的发行包中。测试时,可以指定并发连接数,可以指定 sql 语句。如果没有指定 sql 语句,mysqlslap 会自动生成查询 schema 的 select 语句。 

1. 查看帮助信息。 

<a href="http://my.oschina.net/moooofly/blog/152547#">?</a>

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

<code>[root@betty libmysql]</code><code># mysqlslap --help</code>

<code>mysqlslap  ver 1.0 distrib 5.6.10,</code><code>for</code> <code>linux (x86_64)</code>

<code>copyright (c) 2005, 2013, oracle and</code><code>/or</code> <code>its affiliates. all rights reserved.</code>

<code>oracle is a registered trademark of oracle corporation and</code><code>/or</code> <code>its</code>

<code>affiliates. other names may be trademarks of their respective</code>

<code>owners.</code>

<code>run a query multiple</code><code>times</code> <code>against the server.</code>

<code>usage: mysqlslap [options]</code>

<code>default options are</code><code>read</code> <code>from the following files</code><code>in</code> <code>the given order:</code>

<code>/etc/my</code><code>.cnf</code><code>/etc/mysql/my</code><code>.cnf</code><code>/usr/local/mysql/etc/my</code><code>.cnf ~/.my.cnf</code>

<code>the following</code><code>groups</code> <code>are</code><code>read</code><code>: mysqlslap client</code>

<code>the following options may be given as the first argument:</code>

<code>--print-defaults        print the program argument list and</code><code>exit</code><code>.</code>

<code>--no-defaults           don't</code><code>read</code> <code>default options from any option</code><code>file</code><code>,</code>

<code>                        </code><code>except</code><code>for</code> <code>login</code><code>file</code><code>.</code>

<code>--defaults-</code><code>file</code><code>=</code><code>#       only read default options from the given file #.</code>

<code>--defaults-extra-</code><code>file</code><code>=</code><code># read this file after the global files are read.</code>

<code>--defaults-group-suffix=</code><code>#</code>

<code>                        </code><code>also</code><code>read</code> <code>groups</code> <code>with concat(group, suffix)</code>

<code>--login-path=</code><code>#          read this path from the login file.</code>

<code>  </code><code>-?, --help          display this help and</code><code>exit</code><code>.</code>

<code>  </code><code>-a, --auto-generate-sql 自动生成测试表和数据</code>

<code>                      </code><code>generate sql where not supplied by</code><code>file</code> <code>or</code><code>command</code> <code>line.</code>

<code>  </code><code>--auto-generate-sql-add-autoincrement 增加auto_increment一列</code>

<code>                      </code><code>add an auto_increment column to auto-generated tables.</code>

<code>  </code><code>--auto-generate-sql-execute-number=</code><code># 自动生成的查询的个数</code>

<code>                      </code><code>set this number to generate a</code><code>set</code> <code>number of queries to</code>

<code>                      </code><code>run.</code>

<code>  </code><code>--auto-generate-sql-guid-primary 增加基于guid的主键</code>

<code>                      </code><code>add guid based primary keys to auto-generated tables.</code>

<code>  </code><code>--auto-generate-sql-load-</code><code>type</code><code>=name 测试语句的类型。取值包括:</code><code>read</code><code>,key,write,update和mixed(默认)</code>

<code>                      </code><code>read</code><code>:查询 write:插入 key:读主键 update:更新主键 mixed:一半插入一半查询</code>

<code>                      </code><code>specify</code><code>test</code> <code>load</code><code>type</code><code>: mixed, update, write, key, or</code>

<code>                      </code><code>read</code><code>; default is mixed.</code>

<code>  </code><code>--auto-generate-sql-secondary-indexes=</code><code># 增加二级索引的个数,默认是0</code>

<code>                      </code><code>number of secondary indexes to add to auto-generated</code>

<code>                      </code><code>tables.</code>

<code>  </code><code>--auto-generate-sql-unique-query-number=</code><code># 不同查询的数量,默认值是10</code>

<code>                      </code><code>number of unique queries to generate</code><code>for</code> <code>automatic tests.</code>

<code>  </code><code>--auto-generate-sql-unique-write-number=</code><code># 不同插入的数量,默认是100</code>

<code>                      </code><code>number of unique queries to generate</code><code>for</code>

<code>                      </code><code>auto-generate-sql-write-number.</code>

<code>  </code><code>--auto-generate-sql-write-number=</code><code>#</code>

<code>                      </code><code>number of row inserts to perform</code><code>for</code> <code>each thread (default</code>

<code>                      </code><code>is 100).</code>

<code>  </code><code>--commit=</code><code>#          多少条dml后提交一次</code>

<code>                      </code><code>commit records every x number of statements.</code>

<code>  </code><code>-c, --compress      如果服务器和客户端支持都压缩,则压缩信息传递</code>

<code>                      </code><code>use compression</code><code>in</code> <code>server</code><code>/client</code> <code>protocol.</code>

<code>  </code><code>-c, --concurrency=name 模拟n个客户端并发执行</code><code>select</code><code>。可指定多个值,以逗号或者 --delimiter 参数指定的值做为分隔符</code>

<code>                      </code><code>number of clients to simulate</code><code>for</code> <code>query to run.</code>

<code>  </code><code>--create=name       指定用于创建表的.sql文件或者字串</code>

<code>                      </code><code>file or string to use create tables.</code>

<code>  </code><code>--create-schema=name 指定待测试的数据库名,mysql中schema也就是database,默认是mysqlslap</code>

<code>                      </code><code>schema to run tests</code><code>in</code><code>.</code>

<code>  </code><code>--csv[=name]        generate csv output to named</code><code>file</code> <code>or to stdout</code><code>if</code> <code>no</code><code>file</code>

<code>                      </code><code>is named.</code>

<code>  </code><code>-</code><code>#, --debug[=#]     this is a non-debug version. catch this and exit.</code>

<code>  </code><code>--debug-check       check memory and</code><code>open</code> <code>file</code> <code>usage at</code><code>exit</code><code>.</code>

<code>  </code><code>-t, --debug-info    打印内存和cpu的信息</code>

<code>                      </code><code>print some debug info at</code><code>exit</code><code>.</code>

<code>  </code><code>--default-auth=name default authentication client-side plugin to use.</code>

<code>  </code><code>-f, --delimiter=name 文件中的sql语句使用分割符号</code>

<code>                      </code><code>delimiter to use</code><code>in</code> <code>sql statements supplied</code><code>in</code> <code>file</code> <code>or</code>

<code>                      </code><code>command</code> <code>line.</code>

<code>  </code><code>--detach=</code><code>#          每执行完n个语句,先断开再重新打开连接</code>

<code>                      </code><code>detach (close and reopen) connections after x number of</code>

<code>                      </code><code>requests.</code>

<code>  </code><code>--</code><code>enable</code><code>-cleartext-plugin</code>

<code>                      </code><code>enable</code><code>/disable</code> <code>the</code><code>clear</code> <code>text authentication plugin.</code>

<code>  </code><code>-e, --engine=name   创建测试表所使用的存储引擎,可指定多个</code>

<code>                      </code><code>storage engine to use</code><code>for</code> <code>creating the table.</code>

<code>  </code><code>-h, --host=name     connect to host.</code>

<code>  </code><code>-i, --iterations=</code><code>#  迭代执行的次数</code>

<code>                      </code><code>number of</code><code>times</code> <code>to run the tests.</code>

<code>  </code><code>--no-drop           do not drop the schema after the</code><code>test</code><code>.</code>

<code>  </code><code>-x, --number-char-cols=name 自动生成的测试表中包含多少个字符类型的列,默认1</code>

<code>                      </code><code>number of varchar columns to create</code><code>in</code> <code>table</code><code>if</code>

<code>                      </code><code>specifying --auto-generate-sql.</code>

<code>  </code><code>-y, --number-int-cols=name 自动生成的测试表中包含多少个数字类型的列,默认1</code>

<code>                      </code><code>number of int columns to create</code><code>in</code> <code>table</code><code>if</code> <code>specifying</code>

<code>                      </code><code>--auto-generate-sql.</code>

<code>  </code><code>--number-of-queries=</code><code># 总的测试查询次数(并发客户数×每客户查询次数)</code>

<code>                      </code><code>limit each client to this number of queries (this is not</code>

<code>                      </code><code>exact).</code>

<code>  </code><code>--only-print        只输出模拟执行的结果,不实际执行</code>

<code>                      </code><code>do not connect to the databases, but instead print out</code>

<code>                      </code><code>what would have been</code><code>done</code><code>.</code>

<code>  </code><code>-p, --password[=name]</code>

<code>                      </code><code>password to use when connecting to server. if password is</code>

<code>                      </code><code>not given it's asked from the</code><code>tty</code><code>.</code>

<code>  </code><code>--plugin-</code><code>dir</code><code>=name   directory</code><code>for</code> <code>client-side plugins.</code>

<code>  </code><code>-p, --port=</code><code>#        port number to use for connection.</code>

<code>  </code><code>--post-query=name   测试完成以后执行的sql语句的文件或者字符串 这个过程不影响时间计算</code>

<code>                      </code><code>query to run or</code><code>file</code> <code>containing query to execute after</code>

<code>                      </code><code>tests have completed.</code>

<code>  </code><code>--post-system=name  测试完成以后执行的系统语句 这个过程不影响时间计算</code>

<code>                      </code><code>system() string to execute after tests have completed.</code>

<code>  </code><code>--pre-query=name    测试执行之前执行的sql语句的文件或者字符串 这个过程不影响时间计算</code>

<code>                      </code><code>query to run or</code><code>file</code> <code>containing query to execute before</code>

<code>                      </code><code>running tests.</code>

<code>  </code><code>--pre-system=name   测试执行之前执行的系统语句 这个过程不影响时间计算</code>

<code>                      </code><code>system() string to execute before running tests.</code>

<code>  </code><code>--protocol=name     the protocol to use</code><code>for</code> <code>connection (tcp, socket, pipe,</code>

<code>                      </code><code>memory).</code>

<code>  </code><code>-q, --query=name    指定自定义.sql脚本执行测试。例如可以调用自定义的一个存储过程或者sql语句来执行测试</code>

<code>                      </code><code>query to run or</code><code>file</code> <code>containing query to run.</code>

<code>  </code><code>-s, --silent        不输出</code>

<code>                      </code><code>run program</code><code>in</code> <code>silent mode - no output.</code>

<code>  </code><code>-s, --socket=name   the socket</code><code>file</code> <code>to use</code><code>for</code> <code>connection.</code>

<code>  </code><code>--ssl               enable ssl</code><code>for</code> <code>connection (automatically enabled with</code>

<code>                      </code><code>other flags).</code>

<code>  </code><code>--ssl-ca=name       ca</code><code>file</code> <code>in</code> <code>pem</code><code>format</code> <code>(check openssl docs, implies</code>

<code>                      </code><code>--ssl).</code>

<code>  </code><code>--ssl-capath=name   ca directory (check openssl docs, implies --ssl).</code>

<code>  </code><code>--ssl-cert=name     x509 cert</code><code>in</code> <code>pem</code><code>format</code> <code>(implies --ssl).</code>

<code>  </code><code>--ssl-cipher=name   ssl cipher to use (implies --ssl).</code>

<code>  </code><code>--ssl-key=name      x509 key</code><code>in</code> <code>pem</code><code>format</code> <code>(implies --ssl).</code>

<code>  </code><code>--ssl-crl=name      certificate revocation list (implies --ssl).</code>

<code>  </code><code>--ssl-crlpath=name  certificate revocation list path (implies --ssl).</code>

<code>  </code><code>--ssl-verify-server-cert</code>

<code>                      </code><code>verify server's</code><code>"common name"</code> <code>in</code> <code>its cert against</code>

<code>                      </code><code>hostname</code> <code>used when connecting. this option is disabled by</code>

<code>                      </code><code>default.</code>

<code>  </code><code>-u, --user=name     user</code><code>for</code> <code>login</code><code>if</code> <code>not current user.</code>

<code>  </code><code>-</code><code>v</code><code>, --verbose       输出更多的信息</code>

<code>                      </code><code>more verbose output; you can use this multiple</code><code>times</code> <code>to</code>

<code>                      </code><code>get even</code><code>more</code> <code>verbose output.</code>

<code>  </code><code>-v, --version       output version information and</code><code>exit</code><code>.</code>

<code>[root@betty libmysql]</code><code>#</code>

2. 以自动生成测试表和数据的形式,分别模拟 50 和 100 个客户端并发连接处理 1000 个 query 的情况。 

<code>[root@betty libmysql]</code><code># mysqlslap -a --concurrency=50,100 --number-of-queries=1000            </code>

<code>benchmark</code>

<code>        </code><code>average number of seconds to run all queries: 0.148 seconds</code>

<code>        </code><code>minimum number of seconds to run all queries: 0.148 seconds</code>

<code>        </code><code>maximum number of seconds to run all queries: 0.148 seconds</code>

<code>        </code><code>number of clients running queries: 50</code>

<code>        </code><code>average number of queries per client: 20</code>

<code>        </code><code>average number of seconds to run all queries: 0.246 seconds</code>

<code>        </code><code>minimum number of seconds to run all queries: 0.246 seconds</code>

<code>        </code><code>maximum number of seconds to run all queries: 0.246 seconds</code>

<code>        </code><code>number of clients running queries: 100</code>

<code>        </code><code>average number of queries per client: 10</code>

3.  增加 --debug-info 选项,可以输出内存和cpu信息。 

<code>[root@betty libmysql]</code><code># mysqlslap -a --concurrency=50,100 --number-of-queries=1000 --debug-info</code>

<code>        </code><code>average number of seconds to run all queries: 0.202 seconds</code>

<code>        </code><code>minimum number of seconds to run all queries: 0.202 seconds</code>

<code>        </code><code>maximum number of seconds to run all queries: 0.202 seconds</code>

<code>        </code><code>average number of seconds to run all queries: 0.193 seconds</code>

<code>        </code><code>minimum number of seconds to run all queries: 0.193 seconds</code>

<code>        </code><code>maximum number of seconds to run all queries: 0.193 seconds</code>

<code>user</code><code>time</code> <code>0.09, system</code><code>time</code> <code>0.05</code>

<code>maximum resident</code><code>set</code> <code>size 7848, integral resident</code><code>set</code> <code>size 0</code>

<code>non-physical pagefaults 4221, physical pagefaults 0, swaps 0</code>

<code>blocks</code><code>in</code> <code>0 out 0, messages</code><code>in</code> <code>0 out 0, signals 0</code>

<code>voluntary context switches 7314, involuntary context switches 1400</code>

4. 增加 --iterations 选项,可以 重复执行 5 次 

<code>[root@betty libmysql]</code><code># mysqlslap -a --concurrency=50,100 --number-of-queries=1000 --iterations=5 --debug-info</code>

<code>        </code><code>average number of seconds to run all queries: 0.168 seconds</code>

<code>        </code><code>minimum number of seconds to run all queries: 0.147 seconds</code>

<code>        </code><code>maximum number of seconds to run all queries: 0.217 seconds</code>

<code>        </code><code>average number of seconds to run all queries: 0.209 seconds</code>

<code>        </code><code>minimum number of seconds to run all queries: 0.156 seconds</code>

<code>        </code><code>maximum number of seconds to run all queries: 0.280 seconds</code>

<code>user</code><code>time</code> <code>0.47, system</code><code>time</code> <code>0.25</code>

<code>maximum resident</code><code>set</code> <code>size 9848, integral resident</code><code>set</code> <code>size 0</code>

<code>non-physical pagefaults 16880, physical pagefaults 0, swaps 0</code>

<code>voluntary context switches 35954, involuntary context switches 6583</code>

5. 可以 针对远程主机上的 mysql 进行测试。 

<code>[root@betty shell]</code><code># mysqlslap -a --concurrency=50,100 --number-of-queries=1000 -h 172.16.81.99 -p 3306 -p</code>

<code>enter password:</code>

<code>        </code><code>average number of seconds to run all queries: 2.009 seconds</code>

<code>        </code><code>minimum number of seconds to run all queries: 2.009 seconds</code>

<code>        </code><code>maximum number of seconds to run all queries: 2.009 seconds</code>

<code>        </code><code>average number of seconds to run all queries: 4.519 seconds</code>

<code>        </code><code>minimum number of seconds to run all queries: 4.519 seconds</code>

<code>        </code><code>maximum number of seconds to run all queries: 4.519 seconds</code>

<code>[root@betty shell]</code><code>#</code>

6. 使用 --only-print 选项,可以查看 mysqlslap 在测试过程中如何执行的 sql 语句。在这种方式下,仅会对数据库进行模拟操作。如下显示的自动产生测试表和数据的情况下,mysqlslap 的执行过程: 创建一个临时的库 mysqlslap ,并在测试结束是会将其删除。 

<code>[root@betty libmysql]</code><code># mysqlslap -a --only-print                                             </code>

<code>drop schema if exists `mysqlslap`;</code>

<code>create schema `mysqlslap`;</code>

<code>use mysqlslap;</code>

<code>create table `t1` (intcol1 int(32) ,charcol1 varchar(128));</code>

<code>insert into t1 values (1804289383,</code><code>'mxvtvmc9127qjnm06sgb8r92q2j7vtiiitrdgxm9zlzkdekbwtmxkwz2qg1llkrw5m9dhofilerek3q7oce8o3bejc0wojsm6uzfaeynlh2xcsw1kq1lt4zg9rdxbl'</code><code>);</code>

<code>insert into t1 values (822890675,</code><code>'97rghz65mnzksryt3zwosbg9cnepqr1bzsk81qdge4oanw3rnpfgsbhsbnu1evtdfde83ro9w4jjteqg4yoo9xhck3wnqzs54w5zem92ikdrf48b2oz3m8gmbal11w'</code><code>);</code>

<code>insert into t1 values (1308044878,</code><code>'50w46i58giekxik0cyzfa8bzbladeg3jhzgfzdoqvqqk0akcic7lcjinyssf9wqin6ldc1vzjlkjxkn5onqoy04mtw1wkscyqpl2jg2eteqoqtlfgcve4ztzwwvgmz'</code><code>);</code>

<code>insert into t1 values (964445884,</code><code>'dph7kd1e6f4mmqk1ioopsoiicod83dd8wu7689k6ohtajd3hts6lygv8x9g0el0k87q8g2exjjz2o3khnijbbejyfrotpo5pnvxgybt9nscbno9aikl9qyhi0x3hl9'</code><code>);</code>

<code>insert into t1 values (1586903190,</code><code>'lwrhuwm4he8leymg66ugyip6anar0bdd7ymuvyqcfqp9ebhkzrsyma4wx6gphljhi53deth9j7ixar90jey5outd1ziajdjtjmad7rmiqyxhfhhab7xr1hkuqe51gg'</code><code>);</code>

<code>insert into t1 values (962033002,</code><code>'rfw4egilwisfxpwoc3njx4frnawgi539kr5exfbupszelm2mhqzemd6znuezzhib8fqyuhqbdrdnd8lxqidcnbaewoblzlpzox5aonlqfzpk7qjxclp0wbwiriygjl'</code><code>);</code>

<code>insert into t1 values (1910858270,</code><code>'ksnug3yyannwwdejirkifc4a3e6kyj2i3hsjksiuflhlrxw9yhjdtnfoqd0oouyrcibcb9zqwg4pf0ytzhait67nj7by21fwjqawrzxeh13kt2hrbgl4msrxsulmvd'</code><code>);</code>

<code>insert into t1 values (63299708,</code><code>'fjid3gahprc2l6jgirpm5aw3ugggcloj5ww0enhsilwvs5baxto23axxr6txr9qofeoatxwcjsxnxzxmsdhvoekfc5mses8tyxvsupk5hjs7ihtajalz5xeh2s1gca'</code><code>);</code>

<code>insert into t1 values (737703662,</code><code>'2zxutf6roqjxyhhzsrkrwahwcpxtdhnxykqiro9sekff1yetgqw40ta5u6qnfpvc1dwttxdkfsfhtte9bbdswgzjmryhgllhqjakef4mkjft49excjzznog1f6bnsy'</code><code>);</code>

<code>insert into t1 values (1348361729,</code><code>'i8x2enycnh7sdhmltxciltqe0zpopq9zyg24j0hiagqnpg8jedtrwk5wtxialr9b03fj4ou6tctatwtn7fetzbzkiamvtv6lrezn2rtnfmaokjfjytcp54zfejbb7z'</code><code>);</code>

<code>insert into t1 values (100669,</code><code>'qnmdipw5kkxdtjgch2pnzloer0527frpqdq8uw67ydk1k06uunhtkxybxt5w8plb2bbpzhwybgpnyx9rmicwgkzd6faesvhmzh3yqzmtxoh4bqnylbk1cmeipgylc6'</code><code>);</code>

<code>select intcol1,charcol1 from t1;</code>

<code>insert into t1 values (73673339,</code><code>'bn3152gza4gw7atxjkacywjqdbfynlxqc0kh30ytwgz3fktq43xtrqj4pq25frn7kxhfxd8ruzn1j8rf3y8ugky6es3ibqpjm6ylcyd6xs7ycqcfhkzxynvb7ytahm'</code><code>);</code>

<code>insert into t1 values (1759592334,</code><code>'3lkoxjtvglu5xkhstttjuge5f5qqmccppctmvfzscrzqgim93gsxwb24gkmipezeqstmjqicu7wapgbkw4ilxch3xrlmhkszgldoovsi2qgj6rkvnuyawddjgazdu2'</code><code>);</code>

<code>insert into t1 values (95275444,</code><code>'bnirbdbl81tjzdvuopqrcxgx37xgtzlkexbice3k7xk7aftqxc99jqynptvik83bf6lgdgskd4r3klmhpni8tqnikj1gjw7n2sxfzns2svyg8cpzn7atxl39w4igsp'</code><code>);</code>

<code>insert into t1 values (866596855,</code><code>'naquzhmt1irzijmkblakbnnkkk2scknzi5uhegagqudd5slgpn0smodyc7qorto1qai5qll97qmcizl0mds81x7txpiojyqly0iedrnka1ps0aken5nhumar3kgeim'</code><code>);</code>

<code>insert into t1 values (364531492,</code><code>'qma5suko4m5om7ldvissc6wk9rsg9e8ssixochdgfa5uiintgfxkdj4eawwc2e4nl1bpagwifrcp1zih6f1baypdmwphatwnmzdwgzwnq6srxmcvtd6jrywekdvuwr'</code><code>);</code>

7. 实际测试中的复杂情况。 

使用 --defaults-file 选项,指定从配置文件中读取选项配置。 

使用 --number-int-cols 选项,指定表中会包含 4 个 int 型的列。 

使用 --number-char-cols 选项,指定表中会包含 35 个 char 型的列。 

使用 --engine 选项,指定针对何种存储引擎进行测试。 

<code>[root@betty ~]</code><code># mysqlslap --defaults-file=/etc/my.cnf --concurrency=50,100,200 --iterations=1 --number-int-cols=4 --number-char-cols=35 --auto-generate-sql --auto-generate-sql-add-autoincrement --auto-generate-sql-load-type=mixed --engine=myisam,innodb --number-of-queries=200 --debug-info -s /tmp/mysql.sock</code>

<code>        </code><code>running</code><code>for</code> <code>engine myisam</code>

<code>        </code><code>average number of seconds to run all queries: 0.015 seconds</code>

<code>        </code><code>minimum number of seconds to run all queries: 0.015 seconds</code>

<code>        </code><code>maximum number of seconds to run all queries: 0.015 seconds</code>

<code>        </code><code>average number of queries per client: 4</code>

<code>        </code><code>average number of seconds to run all queries: 0.024 seconds</code>

<code>        </code><code>minimum number of seconds to run all queries: 0.024 seconds</code>

<code>        </code><code>maximum number of seconds to run all queries: 0.024 seconds</code>

<code>        </code><code>average number of queries per client: 2</code>

<code>        </code><code>average number of seconds to run all queries: 0.028 seconds</code>

<code>        </code><code>minimum number of seconds to run all queries: 0.028 seconds</code>

<code>        </code><code>maximum number of seconds to run all queries: 0.028 seconds</code>

<code>        </code><code>number of clients running queries: 200</code>

<code>        </code><code>average number of queries per client: 1</code>

<code>        </code><code>running</code><code>for</code> <code>engine innodb</code>

<code>        </code><code>average number of seconds to run all queries: 0.112 seconds</code>

<code>        </code><code>minimum number of seconds to run all queries: 0.112 seconds</code>

<code>        </code><code>maximum number of seconds to run all queries: 0.112 seconds</code>

<code>        </code><code>average number of seconds to run all queries: 0.042 seconds</code>

<code>        </code><code>minimum number of seconds to run all queries: 0.042 seconds</code>

<code>        </code><code>maximum number of seconds to run all queries: 0.042 seconds</code>

<code>        </code><code>average number of seconds to run all queries: 0.105 seconds</code>

<code>        </code><code>minimum number of seconds to run all queries: 0.105 seconds</code>

<code>        </code><code>maximum number of seconds to run all queries: 0.105 seconds</code>

<code>user</code><code>time</code> <code>0.05, system</code><code>time</code> <code>0.06</code>

<code>maximum resident</code><code>set</code> <code>size 8332, integral resident</code><code>set</code> <code>size 0</code>

<code>non-physical pagefaults 5388, physical pagefaults 0, swaps 0</code>

<code>voluntary context switches 7484, involuntary context switches 2839</code>

<code>[root@betty ~]</code><code>#</code>

8. 使用存储过程进行测试。 

略 

========== 我是分割线 ============= 

mysqlslap 运行分三个阶段: 

创建 schema,table 和任何用来测试的已经存储了的程序和数据。这个阶段使用单客户端连接;

进行负载测试。这个阶段使用多客户端连接;

清除(断开连接,删除指定表)。这个阶段使用单客户端连接。

例子: 

a. 提供你自己的创建 sql 语句和查询 sql 语句,有 50 个客户端查询,每个查询 200 次(在单行上输入命令): 

<code>[root@betty ~]</code><code># mysqlslap --delimiter=";" --create="create table a (b int);insert into a values (23)" --query="select * from a" --concurrency=50 --iterations=200</code>

<code>        </code><code>average number of seconds to run all queries: 0.005 seconds</code>

<code>        </code><code>minimum number of seconds to run all queries: 0.003 seconds</code>

<code>        </code><code>maximum number of seconds to run all queries: 0.007 seconds</code>

b. 让 mysqlslap 创建查询的 sql 语句,使用的表有 2 个 int 行和 3 个 varchar 行。使用 5 个客户端,每一个查询 20 次!不要创建表或插入数据。(换言之,用之前测试的模式和数据): 

<code>[root@betty ~]</code><code># mysqlslap --concurrency=5 --iterations=20 --number-int-cols=2 --number-char-cols=3 --auto-generate-sql</code>

<code>        </code><code>average number of seconds to run all queries: 0.025 seconds</code>

<code>        </code><code>minimum number of seconds to run all queries: 0.012 seconds</code>

<code>        </code><code>maximum number of seconds to run all queries: 0.084 seconds</code>

<code>        </code><code>number of clients running queries: 5</code>

<code>        </code><code>average number of queries per client: 0</code>

c. 告诉程序从指定的 create.sql 文件去加载 create,insert 和查询等 sql 语句。该文件有多个表的 create 和insert 语句, 它们都是通过“;”分隔开的。query.sql 文件则有 多个查询语句, 分隔符也是“;”。执行所有的加载语句,然后通过查询文件执行所有的查询语句,分别在 5 个客户端上每个执行 5 次: 

<code>[root@betty ~]</code><code># mysqlslap --concurrency=5 --iterations=5 --query=query.sql --create=create.sql --delimiter=";"</code>

========== 我是分割线  ============= 

      mysqlslap 对于模拟多个用户同时对 mysql 发起“进攻”提供了方便。同时详细的提供了“高负荷攻击 mysql”的详细数据报告。