MySQL Performance-Schema(一) 配置篇
performance-schema最早在MYSQL 5.5中出现,而现在5.6,5.7中performance-Schema又添加了更多的监控项,统计信息也更丰富,越来越有ORACLE-AWR统计信息的赶脚,真乃DBA童鞋进行性能诊断分析的福音。本文主要讲Performance-Schema中的配置表,通过配置表能大概了解performance-schema的全貌,为后续使用和深入理解做准备。
配置表
Performance-Schema中主要有5个配置表,具体如下:
root@performance_schema 06:03:09>show tables like '%setup%';
+----------------------------------------+
| Tables_in_performance_schema (%setup%) |
+----------------------------------------+
| setup_actors |
| setup_consumers |
| setup_instruments |
| setup_objects |
| setup_timers |
+----------------------------------------+
1.setup_actors用于配置user维度的监控,默认情况下监控所有用户线程。
root@performance_schema 05:47:27>select * from setup_actors;
+------+------+------+
| HOST | USER | ROLE |
+------+------+------+
| % | % | % |
+------+------+------+
2.setup_consumers表用于配置事件的消费者类型,即收集的事件最终会写入到哪些统计表中。
root@performance_schema 05:48:16>select * from setup_consumers;
+--------------------------------+---------+
| NAME | ENABLED |
+--------------------------------+---------+
| events_stages_current | NO |
| events_stages_history | NO |
| events_stages_history_long | NO |
| events_statements_current | YES |
| events_statements_history | NO |
| events_statements_history_long | NO |
| events_waits_current | NO |
| events_waits_history | NO |
| events_waits_history_long | NO |
| global_instrumentation | YES |
| thread_instrumentation | YES |
| statements_digest | YES |
+--------------------------------+---------+
可以看到有12个consumer,如果不想关注某些consumer,可以将ENABLED设置为NO,比如events_statements_history_long设置为NO,
则收集事件不会写入到对应的表events_statements_history_long中。12个consumer不是平级的,存在多级层次关系。具体如下表:
global_instrumentation
|– thread_instrumentation
|– events_waits_current
|– events_waits_history
|– events_waits_history_long
|– events_stages_current
|– events_stages_history
|– events_stages_history_long
|– events_statements_current
|– events_statements_history
|– events_statements_history_long
|– statements_digest
多层次的consumer遵从一个基本原则,只有上一层次的为YES,才会继续检查该本层为YES or NO。global_instrumentation是最高级别consumer,如果它设置为NO,则所有的consumer都会忽略。如果只打开global_instrumentation,而关闭所有其它子consumer(设置为NO),则只收集全局维度的统计信息,比如xxx_instance表,而不会收集用户维度,语句维度的信息。第二层次的是thread_instrumentation,用户线程维度的统计信息,比如xxx_by_thread表,另外一个是statements_digest,这个用于全局统计SQL-digest的信息。第三层次是语句维度,包括events_waits_current,events_stages_current和events_statements_current,分别用于统计wait,stages和statement信息,第四层次是历史表信息,主要包括xxx_history和xxx_history_long。
3.setup_instruments表用于配置一条条具体的instrument,主要包含4大类:idle,stage/xxx,statement/xxx,wait/xxx.
root@performance_schema 06:25:50>select name,count(*) from setup_instruments group by LEFT(name,5);
+---------------------------------+----------+
| name | count(*) |
+---------------------------------+----------+
| idle | 1 |
| stage/sql/After create | 111 |
| statement/sql/select | 170 |
| wait/synch/mutex/sql/PAGE::lock | 296 |
+---------------------------------+----------+
idle表示socket空闲的时间,stage类表示语句的每个执行阶段的统计,statement类统计语句维度的信息,wait类统计各种等待事件,比如IO,mutux,spin_lock,condition等。从上表统计结果来看,可以基本看到每类的instrument数目,stage包含111个,statement包含170个,wait包含296个。
4.setup_objects表用于配置监控对象,默认情况下所有mysql,performance_schema和information_schema中的表都不监控。而其它DB的所有表都监控。
root@performance_schema 06:25:55>select * from setup_objects;
+-------------+--------------------+-------------+---------+-------+
| OBJECT_TYPE | OBJECT_SCHEMA | OBJECT_NAME | ENABLED | TIMED |
+-------------+--------------------+-------------+---------+-------+
| TABLE | mysql | % | NO | NO |
| TABLE | performance_schema | % | NO | NO |
| TABLE | information_schema | % | NO | NO |
| TABLE | % | % | YES | YES |
+-------------+--------------------+-------------+---------+-------+
5.setup_timers表用于配置每种类型指令的统计时间单位。MICROSECOND表示统计单位是微妙,CYCLE表示统计单位是时钟周期,时间度量与CPU的主频有关,NANOSECOND表示统计单位是纳秒,关于每种类型的具体含义,可以参考performance_timer这个表。由于wait类包含的都是等待事件,单个SQL调用次数比较多,因此选择代价最小的度量单位cycle。但无论采用哪种度量单位,最终统计表中统计的时间都会装换到皮秒。
root@performance_schema 06:29:50>select * from setup_timers;
+-----------+-------------+
| NAME | TIMER_NAME |
+-----------+-------------+
| idle | MICROSECOND |
| wait | CYCLE |
| stage | NANOSECOND |
| statement | NANOSECOND |
+-----------+-------------+
配置方式
默认情况下,setup_instruments表只打开了statement和wait/io部分的指令,setup_consumer表中很多consumer也没有打开。为了打开需要的选项,可以通过update语句直接修改配置表,并且修改后可以立即生效,但这种方式必需得启动服务器后才可以修改,并且无法持久化,重启后,又得重新设置一遍。从5.6.4开始提供了my.cnf的配置方式,格式如下:
1.设置采集的instrument
performance_schema_instrument='instrument_name=value'
(1)打开wait类型的指令
performance_schema_instrument='wait/%'
(2)打开所有指令
performance_schema_instrument='%=on'
2.设置consumer
performance_schema_consumer_xxx=value
(1)打开 events_waits_history consumer
performance_schema_consumer_events_waits_current=on
performance_schema_consumer_events_waits_history=on
这里要注意consumer的层次关系, events_waits_history处于第4层,因此设置它时,要确保events_statements_current,thread_instrumentation和global_instrumentation的ENABLED状态都为YES,才能生效。由于默认thread_instrumentation和global_instrumentation都是YES,因此只需要显示设置events_waits_current和events_waits_current即可。
3.设置统计表大小
所有的performance_schema表均采用PERFORMANCE_SCHEMA存储引擎,表中的所有数据只存在内存,表的大小在系统初始化时已经
固定好,因此占用的内存是一定的。可以通过配置来定制具体每个表的记录数。
performance_schema_events_waits_history_size=20
performance_schema_events_waits_history_long_size=15000
MySQL Performance-Schema(一) 配置篇的更多相关文章
- MySQL Performance Schema详解
MySQL的performance schema 用于监控MySQL server在一个较低级别的运行过程中的资源消耗.资源等待等情况. 1 performance schema特点 提供了一种在数据 ...
- centos+php+coreseek+sphinx+mysql之二sphinx配置篇
先进入文件夹进行以下操作 cd /usr/local/coreseek/etc cp sphinx.conf.dist sphinx.conf source src1 { sql_host = 127 ...
- mysql performance schema的即时诊断工具-邱伟胜
https://github.com/noodba http://www.noodba.com
- [MySQL Reference Manual] 23 Performance Schema结构
23 MySQL Performance Schema 23 MySQL Performance Schema 23.1 性能框架快速启动 23.2 性能框架配置 23.2.1 性能框架编译时配置 2 ...
- MySQL 5.7 Performance Schema 详解
refman mysql 5.7 MySQL Performance Schema 用于监视MySQL服务器,且运行时消耗很少的性能.Performance Schema 收集数据库服务器性能参数, ...
- Linux下MySQL数据库主从同步配置
说明: 操作系统:CentOS 5.x 64位 MySQL数据库版本:mysql-5.5.35 MySQL主服务器:192.168.21.128 MySQL从服务器:192.168.21.129 准备 ...
- MySQL sys Schema 简单介绍-1
参考文档: MySQL- 5.7 sys schema笔记 MySQL 5.7新特性:SYS库详解 MySQL Performance Schema&sys Schema介绍 内存分配统计视图 ...
- Mysql之performance Schema
Performance schema是用于监控Mysql执行,具有如下特征: 1.用于在运行时探查Mysql Server的执行过程,是由Performance_schema引擎和 Performan ...
- MySQL调优性能监控之performance schema
一.performance_schema的介绍 performance:性能 schema:图(表)示,以大纲或模型的形式表示计划或理论. MySQL的performance schema 用于监控M ...
- Profiling MySQL queries from Performance Schema
转自:http://www.percona.com/blog/2015/04/16/profiling-mysql-queries-from-performance-schema/ When opti ...
随机推荐
- 【Java心得总结五】Java容器上——容器初探
在数学中我们有集合的概念,所谓的一个集合,就是将数个对象归类而分成为一个或数个形态各异的大小整体. 一般来讲,集合是具有某种特性的事物的整体,或是一些确认对象的汇集.构成集合的事物或对象称作元素或是成 ...
- norflash驱动编写笔记
[部分转自]http://blog.csdn.net/ziyiyunmen/article/details/9744901 1. 读数据 md.b 0 2. 读ID NOR手册上: 往地址555H写A ...
- 原创:经验分享:微信小程序外包接单常见问题及流程
从九月底内测到现在已经三个半月.凌晨一点睡觉已经习以为常,也正是这样,才让无前端经验的我做微信小程序开发并不感到费劲.最近才开始接微信小程序的外包项目,目前已经签下了五份合同,成品出了两个.加上转给朋 ...
- 【字符编码】Java字符编码详细解答及问题探讨
一.前言 继上一篇写完字节编码内容后,现在分析在Java中各字符编码的问题,并且由这个问题,也引出了一个更有意思的问题,笔者也还没有找到这个问题的答案.也希望各位园友指点指点. 二.Java字符编码 ...
- using语法糖详解 2015-01-06 17:45 50人阅读 评论(0) 收藏
前段事件在using外套try catch 突然想到,如果出现异常 会不会执行释放,不执行的话那服务器很可能导致崩溃... 特意上了CSDN问了大神..得到了答案.. Using相等于try catc ...
- centos6搭建gitlab
前言 原来的项目放在公网的gitlab上,处于安全考虑,在内网搭建一套,有图形界面,可以直接从外网git导入进来,使用了一下觉得挺方便,把安装流程记录下来,参考官网:https://gitlab.co ...
- animation-fill-mode的一些思考
animation-fill-mode是css3动画的一个属性,它能够控制元素在动画执行前与动画完成后的样式.一个带有延迟,并且按正常方向执行的动画(正常方向是指从0%运行到100%),执行一次的过程 ...
- FreeRTOS 中断优先级嵌套错误引发HardFault异常解决(转)
最近在使用FreeRTOS的时候,突然发现程序在运行了几分钟之后所有的任务都不再调用了,只有几个中断能正常使用,看来是系统挂掉了,连续测试了几次想找出问题,可是这个真的有点不知所措. 我 ...
- WebApi设置SessionState为Required
public override void Init() { //在注册管道事件中 require session state //只能在引发“HttpApplication.AcquireReques ...
- 解决BUG:CS1617: 选项“6”对 /langversion 无效;必须是 ISO-1、ISO-2、3、4、5 或 Default
vs 2015的项目用vs2013,更改.net版本之后,打开会报以下错误,原因是配置文件修改出了问题.已经验证是BUG 你只需要把Web.config换成以前的就好了. https://conn ...