http://aolens.blog.51cto.com/7021142/1901557-------用mysql自带工具mysqlslap对数据库进行压力测试

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
[root@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
[root@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
[root@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

(转)用mysql自带工具mysqlslap对数据库进行压力测试的更多相关文章

  1. Mysql压测工具mysqlslap 讲解

    在mysql5.1以后的版本:客户端带了个工具mysqlslap可以对mysql进行压力测试: 可以使用mysqlslap --help来显示使用方法: Default options are rea ...

  2. MySQL数据库基准压力测试工具之MySQLSlap使用实例

    一.Mysqlslap介绍 mysqlslap是MySQL5.1之后自带的benchmark基准测试工具,类似Apache Bench负载产生工具,生成schema,装载数据,执行benckmark和 ...

  3. Mysql多线程性能测试工具sysbench 安装、使用和测试

    From:http://www.cnblogs.com/zhoujinyi/archive/2013/04/19/3029134.html 摘要:      sysbench是一个开源的.模块化的.跨 ...

  4. mysql之 sysbench1.0.3 安装与系统压力测试

    针对系统和数据库压测是项目上线前必做的一项,这里使用的是最新版本的sysbench做的压测使用详解.sysbench可以做系统层面的压力测试(CPU.内存.硬盘IO.互斥锁.Thead),也可以做数据 ...

  5. 开源API集成测试工具 Hitchhiker v0.2更新 - 压力测试

    Hitchhiker 是一款开源的 Restful Api 集成测试工具,支持Schedule, 数据对比,压力测试,可以轻松部署到本地,和你的team成员一起管理Api. 详细介绍请看: http: ...

  6. Linux系统性能测试工具(二)——内存压力测试工具memtester

    本文介绍关于Linux系统(适用于centos/ubuntu等)的内存压力测试工具-memtester.内存性能测试工具包括: 内存带宽测试工具——mbw: 内存压力测试工具——memtester: ...

  7. 基于奇林软件kylinTOP工具的HTTP2协议的压力测试

    1.HTTP协议概述 说到http,那就应该先了解一下http协议的发展历史.关于http协议的历史,可以参考阮一峰老师的这篇博客文章HTTP 协议入门,里面介绍的比较详细了.简单来说http先后存在 ...

  8. 使用mysql自带工具mysqldump进行全库备份以及source命令恢复数据库

    mysql数据库提供了一个很好用的工具mysqldump用以备份数据库,下面将使用mysqldump命令进行备份所有数据库以及指定数据库 一.mysqldump一次性备份所有数据库数据 /usr/lo ...

  9. MySQL 自带工具使用介绍

    MySQL 数据库不仅提供了数据库的服务器端应用程序,同时还提供了大量的客户端工具程序,如mysql,mysqladmin,mysqldump 等等,都是大家所熟悉的.虽然有些人对这些工具的功能都已经 ...

随机推荐

  1. JavaScript语言精粹 笔记04 数组

    数组1 数组字面量2 长度3 删除4 列举5 混淆的地方6 方法7 维度 数组1 数组字面量 var empty = []; var numbers = [ 'zero', 'one', 'two', ...

  2. docker中安装Jenkins

    1.获取Jenkins镜像(不要直接docker pull jenkin,这样获取的不是最新的版本,后续安装部分插件会不成功) docker pull jenkins/jenkins 创建文件夹 su ...

  3. 菜鸟的Xamarin.Forms前行之路——windows下VS运行ios模拟器调试

    在Xamarin.Forms项目中,运行安卓模拟器是很方便的,但是想要运行IOS模拟器,相对而言是困难一点. 在参考一些资料后,发现很多是与Xamarin.studio有关的方法,尝试了许久没有成功. ...

  4. Ocelot

    Ocelot——初识基于.Net Core的API网关 Ocelot API网关的实现剖析 微服务网关Ocelot API网关Ocelot 使用Polly 处理部分失败问题 谈谈微服务中的 API 网 ...

  5. Eclipse无法正常创建android工程解决方法!

    我最近升级了安卓的SDK,升级后发现无法在Eclipse中创建android工程了,创建的工程完毕后,没有自动生成这个工程的activity和对应的布局文件,上网搜索一番,最后终于解决了.可能是升级后 ...

  6. OCP最新题库052考题解析及答案-第37题

    37.USER1 grants SELECT, INSERT, and UPDATE privileges on USER1. EMP to USER2. SYS executes this comm ...

  7. less配置

    一.sublime text需要下载考拉,然后要 一直打开着: 1.编译工具用koala编译 下载地址:http://koala-app.com/index-zh.html 2.LESS中的注释: 可 ...

  8. POJ - 2387 Til the Cows Come Home (最短路Dijkstra+优先队列)

    Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before ...

  9. 卸载jdk1.7

    卸载jdk1.7: 1.开始->程序->控制面板 ->卸载程序->程序和功能 2.找到jdk的两个程序:java 7 update 45和java(TM)SE Developm ...

  10. jvisualvm_使用jstatd连接远程linux应用

    [1]确定linux系统正确安装了ssh # sudo ps -e | grep ssh ①注意使用root,使用$会报如下错误: [appadmin@webcsuat2 ~]$ sudo ps -e ...