我的mac 电脑上安装的环境是 mamp,测试语句如下,/Applications/MAMP/Library/bin/mysqlslap -uroot -proot-a --concurrency=50,100 --number-of-queries 1000 --iterations=5 --engine=myisam,innodb--debug-info
--concurrency:并发量是50 和100
--number-of-queries 1000 执行一千次查询
--iterations:迭代5次,执行五次
--engine= myisam,innodb :分别用myisam 和innodb两种引擎分别测试
执行结果如下:
Benchmark
Running for engine myisam
Average number of seconds to run all queries: 0.081 seconds
Minimum number of seconds to run all queries: 0.078 seconds
Maximum number of seconds to run all queries: 0.086 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.112 seconds
Minimum number of seconds to run all queries: 0.098 seconds
Maximum number of seconds to run all queries: 0.151 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.167 seconds
Minimum number of seconds to run all queries: 0.146 seconds
Maximum number of seconds to run all queries: 0.183 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.209 seconds
Minimum number of seconds to run all queries: 0.181 seconds
Maximum number of seconds to run all queries: 0.246 seconds
Number of clients running queries: 100
Average number of queries per client: 10
一些其他的命令也放在下面,有兴趣的朋友可以学习一下
--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文件位置
2.用自动生成的测试数据进行测试,且只打印实际的测试过程。
# /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`;
3.分别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
4.分别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
5.同时测试不同的存储引擎
# /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
6.指定数据库的测试
[plain]view plaincopy
# /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
需要注意的是,以上的测试不登陆mysql 执行的
网友评论