mysqlslap 是 MySQL 自带的一个用于实现负载性能测试和压力测试的工具。它可以模拟多个客户端对数据库进行施压,并生成报告来了解数据库的性能状况。
mysqlslap 的运行过程主要分三步:
创建库、表,导入数据用于测试。此过程由单线程完成。
开始进行压力测试。该步骤可以使用多线程完成。
清理测试数据。此过程由单线程完成。
下面举几个例子来说明下如何使用 mysqlslap。
自动生成测试表,其中会生成自增列,采用单线程进行测试。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
[root@node1 ~]# mysqlslap -uroot -p --auto-generate-sql --auto-generate-sql-load-type=mixed --auto-generate-sql-add-autoincrement Enter password: Benchmark #运行所有语句的平局时间,单位秒 Average number of seconds torun all queries: 0.018 seconds #运行所有语句的最小秒数 Minimum number of seconds torun all queries: 0.018 seconds #运行所有语句的最大秒数 Maximum number of seconds torun all queries: 0.018 seconds #客户端数量 Number of clients running queries: 1 #每个客户端运行查询的平均数 Average number of queries per client: 0
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
针对CPU的基准测试
测试计算素数直到某个最大值所需要的时间。
1 2 3 4 5 6 7 8 9
[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 …………………………….
针对内存的基准测试
1
sysbench --test=memory --memory-block-size=8k --memory-total-size=100G run
OLTP test statistics: queries performed: read: 407498 write: 0 other: 58214 total: 465712 transactions: 29107 (485.07 per sec.) read/write 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 approx. 95 percentile: 25.98ms Threads fairness: events (avg/stddev): 3638.3750/42.84 execution time (avg/stddev): 59.9983/0.00