MySQL/MariaDB的"response time"插件
2016-03-22 17:03
585 查看
“响应时间”是衡量数据库性能的常用指标。在MariaDB中可以使用插件“QUERY_RESPONSE_TIME”来获取查询时间区间的统计信息。
// 安装插
件
// 参数说明
query_response_time_flush
Description: Updating this variable flushes the statistics and re-reads query_response_time_range_base.
Commandline: None
Scope: Global
Dynamic: Yes
Data Type: boolean
Default Value: OFF
query_response_time_range_base
Description: Select base of log for QUERY_RESPONSE_TIME ranges. WARNING: variable change takes affect only after flush.
Commandline: --query-response-time-range-base=#
Scope: Global
Dynamic: Yes
Data Type: numeric
Default Value: 10
Range: 2 to 1000
if the range base=10, we have the following intervals:
(0; 10 ^ -6], (10 ^ -6; 10 ^ -5], (10 ^ -5; 10 ^ -4], ...,
(10 ^ -1; 10 ^1], (10^1; 10^2]...(10^7; positive infinity]
query_response_time_stats
Description: Enable or disable query response time statistics collecting
Commandline: query-response-time-stats[={0|1}]
Scope: Global
Dynamic: Yes
Data Type: boolean
Default Value: OFF
// 打开统计
// 分析
从上面的记录可知:
有70个查询的执行时间在0.000010秒<query execution time < =0.000100秒这个区间里;耗时总计0.002200秒。
有16个查询的执行时间在0.000100秒<query execution time < =0.001000秒这个区间里;耗时总计0.005615秒。
// 安装插
件
$ cd ${mysql_base}/lib/plugin $ ll -rw-r--r--. 1 root root 403898 Feb 25 01:15 query_response_time.so
MariaDB [(none)]> install plugin query_response_time_audit soname 'query_response_time.so'; MariaDB [(none)]> install plugin query_response_time soname 'query_response_time.so'; MariaDB [(none)]> show plugins; ... | QUERY_RESPONSE_TIME_AUDIT | ACTIVE | AUDIT | query_response_time.so | GPL | | QUERY_RESPONSE_TIME | ACTIVE | INFORMATION SCHEMA | query_response_time.so | GPL | +-------------------------------+----------+--------------------+------------------------+---------+
// 参数说明
MariaDB [(none)]> show variables like 'query_response%'; +--------------------------------+-------+ | Variable_name | Value | +--------------------------------+-------+ | query_response_time_flush | OFF | | query_response_time_range_base | 10 | | query_response_time_stats | OFF | +--------------------------------+-------+ 3 rows in set (0.00 sec)
query_response_time_flush
Description: Updating this variable flushes the statistics and re-reads query_response_time_range_base.
Commandline: None
Scope: Global
Dynamic: Yes
Data Type: boolean
Default Value: OFF
query_response_time_range_base
Description: Select base of log for QUERY_RESPONSE_TIME ranges. WARNING: variable change takes affect only after flush.
Commandline: --query-response-time-range-base=#
Scope: Global
Dynamic: Yes
Data Type: numeric
Default Value: 10
Range: 2 to 1000
if the range base=10, we have the following intervals:
(0; 10 ^ -6], (10 ^ -6; 10 ^ -5], (10 ^ -5; 10 ^ -4], ...,
(10 ^ -1; 10 ^1], (10^1; 10^2]...(10^7; positive infinity]
query_response_time_stats
Description: Enable or disable query response time statistics collecting
Commandline: query-response-time-stats[={0|1}]
Scope: Global
Dynamic: Yes
Data Type: boolean
Default Value: OFF
// 打开统计
MariaDB [(none)]> set global query_response_time_stats = 1; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> set global query_response_time_flush='ON'; Query OK, 0 rows affected (0.00 sec) MariaDB [information_schema]> select * from information_schema.QUERY_RESPONSE_TIME; +----------------+-------+----------------+ | TIME | COUNT | TOTAL | +----------------+-------+----------------+ | 0.000001 | 0 | 0.000000 | | 0.000010 | 0 | 0.000000 | | 0.000100 | 70 | 0.002200 | | 0.001000 | 16 | 0.005615 | | 0.010000 | 0 | 0.000000 | | 0.100000 | 0 | 0.000000 | | 1.000000 | 0 | 0.000000 | | 10.000000 | 0 | 0.000000 | | 100.000000 | 0 | 0.000000 | | 1000.000000 | 0 | 0.000000 | | 10000.000000 | 0 | 0.000000 | | 100000.000000 | 0 | 0.000000 | | 1000000.000000 | 0 | 0.000000 | | TOO LONG | 0 | TOO LONG | +----------------+-------+----------------+ 14 rows in set (0.00 sec)
// 分析
从上面的记录可知:
有70个查询的执行时间在0.000010秒<query execution time < =0.000100秒这个区间里;耗时总计0.002200秒。
有16个查询的执行时间在0.000100秒<query execution time < =0.001000秒这个区间里;耗时总计0.005615秒。
相关文章推荐
- MySQL中的integer 数据类型
- MySQL存储过程
- mysql中int、bigint、smallint 和 tinyint的区别与长度
- mysql load data 导出、导入 csv
- source命令执行SQL脚本文件
- MySQL创建用户及权限控制
- MySQL管理数据表
- linux下mysql添加用户
- mysql procedure
- mysql触发器
- MySQL 备份和恢复策略
- mac下安装mysql(转载)
- mysql 修改编码 Linux/Mac/Unix/通用(杜绝修改后无法启动的情况!)
- MySQL数据的导出、导入(mysql内部命令:mysqldump、mysql)
- mysql数据行转列
- Linux下修改MySQL编码的方法
- MySQL Server 日志
- MySQL 安全事宜
- MySQL 备份与恢复