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(一) 配置篇的更多相关文章

  1. MySQL Performance Schema详解

    MySQL的performance schema 用于监控MySQL server在一个较低级别的运行过程中的资源消耗.资源等待等情况. 1 performance schema特点 提供了一种在数据 ...

  2. centos+php+coreseek+sphinx+mysql之二sphinx配置篇

    先进入文件夹进行以下操作 cd /usr/local/coreseek/etc cp sphinx.conf.dist sphinx.conf source src1 { sql_host = 127 ...

  3. mysql performance schema的即时诊断工具-邱伟胜

    https://github.com/noodba http://www.noodba.com

  4. [MySQL Reference Manual] 23 Performance Schema结构

    23 MySQL Performance Schema 23 MySQL Performance Schema 23.1 性能框架快速启动 23.2 性能框架配置 23.2.1 性能框架编译时配置 2 ...

  5. MySQL 5.7 Performance Schema 详解

    refman mysql 5.7 MySQL Performance Schema  用于监视MySQL服务器,且运行时消耗很少的性能.Performance Schema 收集数据库服务器性能参数, ...

  6. Linux下MySQL数据库主从同步配置

    说明: 操作系统:CentOS 5.x 64位 MySQL数据库版本:mysql-5.5.35 MySQL主服务器:192.168.21.128 MySQL从服务器:192.168.21.129 准备 ...

  7. MySQL sys Schema 简单介绍-1

    参考文档: MySQL- 5.7 sys schema笔记 MySQL 5.7新特性:SYS库详解 MySQL Performance Schema&sys Schema介绍 内存分配统计视图 ...

  8. Mysql之performance Schema

    Performance schema是用于监控Mysql执行,具有如下特征: 1.用于在运行时探查Mysql Server的执行过程,是由Performance_schema引擎和 Performan ...

  9. MySQL调优性能监控之performance schema

    一.performance_schema的介绍 performance:性能 schema:图(表)示,以大纲或模型的形式表示计划或理论. MySQL的performance schema 用于监控M ...

  10. Profiling MySQL queries from Performance Schema

    转自:http://www.percona.com/blog/2015/04/16/profiling-mysql-queries-from-performance-schema/ When opti ...

随机推荐

  1. cordova plugin add出现CERT_UNTRUSTED错误解决方法

    介绍 目前使用ionic+cordova完成hybmid app开发,在安装geolocation插件时爆出来一个莫名的错误: Fetching from npm failed: CERT_UNTRU ...

  2. 使用Jquery的Ajax实现无刷新更新,修改,删除页面

    本文将向大家讲述一下最近工作的一些总结,主要包括了以下内容,注册界面以及详细信息界面的编辑.主要是介绍了AJAX技术,因为我觉得其他方面没什么好介绍的.首先是跟大家说一下Ajax的优点,假如你删除了一 ...

  3. 使用dynamic linq 解决自定义查询的若干弊端

    在项目中想必大家肯定是使用各种ORM, 如:NH.EF.fluent Data. 然而我在使用ORM的这几年中,随着数据库的结构越来越复杂,自定义查询的越来越多,但是一直没有解决一个问题就是自定义查询 ...

  4. 使用代码为textview设置drawableLeft

    xml中的textView中设置android:drawableLeft: <TextView android:id="@+id/bookTitle" android:lay ...

  5. winform只允许一个应用程序运行 2014-12-08 09:51 31人阅读 评论(0) 收藏

    使用互斥体Mutex类型 导入命名空间 using System.Threading; //声明互斥体 Mutex mutex = new Mutex(false, "ThisShouldO ...

  6. 一个简单的WPF字体选择器实现

    很久没有写博客了. 这是放暑假中的第一篇博客,以后会多多更新!!! 这就是我写的一个字体选择器,界面如下: 本程序用到的技术比较简单,仅仅是用了Font类的几个方法和数据绑定而已. 首先建一个四行两列 ...

  7. C++中关于[]静态数组和new分配的动态数组的区别分析

    这篇文章主要介绍了C++中关于[]静态数组和new分配的动态数组的区别分析,很重要的概念,需要的朋友可以参考下 本文以实例分析了C++语言中关于[]静态数组和new分配的动态数组的区别,可以帮助大家加 ...

  8. sqlHelper做增删改查,SQL注入处理,存储值,cookie,session

    一.存储值 eg:登录一个页面,在进入这个页面之前你怎么知道它登没登录呢?[在登录成功之后我们把状态保存起来] 存储值得方式有两种,一种是cookie,一种是session 1.1区别: 代码: if ...

  9. js 与JQuery显示及隐藏方法

    虽然以后两种方式都能让文本信息隐藏和显示 第一种文本隐藏以后还是会占居位置, 第二种则不会占位置. <p id="p1">这是一段文本.</p> <i ...

  10. ObjectStream 及 序列化 介绍

    ObjectInputStream 和 ObjectOutputStream 介绍 ObjectInputStream 和 ObjectOutputStream 的作用是,对基本数据和对象进行序列化操 ...