时间:2021-07-01 10:21:17 帮助过:35人阅读
MySQL从5.1.4版开始带有一个压力测试工具mysqlslap,通过模拟多个并发客户端访问mysql来执行测试,使用起来非常的简单。通过mysqlslap help可以获得可用的选项,这里列一些主要的参数,更详细的说明参考官方手册。 --auto-generate-sql, -a自动生成测试表和
MySQL从5.1.4版开始带有一个压力测试工具mysqlslap,通过模拟多个并发客户端访问mysql来执行测试,使用起来非常的简单。通过mysqlslap –help可以获得可用的选项,这里列一些主要的参数,更详细的说明参考官方手册。
--auto-generate-sql, -a 自动生成测试表和数据 --auto-generate-sql-load-type=type 测试语句的类型。取值包括:read,key,write,update和mixed(默认)。 --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参数指定的值做为分隔符 --engine=engine_name, -e engine_name 创建测试表所使用的存储引擎,可指定多个,用分隔符隔开。 --iterations=N, -i N 测试执行的迭代次数 --detach=N 执行N条语句后断开重连 --debug-info, -T 打印内存和CPU的信息 --only-print 只打印测试语句而不实际执行 --defaults-file 配置文件存放位置 --socket=name,-S 指定socket文件位置
一些实例
用自动生成的测试数据进行测试,且只打印实际的测试过程。
# /usr/local/webserver/mysql/bin/mysqlslap -a --only-print DROP SCHEMA IF EXISTS `mysqlslap`; CREATE SCHEMA `mysqlslap`; use mysqlslap; CREATE TABLE `t1` (intcol1 INT(32) ,charcol1 VARCHAR(128)); INSERT INTO t1 VALUES (1804289383,'mxvtvmC9127qJNm06sGB8R92q2j7vTiiITRDGXM9ZLzkdekbWtmXKwZ2qG1llkRw5m9DHOFilEREk3q7oce8O3BEJC0woJsm6uzFAEynLH2xCsw1KQ1lT4zg9rdxBL'); INSERT INTO t1 VALUES (822890675,'97RGHZ65mNzkSrYT3zWoSbg9cNePQr1bzSk81qDgE4Oanw3rnPfGsBHSbnu1evTdFDe83ro9w4jjteQg4yoo9xHck3WNqzs54W5zEm92ikdRF48B2oz3m8gMBAl11W'); ...... INSERT INTO t1 VALUES (100669,'qnMdipW5KkXdTjGCh2PNzLoeR0527frpQDQ8uw67Ydk1K06uuNHtkxYBxT5w8plb2BbpzhwYBgPNYX9RmICWGkZD6fAESvhMzH3yqzMtXoH4BQNylbK1CmEIPGYlC6'); SELECT intcol1,charcol1 FROM t1; INSERT INTO t1 VALUES (73673339,'BN3152Gza4GW7atxJKACYwJqDbFynLxqc0kh30YTwgz3FktQ43XTrqJ4PQ25frn7kXhfXD8RuzN1j8Rf3y8ugKy6es3IbqPJM6ylCyD6xS7YcQCfHKZxYNvB7yTahm'); DROP SCHEMA IF EXISTS `mysqlslap`;
分别100和200个并发,执行1000次总查询
$mysqlslap -a --concurrency=50,100 --number-of-queries 1000 --debug-info # /usr/local/webserver/mysql/bin/mysqlslap -a --concurrency=100,200 --number-of-queries 1000 --debug-info Benchmark Average number of seconds to run all queries: 0.232 seconds Minimum number of seconds to run all queries: 0.232 seconds Maximum number of seconds to run all queries: 0.232 seconds Number of clients running queries: 100 Average number of queries per client: 10 Benchmark Average number of seconds to run all queries: 0.268 seconds Minimum number of seconds to run all queries: 0.268 seconds Maximum number of seconds to run all queries: 0.268 seconds Number of clients running queries: 200 Average number of queries per client: 5 User time 0.02, System time 0.49 Maximum resident set size 6100, Integral resident set size 0 Non-physical pagefaults 3165, Physical pagefaults 0, Swaps 0 Blocks in 0 out 0, Messages in 0 out 0, Signals 0 Voluntary context switches 3102, Involuntary context switches 7541
分别200和400个并发,执行2000次总查询并迭代8次
# /usr/local/webserver/mysql/bin/mysqlslap -a --concurrency=200,400 --number-of-queries 2000 --iterations=8 --debug-info Benchmark Average number of seconds to run all queries: 0.657 seconds Minimum number of seconds to run all queries: 0.603 seconds Maximum number of seconds to run all queries: 0.736 seconds Number of clients running queries: 200 Average number of queries per client: 10 Benchmark Average number of seconds to run all queries: 0.711 seconds Minimum number of seconds to run all queries: 0.648 seconds Maximum number of seconds to run all queries: 0.860 seconds Number of clients running queries: 400 Average number of queries per client: 5 User time 0.58, System time 9.12 Maximum resident set size 30764, Integral resident set size 0 Non-physical pagefaults 92471, Physical pagefaults 0, Swaps 0 Blocks in 0 out 0, Messages in 0 out 0, Signals 0 Voluntary context switches 99629, Involuntary context switches 157741
同时测试不同的存储引擎
# /usr/local/webserver/mysql/bin/mysqlslap -a --concurrency=200,400 --number-of-queries 2000 --iterations=8 --engine=myisam,innodb --debug-info Benchmark Average number of seconds to run all queries: 0.740 seconds Minimum number of seconds to run all queries: 0.678 seconds Maximum number of seconds to run all queries: 0.827 seconds Number of clients running queries: 200 Average number of queries per client: 10 Benchmark Average number of seconds to run all queries: 0.696 seconds Minimum number of seconds to run all queries: 0.661 seconds Maximum number of seconds to run all queries: 0.775 seconds Number of clients running queries: 400 Average number of queries per client: 5 User time 0.62, System time 9.27 Maximum resident set size 33368, Integral resident set size 0 Non-physical pagefaults 89594, Physical pagefaults 0, Swaps 0 Blocks in 0 out 0, Messages in 0 out 0, Signals 0 Voluntary context switches 98328, Involuntary context switches 153787
指定数据库的测试
# /usr/local/webserver/mysql/bin/mysqlslap --concurrency=500 --iterations=8 --create-schema=test --query=/root/test.sql Benchmark Average number of seconds to run all queries: 0.343 seconds Minimum number of seconds to run all queries: 0.283 seconds Maximum number of seconds to run all queries: 0.525 seconds Number of clients running queries: 500 Average number of queries per client: 1
原文地址:用mysqlslap进行MySQL压力测试, 感谢原作者分享。