mysqlslap
MySQL从5.1.4版开始带有一个压力测试工具mysqlslap,通过模拟多个并发客户端访问mysql来执行测试,使用起来非常的简单。通过mysqlslap -help可以获得可用的选项,这里列一些主要的参数,更详细的说明参考官方手册。
man mysqlslap 也可以看到有下面一条示例:
- mysqlslap --delimiter=";" --create="CREATE TABLE a (b int);INSERT INTO a VALUES (23)" --query="SELECT * FROM a" --concurrency=50 --iterations=200
mysqlslap --help 参数
- -a, --auto-generate-sql 自动生成测试表和数据
- --auto-generate-sql-load-type=name 测试语句的类型。取值包括:read,key,write,update和mixed(多种混合,默认)。
- -C, --compress 如果服务器和客户端支持都压缩,则压缩信息传递
- --commit=N 多少条DML后提交一次
- --create-schema=name 指定数据库测试,不要和:auto-generate-sql 参数一起使用!
- --detach=N 执行N条语句后断开重连
- --concurrency 指定并发数
- -T, --debug-info 打印内存和CPU的信息
- --number-of-queries=1000 指定查询总次数
- -i, --iterations=5 重复多次(迭代多次)
- -e, --engine=name 指定引擎
- --only-print 只输出测试语句而不实际执行
- -q, --query=name 使用自定义脚本执行测试,例如可以调用自定义的一个存储过程或者sql语句来执行测试。
压力测试: 分别50、100和500个并发,执行1000次总查询,指定引擎:myisam,innodb
- [root@localhost ~]# mysqlslap --auto-generate-sql --concurrency=50,100,500 --number-of-queries=1000 --iterations=5 --debug-info --engine=myisam,innodb -uroot -p
- Enter password:
- Benchmark
- Running for engine myisam
- Average number of seconds to run all queries: 0.108 seconds
- Minimum number of seconds to run all queries: 0.083 seconds
- Maximum number of seconds to run all queries: 0.119 seconds
- Number of clients running queries: 50
- Average number of queries per client: 20
- Benchmark
- Running for engine myisam
- Average number of seconds to run all queries: 0.127 seconds
- Minimum number of seconds to run all queries: 0.094 seconds
- Maximum number of seconds to run all queries: 0.150 seconds
- Number of clients running queries: 100
- Average number of queries per client: 10
- Benchmark
- Running for engine myisam
- Average number of seconds to run all queries: 0.182 seconds
- Minimum number of seconds to run all queries: 0.161 seconds
- Maximum number of seconds to run all queries: 0.204 seconds
- Number of clients running queries: 500
- Average number of queries per client: 2
- Benchmark
- Running for engine innodb
- Average number of seconds to run all queries: 0.305 seconds
- Minimum number of seconds to run all queries: 0.294 seconds
- Maximum number of seconds to run all queries: 0.322 seconds
- Number of clients running queries: 50
- Average number of queries per client: 20
- Benchmark
- Running for engine innodb
- Average number of seconds to run all queries: 0.315 seconds
- Minimum number of seconds to run all queries: 0.304 seconds
- Maximum number of seconds to run all queries: 0.338 seconds
- Number of clients running queries: 100
- Average number of queries per client: 10
- Benchmark
- Running for engine innodb
- Average number of seconds to run all queries: 0.515 seconds
- Minimum number of seconds to run all queries: 0.485 seconds
- Maximum number of seconds to run all queries: 0.548 seconds
- Number of clients running queries: 500
- Average number of queries per client: 2
- User time 2.48, System time 2.47
- Maximum resident set size 27284, Integral resident set size 0
- Non-physical pagefaults 55681, Physical pagefaults 0, Swaps 0
- Blocks in 0 out 0, Messages in 0 out 0, Signals 0
- Voluntary context switches 101688, Involuntary context switches 95927
“江南一品绣”床上用品淘宝店:http://xiaomiwozhidao.taobao.com