设为首页 收藏本站
查看: 1301|回复: 0

[经验分享] 用mysql自带工具mysqlslap对数据库进行压力测试

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2017-3-1 15:45:49 | 显示全部楼层 |阅读模式
mysqlslap是mysql自带的工具,不需要单独安装:
参数:-concurrency 代表并发数量,多个可以用逗号隔开,concurrency=10,50,100, 并发连接线程数分别是10、50、100个并发。
--engines 代表要测试的引擎,可以有多个,用分隔符隔开。
--iterations 代表要运行这些测试多少次。
--auto-generate-sql 代表用系统自己生成的SQL脚本来测试。
--auto-generate-sql-load-type 代表要测试的是读还是写还是两者混合的(read,write,update,mixed)
--number-of-queries 代表总共要运行多少次查询。每个客户运行的查询数量可以用查询总数/并发数来计算。
--debug-info 代表要额外输出CPU以及内存的相关信息。
--number-int-cols :创建测试表的 int 型字段数量
--auto-generate-sql-add-autoincrement : 代表对生成的表自动添加auto_increment列,从5.1.18版本开始
--number-char-cols 创建测试表的 char 型字段数量。
--create-schema 测试的schema,MySQL中schema也就是database。
--query 使用自定义脚本执行测试,例如可以调用自定义的一个存储过程或者sql语句来执行测试。
--only-print 如果只想打印看看SQL语句是什么,可以用这个选项。
1,简单用法
1
2
3
4
5
6
7
8
9
10
11
12
13
[iyunv@Linux_Aolens_01 /home/aolens]# mysqlslap --user=root --password=password --auto-generate-sql
  
Benchmark
  
Average number of seconds to run all queries: 0.002 seconds
  
Minimum number of seconds to run all queries: 0.002 seconds
  
Maximum number of seconds to run all queries: 0.002 seconds
  
Number of clients running queries: 1
  
Average number of queries per client: 0





结果中各项含义:
  • Average number of ... 运行所有语句的平均秒数
  • Minimum number of ... 运行所有语句的最小秒数
  • Maximum number of ... 运行所有语句的最大秒数
  • Number of clients ... 客户端数量
  • Average number of queries per client 每个客户端运行查询的平均数


2,添加并发
1
2
3
4
5
6
7
[iyunv@Linux_Aolens_01 /home/aolens]# mysqlslap --user=root --password=password --auto-generate-sql --concurrency=100 --number-of-queries=1000
Benchmark
Average number of seconds to run all queries: 0.316 seconds
Minimum number of seconds to run all queries: 0.316 seconds
Maximum number of seconds to run all queries: 0.316 seconds
Number of clients running queries: 100
Average number of queries per client: 10



3,使用自己测试库和测试语句
1
2
3
4
5
6
7
[iyunv@Linux_Aolens_01 /home/aolens]# mysqlslap --user=root --password=password --concurrency=10 --number-of-queries=100 --create-schema=wordpress --query="SELECT * FROM wordpress.wp_posts;"
Benchmark
Average number of seconds to run all queries: 4.255 seconds
Minimum number of seconds to run all queries: 4.255 seconds
Maximum number of seconds to run all queries: 4.255 seconds
Number of clients running queries: 10
Average number of queries per client: 10



4,结合实际,对网站首页所请求的数据库连接做压力测试数据库Mariadb 10.0.14
首先给数据库安装审计插件,并启用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
MariaDB [(none)]> show variables like '%audit%'
-> ;
+-------------------------------+-----------------------+
| Variable_name | Value |
+-------------------------------+-----------------------+
| server_audit_events | |
| server_audit_excl_users | |
| server_audit_file_path | server_audit.log |
| server_audit_file_rotate_now | OFF |
| server_audit_file_rotate_size | 1000000 |
| server_audit_file_rotations | 9 |
| server_audit_incl_users | |
| server_audit_logging | OFF |
| server_audit_mode | 0 |
| server_audit_output_type | file |
| server_audit_syslog_facility | LOG_USER |
| server_audit_syslog_ident | mysql-server_auditing |
| server_audit_syslog_info | |
| server_audit_syslog_priority | LOG_INFO |
+-------------------------------+-----------------------+
14 rows in set (0.00 sec)



发现已经安装了,没有安装的MariaDB [(none)]> INSTALL PLUGIN server_audit SONAME 'server_audit.so';
命令行启动审计功能:
       命令行启用audit ,重启后失效
1
2
3
4
5
6
7
8
MariaDB [(none)]> set global server_audit_file_rotate_size=1024*1024*1024;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> set global server_audit_events='query,table';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> set global server_audit_file_rotate_now=on;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> set global server_audit_logging='ON';
Query OK, 0 rows affected (0.00 sec)





刷新一下首页查看审计日志里都有哪些SQL操作,对这些SQL进行压测:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
mysqlslap --user=root --password=password --concurrency=20 --number-of-queries=1000 --create-schema=wordpress --query=" \
SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes'; \
SELECT option_value FROM wp_options WHERE option_name = 'a3_lz_google_api_key' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = 'a3_lz_google_api_key_enable' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = '_transient_timeout_a3_lz_google_api_key_status' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = '_transient_a3_lz_google_api_key_status' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = 'wordpress_api_key' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = 'onp_license_clipboard-images' LIMIT 1; \
SELECT autoload FROM wp_options WHERE option_name = 'onp_license_clipboard-images'; \
SELECT option_value FROM wp_options WHERE option_name = 'onp_version_check_clipboard-images' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = 'ossdl_https' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = 'uninstall_plugins' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = 'a3_lazy_load_just_installed' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = 'akismet_comment_nonce' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = 'preload_cache_counter' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = 'rewrite_rules' LIMIT 1; \
......"
Benchmark
Average number of seconds to run all queries: 40.931 seconds
Minimum number of seconds to run all queries: 40.931 seconds
Maximum number of seconds to run all queries: 40.931 seconds
Number of clients running queries: 20
Average number of queries per client: 50



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-348889-1-1.html 上篇帖子: MySQL备份与还原详细过程示例 下篇帖子: Ameoba实现MySQL读写分离及负载均衡 压力测试 数据库 mysql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表