首页数据库数据库性能测试工具(mysql几种性能测试的工具使用)

数据库性能测试工具(mysql几种性能测试的工具使用)

编程之家2023-10-1899次浏览

大家好,今天来为大家解答数据库性能测试工具这个问题的一些问题点,包括mysql几种性能测试的工具使用也一样很多人还不知道,因此呢,今天就来为大家分析分析,现在让我们一起来看看吧!如果解决了您的问题,还望您关注下本站哦,谢谢~

数据库性能测试工具(mysql几种性能测试的工具使用)

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

1、mysqlslap

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

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

优点:简单,容易使用。

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

使用方法:

数据库性能测试工具(mysql几种性能测试的工具使用)

可以使用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代表要运行这些测试多少次。

数据库性能测试工具(mysql几种性能测试的工具使用)

--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.

mysql几种性能测试的工具使用

mysql几种性能测试的工具使用

近期由于要比较mysql及其分支mariadb, percona的性能,了解了几个这方面的工具,包括:mysqlslap sysbench tpcc-mysql,做一个整理,备忘,分享

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-printBenchmarkAverage number of seconds to run all queries: 25.225 secondsMinimum number of seconds to run all queries: 25.225 secondsMaximum number of seconds to run all queries: 25.225 secondsNumber of clients running queries: 100Average number of queries per client: 0以上表明100个客户端同时运行要25秒

2、sysbench安装:可以从http://sourceforge.net/projects/sysbench/下载tar zxf sysbench-0.4.12.tar.gzcd sysbench-0.4.12./autogen.sh./configure&& make&& make installstrip/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 install3.如果报错: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 runsysbench 0.4.12: multi-threaded system evaluation benchmarkNo DB drivers specified, using mysqlRunning the test with following options:Number of threads: 100Doing OLTP test.Running mixed OLTP testUsing Special distribution(12 iterations, 1 pct of values are returned in 75 pct cases)Using"BEGIN" for starting transactionsUsing auto_inc on the id columnMaximum number of requests for OLTP test is limited to 4000Threads started!Done.OLTP test statistics:queries performed:read: 56014write: 20005other: 8002total: 84021transactions: 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.4393stotal number of events: 4001total time taken by event execution: 1504.7744per-request statistics:min: 33.45msavg: 376.10msmax: 861.53msapprox. 95 percentile: 505.65msThreads fairness:events(avg/stddev): 40.0100/0.67execution time(avg/stddev): 15.0477/0.22

3、tpcc-mysql安装:如果从原网站上下载源码比较麻烦,需要工具、注册、生成证书等。这里提供一个下载包http://blog.chinaunix.net/blog/downLoad/fileid/8532.htmlexport C_INCLUDE_PATH=/usr/include/mysqlexport PATH=/usr/bin:$PATHexport LD_LIBRARY_PATH=/usr/lib/mysqlcd/tmp/tpcc/srcmake然后就会在/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.10, 245(77):10.923|28.902, 242(0):3.677|10.796, 25(0):1.579|2.198, 24(0):17.451|21.047, 25(4):19.999|33.77620, 262(75):9.070|11.917, 263(0):3.407|4.716, 26(0):1.608|1.776, 27(0):11.347|16.408, 26(1):19.166|21.01830, 247(90):11.130|14.131, 241(0):2.367|2.654, 24(0):0.960|1.095, 24(0):9.308|16.538, 25(3):19.999|24.87440, 237(69):11.840|13.009, 239(1):3.638|7.245, 24(0):0.692|0.773, 23(0):8.756|10.456, 23(1):19.527|20.49550, 252(69):10.548|17.925, 256(0):2.652|2.893, 26(0):1.177|3.579, 27(0):14.648|15.018, 25(4):19.999|26.39860, 256(78):9.323|11.328, 251(1):3.895|5.380, 25(0):0.785|1.542, 25(0):11.382|15.829, 26(0):18.481|18.855STOPPING THREADS....................................................................................................<Raw Results>[0] sc:1041 lt:458 rt:0 fl:0[1] sc:1490 lt:2 rt:0 fl:0[2] sc:150 lt:0 rt:0 fl:0[3] sc:150 lt:0 rt:0 fl:0[4] sc:137 lt:13 rt:0 fl:0in 60 sec.<Raw Results2(sum ver.)>[0] sc:1041 lt:458 rt:0 fl:0[1] sc:1490 lt:2 rt:0 fl:0[2] sc:150 lt:0 rt:0 fl:0[3] sc:150 lt:0 rt:0 fl:0[4] sc:137 lt:13 rt:0 fl:0<Constraint Check>(all must be [OK])[transaction percentage]Payment: 43.36%(>=43.0%) [OK]Order-Status: 4.36%(>= 4.0%) [OK]Delivery: 4.36%(>= 4.0%) [OK]Stock-Level: 4.36%(>= 4.0%) [OK][response time(at least 90% passed)]New-Order: 69.45% [NG]*Payment: 99.87% [OK]Order-Status: 100.00% [OK]Delivery: 100.00% [OK]Stock-Level: 91.33% [OK]<TpmC>1499.000 TpmC关于Tpcc的概念请参见http://baike.baidu.com/view/2776305.htm这里把测试用例介绍贴一下TPC-C测试用到的模型是一个大型的商品批发销售公司,它拥有若干个分布在不同区域的商品仓库。当业务扩展的时候,公司将添加新的仓库。每个仓库负责为10个销售点供货,其中每个销售点为3000个客户提供服务,每个客户提交的订单中,平均每个订单有10项产品,所有订单中约1%的产品在其直接所属的仓库中没有存货,必须由其他区域的仓库来供货。同时,每个仓库都要维护公司销售的100000种商品的库存记录

mysql几种性能测试的工具使用

标签:followingfilesengines数据库连接线

如何使用MySQL自带的性能压力测试工具mysqlslap

使用语法如下:

# mysqlslap [options]

常用参数 [options]详细说明:

--auto-generate-sql,-a自动生成测试表和数据,表示用mysqlslap工具自己生成的SQL脚本来测试并发压力。

--auto-generate-sql-load-type=type测试语句的类型。代表要测试的环境是读操作还是写操作还是两者混合的。取值包括:read,key,write,update和mixed(默认)。

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

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

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

--number-of-queries=N总的测试查询次数(并发客户数×每客户查询次数)

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

--create-schema代表自定义的测试库名称,测试的schema,MySQL中schema也就是database。

--commint=N多少条DML后提交一次。

--compress,-C如果服务器和客户端支持都压缩,则压缩信息传递。

--concurrency=N,-c N表示并发量,也就是模拟多少个客户端同时执行select。可指定多个值,以逗号或者--delimiter参数指定的值做为分隔符。例如:--concurrency=100,200,500。

--engine=engine_name,-e engine_name代表要测试的引擎,可以有多个,用分隔符隔开。例如:--engines=myisam,innodb。

--iterations=N,-i N测试执行的迭代次数,代表要在不同并发环境下,各自运行测试多少次。

--only-print只打印测试语句而不实际执行。

--detach=N执行N条语句后断开重连。

--debug-info,-T打印内存和CPU的相关信息。

说明:

测试的过程需要生成测试表,插入测试数据,这个mysqlslap可以自动生成,默认生成一个mysqlslap的schema,如果已经存在则先删除。可以用--only-print来打印实际的测试过程,整个测试完成后不会在数据库中留下痕迹。

各种测试参数实例(-p后面跟的是mysql的root密码):

单线程测试。测试做了什么。

# mysqlslap-a-uroot-p123456

多线程测试。使用–concurrency来模拟并发连接。

# mysqlslap-a-c 100-uroot-p123456

迭代测试。用于需要多次执行测试得到平均值。

# mysqlslap-a-i 10-uroot-p123456

# mysqlslap---auto-generate-sql-add-autoincrement-a-uroot-p123456

# mysqlslap-a--auto-generate-sql-load-type=read-uroot-p123456

# mysqlslap-a--auto-generate-secondary-indexes=3-uroot-p123456

# mysqlslap-a--auto-generate-sql-write-number=1000-uroot-p123456

# mysqlslap--create-schema world-q"select count(*) from City"-uroot-p123456

# mysqlslap-a-e innodb-uroot-p123456

# mysqlslap-a--number-of-queries=10-uroot-p123456

测试同时不同的存储引擎的性能进行对比:

# mysqlslap-a--concurrency=50,100--number-of-queries 1000--iterations=5--engine=myisam,innodb--debug-info-uroot-p123456

执行一次测试,分别50和100个并发,执行1000次总查询:

# mysqlslap-a--concurrency=50,100--number-of-queries 1000--debug-info-uroot-p123456

50和100个并发分别得到一次测试结果(Benchmark),并发数越多,执行完所有查询的时间越长。为了准确起见,可以多迭代测试几次:

# mysqlslap-a--concurrency=50,100--number-of-queries 1000--iterations=5--debug-info-uroot-p123456

关于数据库性能测试工具到此分享完毕,希望能帮助到您。

抖音域名(抖音域名ip地址)如何注销域名备案(如何做域名备案注销)