作为DBA,你不得不掌握的压测工具
有关SQL
共 4773字,需浏览 10分钟
·
2021-09-14 16:17
创建库、表,导入数据用于测试。此过程由单线程完成。
开始进行压力测试。该步骤可以使用多线程完成。
清理测试数据。此过程由单线程完成。
~]# mysqlslap -uroot -p --auto-generate-sql --auto-generate-sql-load-type=mixed --auto-generate-sql-add-autoincrement
Enter password:
Benchmark
#运行所有语句的平局时间,单位秒
Average number of seconds to run all queries: 0.018 seconds
#运行所有语句的最小秒数
Minimum number of seconds to run all queries: 0.018 seconds
#运行所有语句的最大秒数
Maximum number of seconds to run all queries: 0.018 seconds
#客户端数量
Number of clients running queries: 1
#每个客户端运行查询的平均数
Average number of queries per client: 0
--auto-generate-sql:自动生成测试表和数据,mysqlslap工具自己生成sql脚本进行测试。
--auto-generate-sql-load-type:指定测试语句的类型。取值包括:read,key,write,update和mixed(默认)。
--auto-generate-sql-add-autoincrement:生成的表中会添加自增列。
mysqlslap -uroot -p --auto-generate-sql --auto-generate-sql-load-type=mixed --concurrency=100 --number-of-queries=1000
--concurrency=100:指定同时有100个客户端连接
--number-of-queries=1000:指定总的测试查询次数,该值除以concurrency的值就是每个客户端执行的查询次数。
mysqlslap --delimiter=";" --create="CREATE TABLE a (b int);INSERT INTO a VALUES (23)" --query="SELECT * FROM a" --concurrency=50 --iterations=200
mysqlslap -uroot -p --concurrency=5 --iterations=20 --number-int-cols=2 --number-char-cols=3 --auto-generate-sql
mysqlslap --concurrency=5 --iterations=5 --query=query.sql --create=create.sql --delimiter=";"
cd sysbench-0.5
./autogen.sh
./configure --prefix=/usr/local/sysbench --build=x86_64
make && make install
cp /usr/local/sysbench/bin/sysbench /usr/bin/
验证sysbench安装是否成功。
[root@node1 ~]# sysbench --version
sysbench 0.5
[root@node1 ~]# sysbench --test=cpu --cpu-max-prime=2000 run
sysbench 0.5: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 1
Random number generator seed is 0 and will be ignored
…………………………
General statistics:
total time: 1.1302s
…………………………….
sysbench --test=memory --memory-block-size=8k --memory-total-size=100G run
sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw prepare
sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw run
sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw cleanup
sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --mysql-password=root prepare
mysql> select count(*) from sbtest1;
+----------+
| count(*) |
+----------+
| 1000000 |
+----------+
sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --mysql-password=root --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run
OLTP test statistics:
queries performed:
read: 407498
write: 0
other: 58214
total: 465712
transactions: 29107 (485.07 per sec.)
requests: 407498 (6790.91 per sec.)
other operations: 58214 (970.13 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 60.0064s
total number of events: 29107
total time taken by event execution: 479.9865s
response time:
min: 1.55ms
avg: 16.49ms
max: 539.30ms
95 percentile: 25.98ms
Threads fairness:
events (avg/stddev): 3638.3750/42.84
execution time (avg/stddev): 59.9983/0.00
sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --mysql-password=root cleanup
评论