MySQL5.1地的确提供了好多有力的工具来帮助我们DBA进行数据库管理。
现在看一下这个压力测试工具mysqlslap.
关于他的选项手册上以及--help介绍的很详细。
我解释一下一些常用的选项。
这里要注意的几个选项:
--concurrency代表并发数量,多个可以用逗号隔开,当然你也可以用自己的分隔符隔开,这个时候要用到--delimiter开关。--engines代表要测试的引擎,可以有多个,用分隔符隔开。--iterations代表要运行这些测试多少次。--auto-generate-sql 代表用系统自己生成的SQL脚本来测试。--auto-generate-sql-load-type 代表要测试的是读还是写还是两者混合的(read,write,update,mixed)--number-of-queries 代表总共要运行多少次查询。每个客户运行的查询数量可以用查询总数/并发数来计算。比如倒数第二个结果2=200/100。--debug-info 代表要额外输出CPU以及内存的相关信息。--number-int-cols 代表示例表中的INTEGER类型的属性有几个。--number-char-cols 意思同上。--create-schema 代表自己定义的模式(在MySQL中也就是库)。--query 代表自己的SQL脚本。--only-print 如果只想打印看看SQL语句是什么,可以用这个选项。
现在来看一些我测试的例子。
1、用自带的SQL脚本来测试。
MySQL版本为5.1.23
[root@localhost ~]# mysqlslap --defaults-file=/usr/local/mysql-maria/my.cnf --concurrency=50,100,200 --iterations=1 --number-int-cols=4 --number-char-cols=35 --auto-generate-sql --auto-generate-sql-add-autoincrement --auto-generate-sql-load-type=mixed --engine=myisam,innodb --number-of-queries=200 --debug-info -uroot -p1 -S/tmp/mysql_3310.sock
Benchmark
Running for engine myisam
Average number of seconds to run all queries: 0.063 seconds
Minimum number of seconds to run all queries: 0.063 seconds
Maximum number of seconds to run all queries: 0.063 seconds
Number of clients running queries: 50
Average number of queries per client: 4
Benchmark
Running for engine myisam
Average number of seconds to run all queries: 0.070 seconds
Minimum number of seconds to run all queries: 0.070 seconds
Maximum number of seconds to run all queries: 0.070 seconds
Number of clients running queries: 100
Average number of queries per client: 2
Benchmark
Running for engine myisam
Average number of seconds to run all queries: 0.092 seconds
Minimum number of seconds to run all queries: 0.092 seconds
Maximum number of seconds to run all queries: 0.092 seconds
Number of clients running queries: 200
Average number of queries per client: 1
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.115 seconds
Minimum number of seconds to run all queries: 0.115 seconds
Maximum number of seconds to run all queries: 0.115 seconds
Number of clients running queries: 50
Average number of queries per client: 4
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.134 seconds
Minimum number of seconds to run all queries: 0.134 seconds
Maximum number of seconds to run all queries: 0.134 seconds
Number of clients running queries: 100
Average number of queries per client: 2
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.192 seconds
Minimum number of seconds to run all queries: 0.192 seconds
Maximum number of seconds to run all queries: 0.192 seconds
Number of clients running queries: 200
Average number of queries per client: 1
User time 0.06, System time 0.15
Maximum resident set size 0, Integral resident set size 0
Non-physical pagefaults 5803, Physical pagefaults 0, Swaps 0
Blocks in 0 out 0, Messages in 0 out 0, Signals 0
Voluntary context switches 8173, Involuntary context switches 528
我来解释一下结果的含义。拿每个引擎最后一个Benchmark示例。对于INNODB引擎,200个客户端同时运行这些SQL语句平均要花0.192秒。相应的MYISAM为0.092秒。
2、用我们自己定义的SQL 脚本来测试。
这些数据在另外一个MySQL实例上。版本为5.0.45先看一下这两个表的相关数据。
1)、总记录数。
mysql> select table_rows as rows from information_schema.tables where table_schema='t_girl' and table_name='article';
+--------+
| rows |
+--------+
| 296693 |
+--------+
1 row in set (0.01 sec)
mysql> select table_rows as rows from information_schema.tables where table_schema='t_girl' and table_name='category';
+------+
| rows |
+------+
| 113 |
+------+
1 row in set (0.00 sec)
2)、总列数。
mysql> select count(*) as column_total from information_schema.columns where table_schema = 't_girl' and table_name = 'article';
+--------------+
| column_total |
+--------------+
| 32 |
+--------------+
1 row in set (0.01 sec)
mysql> select count(*) as column_total from information_schema.columns where table_schema = 't_girl' and table_name = 'category';
+--------------+
| column_total |
+--------------+
| 9 |
+--------------+
1 row in set (0.01 sec)
3)、调用的存储过程
DELIMITER $$
DROP PROCEDURE IF EXISTS `t_girl`.`sp_get_article`$$
CREATE DEFINER=`root`@`%` PROCEDURE `sp_get_article`(IN f_category_id int,
IN f_page_size int, IN f_page_no int
)
BEGIN
set @stmt = 'select a.* from article as a inner join ';
set @stmt = concat(@stmt,'(select a.aid from article as a ');
if f_category_id != 0 then
set @stmt = concat(@stmt,' inner join (select cid from category where cid = ',f_category_id,' or parent_id = ',f_category_id,') as b on a.category_id = b.cid');
end if;
if f_page_size >0 && f_page_no > 0 then
set @stmt = concat(@stmt,' limit ',(f_page_no-1)*f_page_size,',',f_page_size);
end if;
set @stmt = concat(@stmt,') as b on (a.aid = b.aid)');
prepare s1 from @stmt;
execute s1;
deallocate prepare s1;
set @stmt = NULL;
END$$
DELIMITER ;
4)、我们用mysqlslap来测试
以下得这个例子代表用mysqlslap来测试并发数为25,50,100的调用存储过程,并且总共调用5000次。
[root@localhost ~]# mysqlslap --defaults-file=/usr/local/mysql-maria/my.cnf --concurrency=25,50,100 --iterations=1 --query='call t_girl.sp_get_article(2,10,1);' --number-of-queries=5000 --debug-info -uroot -p -S/tmp/mysql50.sock
Enter password:
Benchmark
Average number of seconds to run all queries: 3.507 seconds
Minimum number of seconds to run all queries: 3.507 seconds
Maximum number of seconds to run all queries: 3.507 seconds
Number of clients running queries: 25
Average number of queries per client: 200
平均每个并发运行200个查询用了3.507秒。
Benchmark
Average number of seconds to run all queries: 3.742 seconds
Minimum number of seconds to run all queries: 3.742 seconds
Maximum number of seconds to run all queries: 3.742 seconds
Number of clients running queries: 50
Average number of queries per client: 100
Benchmark
Average number of seconds to run all queries: 3.697 seconds
Minimum number of seconds to run all queries: 3.697 seconds
Maximum number of seconds to run all queries: 3.697 seconds
Number of clients running queries: 100
Average number of queries per client: 50
User time 0.87, System time 0.33
Maximum resident set size 0, Integral resident set size 0
Non-physical pagefaults 1877, Physical pagefaults 0, Swaps 0
Blocks in 0 out 0, Messages in 0 out 0, Signals 0
Voluntary context switches 27218, Involuntary context switches 3100
看一下SHOW PROCESSLIST 结果
mysql> show processlist;
+------+------+--------------------+--------------------+---------+-------+--------------------+------------------------------------------------------------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+------+------+--------------------+--------------------+---------+-------+--------------------+------------------------------------------------------------------------------------------------------+
…………
| 3177 | root | % | t_girl | Query | 0 | NULL | select a.* from article as a inner join (select a.aid from article as a inner join (select cid from |
| 3178 | root | % | t_girl | Query | 0 | NULL | select a.* from article as a inner join (select a.aid from article as a inner join (select cid from |
| 3179 | root | % | t_girl | Query | 0 | NULL | select a.* from article as a inner join (select a.aid from article as a inner join (select cid from |
| 3181 | root | % | t_girl | Query | 0 | NULL | select a.* from article as a inner join (select a.aid from article as a inner join (select cid from |
| 3180 | root | % | t_girl | Query | 0 | NULL | select a.* from article as a inner join (select a.aid from article as a inner join (select cid from |
| 3182 | root | % | t_girl | Query | 0 | NULL | select a.* from article as a inner join (select a.aid from article as a inner join (select cid from |
| 3183 | root | % | t_girl | Query | 0 | NULL | select a.* from article as a inner join (select a.aid from article as a inner join (select cid from |
| 3187 | root | % | t_girl | Query | 0 | removing tmp table | select a.* from article as a inner join (select a.aid from article as a inner join (select cid from |
| 3186 | root | % | t_girl | Query | 0 | NULL | select a.* from article as a inner join (select a.aid from article as a inner join (select cid from |
| 3194 | root | % | t_girl | Query | 0 | NULL | select a.* from article as a inner join (select a.aid from article as a inner join (select cid from |
| 3203 | root | % | t_girl | Query | 0 | NULL | deallocate prepare s1 |
…………
| 3221 | root | % | t_girl | Query | 0 | NULL | select a.* from article as a inner join (select a.aid from article as a inner join (select cid from |
| 3222 | root | % | t_girl | Query | 0 | NULL | select a.* from article as a inner join (select a.aid from article as a inner join (select cid from |
| 3223 | root | % | t_girl | Query | 0 | NULL | select a.* from article as a inner join (select a.aid from article as a inner join (select cid from |
| 3224 | root | % | t_girl | Query | 0 | removing tmp table | select a.* from article as a inner join (select a.aid from article as a inner join (select cid from |
| 3225 | root | % | t_girl | Query | 0 | NULL | select a.* from article as a inner join (select a.aid from article as a inner join (select cid from |
| 3226 | root | % | t_girl | Query | 0 | NULL | select a.* from article as a inner join (select a.aid from article as a inner join (select cid from |
+------+------+--------------------+--------------------+---------+-------+--------------------+------------------------------------------------------------------------------------------------------+
55 rows in set (0.00 sec)
上面的测试语句其实也可以这样写
[root@localhost ~]# mysqlslap --defaults-file=/usr/local/mysql-maria/my.cnf --concurrency=25,50,100 --iterations=1 --create-schema='t_girl' --query='call sp_get_article(2,10,1);' --number-of-queries=5000 --debug-info -uroot -p -S/tmp/mysql50.sock
小总结一下。mysqlslap对于模拟多个用户同时对MySQL发起“进攻”提供了方便。同时详细的提供了“高负荷攻击MySQL”的详细数据报告。而且如果你想对于多个引擎的性能。这个工具再好不过了。
分享到:
相关推荐
生产服务器用LANMP组合和用LAMP组合有段时间了,总体来说都很稳定。但出现过几次因为MYSQL并发太多而挂掉,一直想对MYSQL做压力测试。刚看到一篇介绍MYSQL压力测试的文章,确实不错,先收藏先吧
在本例中,参考作者的上一篇文章,了解如何通过 Eclipse 连接 MySQL 并批量插入数据。 接下来,我们需要 JMeter 和 MySQL 的 JDBC 驱动。JMeter 版本不一定要特定,但确保它是支持 JDBC 连接的。将 JDBC 驱动添加到...
同时,进行压力测试以确保在高并发情况下系统的稳定性和性能。 总结,JSP+MySQL博客源码是一个基于Java和MySQL的动态网站示例,涵盖了用户管理、文章发布和评论互动等核心功能。开发者可以借此学习到Web开发的基本...
知识点3: MySQL数据库的性能测试可以通过使用流行的压力测试框架sysbench来实现,并可以根据数据库大小、表数量以及表的记录数划分,界定数据库的并发访问数,来模拟实际项目中的应用场景。 知识点4: 在基于...
【JavaWeb Servlet+JSP+MYSQL+Bootstrap 文章管理系统】是一个常见的IT毕业设计项目,它涵盖了Web开发中的多个核心技术,包括后端处理、前端展示和数据存储。下面将详细阐述这些技术及其在项目中的应用。 1. **...
在博客系统中,MySQL通常会包含如用户信息、文章、评论、分类等表。 要创建一个Java + MySQL博客系统,我们需要以下步骤: 1. **设计数据库模型**:确定博客系统需要哪些数据表,例如用户表(user)、文章表(post)、...
5. **测试和优化**:完成基础设置后,进行压力测试和性能评估,根据结果优化配置,如调整复制延迟、增加从节点等。 6. **维护和监控**:定期备份数据,监控系统性能,及时处理可能出现的问题,确保集群的稳定运行。...
本篇文章将详细介绍如何在生产环境中使用MySQL 5.7.20和MaxScale 2.0来构建一个简单的读写分离架构。 #### 二、环境准备 在开始部署之前,我们需要准备好以下环境: - **操作系统**:CentOS 7.x - **MySQL 版本**...
搭建完成后,进行性能测试和压力测试,优化配置参数,如调整nginx的worker_processes、Apache的MaxClients等,以确保系统在高负载下仍能稳定运行。 **四、监控与维护** 部署监控工具,如Nagios、Zabbix等,实时...
4. **压力测试**:评估程序在高负载或资源受限条件下的表现。Apache JMeter和Locust是常用于Web应用的压力测试工具。 5. **性能测试**:关注程序的响应时间、吞吐量等性能指标。可以使用gprof或valgrind来分析程序...
本篇文章将详细探讨如何通过结合MySQL、Galera集群和HAProxy来构建高可用性的数据库架构。 MySQL Galera集群是一种强大的解决方案,它提供了完全的多主复制,允许所有节点同时读写,从而实现了数据的实时同步。...
性能测试通过模拟用户访问和操作来评估服务器的处理能力,它涉及到各种不同的测试类型,如负载测试(衡量系统在超过正常负载的情况下处理能力)、压力测试(确定系统的最大操作能力)、稳定性测试(确保服务器长时间...
性能测试是评估数据库引擎性能的重要手段,可以通过基准测试、压力测试和实际应用模拟来对比不同引擎的性能表现。这包括查询速度、并发处理能力、内存使用、磁盘I/O等方面。为了选择合适的引擎,开发者需要根据应用...
10. **测试与部署**:开发过程中,单元测试、集成测试和压力测试都是必不可少的,以确保系统的稳定性和性能。最后,系统需要被部署到服务器,如Apache或Nginx,以供用户访问。 通过对这些知识点的理解和应用,毕业...
首先,sysbench0.5是针对早期版本的sysbench,它主要专注于MySQL数据库的性能测试,但也提供了对Oracle数据库的支持。sysbench0.5提供了一套全面的测试场景,包括OLTP(在线事务处理)工作负载、读写混合操作以及CPU...
本篇文章将深入探讨MySQL的备份与恢复策略,包括常见的工具和参数,特别是对`mysqldump`工具的详细使用。 1. **mysqldump**:这是MySQL的逻辑备份工具,通过SQL语句生成数据的脚本文件。它适用于不同MySQL版本之间...
sysbench是一款压力测试工具,可以测试系统的硬件性能,也可以用来对数据库进行基准测试。这篇文章主要介绍了通过sysbench工具实现MySQL数据库的性能测试 ,需要的朋友可以参考下
在压力测试中,将DNS缓存存储在MySQL数据库中相比传统方法,表现出更优秀的性能,包括更快的查询响应时间、更高的查询命中率以及更低的出口带宽占用。 此外,文章还提到了DNS日志的数据量问题。例如,山西农业大学...
开发完成后,通过单元测试、集成测试和压力测试,确保系统功能的正确性和性能的稳定性。在系统上线后,持续进行维护和更新,修复可能出现的问题,以保持系统的良好运行状态。 五、结论 基于微信小程序的文章管理...
文章通过实际部署和测试验证了该方案的有效性。实验表明,基于云平台的MySQL集群在节点失效时能够成功进行故障切换,保证服务连续性,同时也实现了底层数据的存储扩展,显著减少了故障切换时间,提高了系统的可用性...