几个常用的MySQL性能测试工具

几个常用的MySQL性能测试工具,第1张

1、mysqlslap

安装:简单,装了mysql就有了

作用:模拟并发测试数据库性能。

优点:简单,容易使用。

不足:不能指定生成的数据规模,测试过程不清楚针对十万级还是百万级数据做的测试,感觉不太适合做综合测试,比较适合针对既有数据库,对单个sql进行优化的测试。

使用方法:

可以使用mysqlslap --help来显示使用方法:

Default options are read from the following files in the given order:

/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf

--concurrency代表并发数量,多个可以用逗号隔开,concurrency=10,50,100, 并发连接线程数分别是10、50、100个并发。

--engines代表要测试的引擎,可以有多个,用分隔符隔开。

--iterations代表要运行这些测试多少次。

--auto-generate-sql 代表用系统自己生成的SQL脚本来测试。

--auto-generate-sql-load-type 代表要测试的是读还是写还是两者混合的(read,write,update,mixed)

--number-of-queries 代表总共要运行多少次查询。每个客户运行的查询数量可以用查询总数/并发数来计算。

--debug-info 代表要额外输出CPU以及内存的相关信息。

--number-int-cols :创建测试表的 int 型字段数量

--auto-generate-sql-add-autoincrement : 代表对生成的表自动添加auto_increment列,从5.1.18版本开始

--number-char-cols 创建测试表的 char 型字段数量。

--create-schema 测试的schema,MySQL中schema也就是database。

--query 使用自定义脚本执行测试,例如可以调用自定义的一个存储过程或者sql语句来执行测试。

--only-print 如果只想打印看看SQL语句是什么,可以用这个选项。

mysqlslap -umysql -p123 --concurrency=100 --iterations=1 --auto-generate-sql --auto-generate-sql-add-autoincrement --auto-generate-sql-load-type=mixed --engine=myisam --number-of-queries=10 --debug-info

或:

指定数据库和sql语句:

mysqlslap -h192.168.3.18 -P4040 --concurrency=100 --iterations=1 --create-schema='test' --query='select * from test' --number-of-queries=10 --debug-info -umysql -p123

要是看到底做了什么可以加上:--only-print

Benchmark

Average number of seconds to run all queries: 25.225 seconds

Minimum number of seconds to run all queries: 25.225 seconds

Maximum number of seconds to run all queries: 25.225 seconds

Number of clients running queries: 100

Average number of queries per client: 0

以上表明100个客户端同时运行要25秒

2、sysbench

安装:

可以从http://sourceforge.net/projects/sysbench/ 下载

tar zxf sysbench-0.4.12.tar.gz

cd sysbench-0.4.12

./autogen.sh

./configure &&make &&make install

strip /usr/local/bin/sysbench

安装时候可能会报错,后来baidu发现个好文 http://blog.csdn.net/icelemon1314/article/details/7004955 怕以后找不到,也贴过来吧

1.如果mysql不是默认路径安装,那么需要通过指定--with-mysql-includes和--with-mysql-libs参数来加载mysql安装路径

2.如果报错:

../libtool: line 838: X--tag=CC: command not found

../libtool: line 871: libtool: ignoring unknown tag : command not found

../libtool: line 838: X--mode=link: command not found

../libtool: line 1004: *** Warning: inferring the mode of operation is deprecated.: command not found

../libtool: line 1005: *** Future versions of Libtool will require --mode=MODE be specified.: command not found

../libtool: line 2231: X-g: command not found

../libtool: line 2231: X-O2: command not found

那么执行下根目录的:autogen.sh文件,然后重新configure &&make &&make install

3.如果报错:

sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory

那么执行下:

n -s /usr/local/mysql5.5/mysql/lib/libmysqlclient.so.18 /usr/lib64/

4.如果执行autogen.sh时,报如下错误:

./autogen.sh: line 3: aclocal: command not found

那么需要安装一个软件:

yum install automake

然后需要增加一个参数:查找: AC_PROG_LIBTOOL 将其注释,然后增加AC_PROG_RANLIB

作用:模拟并发,可以执行CPU/内存/线程/IO/数据库等方面的性能测试。数据库目前支持MySQL/Oracle/PostgreSQL

优点:可以指定测试数据的规模,可以单独测试读、写的性能,也可以测试读写混合的性能。

不足:测试的时候,由于网络原因,测试的非常慢,但是最终给的结果却很好,并发支持很高,所以给我的感觉是并不太准确。当然也可能我没搞明白原理

使用方法:

准备数据

sysbench --test=oltp --mysql-table-engine=myisam --oltp-table-size=400000 --mysql-db=dbtest2 --mysql-user=root --mysql-host=192.168.1.101 --mysql-password=pwd prepare

执行测试

sysbench --num-threads=100 --max-requests=4000 --test=oltp --mysql-table-engine=innodb --oltp-table-size=400000 --mysql-db=dbtest1 --mysql-user=root --mysql-host=192.168.1.101 --mysql-password=pwd run

sysbench 0.4.12: multi-threaded system evaluation benchmark

No DB drivers specified, using mysql

Running the test with following options:

Number of threads: 100

Doing OLTP test.

Running mixed OLTP test

Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)

Using "BEGIN" for starting transactions

Using auto_inc on the id column

Maximum number of requests for OLTP test is limited to 4000

Threads started!

Done.

OLTP test statistics:

queries performed:

read: 56014

write: 20005

other: 8002

total: 84021

transactions: 4001 (259.14 per sec.)

deadlocks: 0 (0.00 per sec.)

read/write requests: 76019 (4923.75 per sec.)

other operations: 8002 (518.29 per sec.)

Test execution summary:

total time: 15.4393s

total number of events: 4001

total time taken by event execution: 1504.7744

per-request statistics:

min: 33.45ms

avg: 376.10ms

max: 861.53ms

approx. 95 percentile: 505.65ms

Threads fairness:

events (avg/stddev): 40.0100/0.67

execution time (avg/stddev): 15.0477/0.22

3、tpcc-mysql

安装:

如果从原网站上下载源码比较麻烦,需要工具、注册、生成证书等。这里提供一个下载包http://blog.chinaunix.net/blog/downLoad/fileid/8532.html

export C_INCLUDE_PATH=/usr/include/mysql

export PATH=/usr/bin:$PATH

export LD_LIBRARY_PATH=/usr/lib/mysql

cd /tmp/tpcc/src

make

然后就会在 /tmp/tpcc-mysql 下生成 tpcc 命令行工具 tpcc_load 、 tpcc_start

作用:测试mysql数据库的整体性能

优点:符合tpcc标准,有标准的方法,模拟真实的交易活动,结果比较可靠。

不足:不能单独测试读或者写的性能,对于一些以查询为主或者只写的应用,就没有这么大的意义了。

使用方法:

加载数据

创建库

mysql>create database tpcc10

创建表:

shell>mysql tpcc10 <create_table.sql

添加外键:

shell>mysql tpcc10 <add_fkey_idx.sql

加载数据:

1、单进程加载:

shell>./tpcc_load 192.168.11.172 tpcc10 root pwd 300

|主机||数据库||用户||密码||warehouse|

2、并发加载:(推荐,但需要修改一下)

shell>./load.sh tpcc300 300

|数据库||warehouse|

3、测试

./tpcc_start -h192.168.11.172 -d tpcc -u root -p 'pwd' -w 10 -c 10 -r 10 -l 60 -i 10 -f /mnt/hgfs/mysql/tpcc100_2013522.txt

***************************************

*** ###easy### TPC-C Load Generator ***

***************************************

option h with value '192.168.11.172'

option d with value 'tpcc'

option u with value 'root'

option p with value 'pwd'

option w with value '1'

option c with value '100'

option r with value '120'

option l with value '60'

option i with value '10'

option f with value '/mnt/hgfs/mysql/tpcc100_2013522.txt'

<Parameters>

[server]: 192.168.11.172

[port]: 3306

[DBname]: tpcc

[user]: root

[pass]: pwd

[warehouse]: 1

[connection]: 100

[rampup]: 120 (sec.)

[measure]: 60 (sec.)

RAMP-UP TIME.(120 sec.)

MEASURING START.

以目前的硬件条件,无论你怎么优化,都不可能在生产环境中做到“每秒1000次的并发访问”,除非你拿来做测试的是只有几条数据的表和最简单的查询。 如果你完全不懂负载平衡,读写分离,群集这些概念的话。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5915364.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-08
下一篇 2023-03-08

发表评论

登录后才能评论

评论列表(0条)

保存