mysql  performance_schema 初探:

mysql 5.5 版本 新增了一个性能优化的引擎: PERFORMANCE_SCHEMA

这个功能默认是关闭的:

需要设置参数: performance_schema  才可以启动该功能,这个参数是静态参数,只能写在my.cnf 中

不能动态修改。

先看看有什么东西吧:

mysql> use performance_schema;
Database changed
mysql> show tables ;
+----------------------------------------------+
| Tables_in_performance_schema                 |
+----------------------------------------------+
| cond_instances                               |
| events_waits_current                         |
| events_waits_history                         |
| events_waits_history_long                    |
| events_waits_summary_by_instance             |
| events_waits_summary_by_thread_by_event_name |
| events_waits_summary_global_by_event_name    |
| file_instances                               |
| file_summary_by_event_name                   |
| file_summary_by_instance                     |
| mutex_instances                              |
| performance_timers                           |
| rwlock_instances                             |
| setup_consumers                              |
| setup_instruments                            |
| setup_timers                                 |
| threads                                      |
+----------------------------------------------+
17 rows in set (0.00 sec)

这里的数据表分为几类:

1) setup table :  设置表,配置监控选项。

2) current events table : 记录当前那些thread 正在发生什么事情。

3) history table  发生的各种事件的历史记录表

4) summary table  对各种事件的统计表

5) 杂项表,乱七八糟表。

setup 表:

mysql> SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
    -> WHERE TABLE_SCHEMA = 'performance_schema'
    -> AND TABLE_NAME LIKE 'setup%';
+-------------------+
| TABLE_NAME        |
+-------------------+
| setup_consumers   |
| setup_instruments |
| setup_timers      |
+-------------------+

setup_consumers 描述各种事件

setup_instruments 描述这个数据库下的表名以及是否开启监控。

setup_timers   描述 监控选项已经采样频率的时间间隔

这个要多说一点 目前 performance-schema  只支持 'wait'  时间的监控,代码树上 wait/ 下的函数都可以监控到。

文档上说了只有 'wait' 事件的检测,有没有其他的选项呢?

看看源代码

static row_setup_timers all_setup_timers_data[COUNT_SETUP_TIMERS]=
{
  {
    { C_STRING_WITH_LEN("wait") },
    &wait_timer
  }
};

THR_LOCK table_setup_timers::m_table_lock;

int table_setup_timers::update_row_values(TABLE *table,
                                          const unsigned char *,
                                          unsigned char *,
                                          Field **fields)
{
  Field *f;
  longlong value;

DBUG_ASSERT(m_row);

for (; (f= *fields) ; fields++)
  {
    if (bitmap_is_set(table->write_set, f->field_index))
    {
      switch(f->field_index)
      {
      case 0: /* NAME */
        my_error(ER_WRONG_PERFSCHEMA_USAGE, MYF(0));
        return HA_ERR_WRONG_COMMAND;
      case 1: /* TIMER_NAME */
        value= get_field_enum(f);
        if ((value >= FIRST_TIMER_NAME) && (value <= LAST_TIMER_NAME))
          *(m_row->m_timer_name_ptr)= (enum_timer_name) value;
        else
          return HA_ERR_WRONG_COMMAND;
        break;
      default:
        DBUG_ASSERT(false);
      }
    }
  }

return 0;
}

代码里写死了,只有 'wait' 一个值,不排除以后的版本会增加新的关键字,但至少目前就只有一个啦。
并且这个表的name 字段是不允许修改的的。 下面的修改的方法里没有做任何处理,涉及到name字段的修改,直接报错。

mysql> SELECT * FROM setup_timers;
+------+------------+
| NAME | TIMER_NAME |
+------+------------+
| wait | CYCLE      |
+------+------------+
只有 timer_name 可以update 这是一个enum 字段。

性能事件表:

mysql> SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
    -> WHERE TABLE_SCHEMA = 'performance_schema'
    -> AND TABLE_NAME LIKE '%current';
+----------------------+
| TABLE_NAME           |
+----------------------+
| events_waits_current |
+----------------------+

记录当前正在发生的等待事件,这个表是只读的表,不能update ,delete ,但是可以truncate

具体字段是什么意思就自己去查doc 了,这里不说了。

性能历史表:

mysql> SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
    -> WHERE TABLE_SCHEMA = 'performance_schema'
    -> AND (TABLE_NAME LIKE '%history' OR TABLE_NAME LIKE '%history_long');
+---------------------------+
| TABLE_NAME                |
+---------------------------+
| events_waits_history      |
| events_waits_history_long |
+---------------------------+

这些表与前面的性能表的结构是一致的, history 表只保留每个线程(thread) 的最近的10个事件, history_long 记录最近的10000个事件。

新事件如表,如果旧表满了,就会丢弃旧的数据,标准的先进先出(FIFO)  这俩表也是只读表,只能truncate

事件汇总表:

mysql> SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
    -> WHERE TABLE_SCHEMA = 'performance_schema'
    -> AND TABLE_NAME LIKE '%summary%';
+----------------------------------------------+
| TABLE_NAME                                   |
+----------------------------------------------+
| events_waits_summary_by_instance             |
| events_waits_summary_by_thread_by_event_name |
| events_waits_summary_global_by_event_name    |
| file_summary_by_event_name                   |
| file_summary_by_instance                     |
+----------------------------------------------+

按照相关的标准对进行的事件统计表,

events_waits_summary_global_by_event_name     在mysql5.5.7 以前叫: EVENTS_WAITS_SUMMARY_BY_EVENT_NAME

表也是只读的,只能turcate

performance  schema  instance 表:

mysql> SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
    -> WHERE TABLE_SCHEMA = 'performance_schema'
    -> AND TABLE_NAME LIKE '%instances';
+------------------+
| TABLE_NAME       |
+------------------+
| cond_instances   |
| file_instances   |
| mutex_instances  |
| rwlock_instances |
+------------------+

记录各种等待事件涉及到的实例  :  主要是3类:  cond  (容器? ) mutex (互斥锁) ,rwlock (读写锁)

这表是只读的。

乱七八糟表:

mysql> SELECT * FROM performance_timers;
+-------------+-----------------+------------------+----------------+
| TIMER_NAME  | TIMER_FREQUENCY | TIMER_RESOLUTION | TIMER_OVERHEAD |
+-------------+-----------------+------------------+----------------+
| CYCLE       |      2389029850 |                1 |             72 |
| NANOSECOND  |            NULL |             NULL |           NULL |
| MICROSECOND |         1000000 |                1 |            585 |
| MILLISECOND |            1035 |                1 |            738 |
| TICK        |             101 |                1 |            630 |
+-------------+-----------------+------------------+----------------+

这个表式只读表,记录了事件采样频率的设定,我们前面说的setup_timer 表的timer_name 只能区这4个中一个。

mysql> SELECT * FROM threads;
+-----------+----------------+----------------------------------------+
| THREAD_ID | PROCESSLIST_ID | NAME                                   |
+-----------+----------------+----------------------------------------+
|         0 |              0 | thread/sql/main                        |
|         1 |              0 | thread/innodb/io_handler_thread        |
|        16 |              0 | thread/sql/signal_handler              |
|        23 |              7 | thread/sql/one_connection              |
|         5 |              0 | thread/innodb/io_handler_thread        |
|        12 |              0 | thread/innodb/srv_lock_timeout_thread  |
|        22 |              6 | thread/sql/one_connection              |

这个表记录了系统里当前存在的各种线程。

下面就是 涉及到performance_schema的各个系统参数了:

mysql> SHOW VARIABLES LIKE 'perf%';
+---------------------------------------------------+---------+
| Variable_name                                     | Value   |
+---------------------------------------------------+---------+
| performance_schema                                | ON      |
| performance_schema_events_waits_history_long_size | 10000   |
| performance_schema_events_waits_history_size      | 10      |
| performance_schema_max_cond_classes               | 80      |
| performance_schema_max_cond_instances             | 1000    |
| performance_schema_max_file_classes               | 50      |
| performance_schema_max_file_handles               | 32768   |
| performance_schema_max_file_instances             | 10000   |
| performance_schema_max_mutex_classes              | 200     |
| performance_schema_max_mutex_instances            | 1000000 |
| performance_schema_max_rwlock_classes             | 30      |
| performance_schema_max_rwlock_instances           | 1000000 |
| performance_schema_max_table_handles              | 100000  |
| performance_schema_max_table_instances            | 50000   |
| performance_schema_max_thread_classes             | 50      |
| performance_schema_max_thread_instances           | 1000    |
+---------------------------------------------------+---------+

涉及到系统状态的参数:
mysql> SHOW STATUS LIKE 'perf%';
+------------------------------------------+-------+
| Variable_name                            | Value |
+------------------------------------------+-------+
| Performance_schema_cond_classes_lost     | 0     |
| Performance_schema_cond_instances_lost   | 0     |
| Performance_schema_file_classes_lost     | 0     |
| Performance_schema_file_handles_lost     | 0     |
| Performance_schema_file_instances_lost   | 0     |
| Performance_schema_locker_lost           | 0     |
| Performance_schema_mutex_classes_lost    | 0     |
| Performance_schema_mutex_instances_lost  | 0     |
| Performance_schema_rwlock_classes_lost   | 0     |
| Performance_schema_rwlock_instances_lost | 0     |
| Performance_schema_table_handles_lost    | 0     |
| Performance_schema_table_instances_lost  | 0     |
| Performance_schema_thread_classes_lost   | 0     |
| Performance_schema_thread_instances_lost | 0     |
+------------------------------------------+-------+

如何使用这个,来诊断数据库性能问题呢 ? 且听下回分解!

mysql performance_schema 初探的更多相关文章

  1. MYSQL PERFORMANCE_SCHEMA HINTS

    ACCOUNTS NOT PROPERLY CLOSING CONNECTIONS [ 1 ] Works since 5.6 SELECT ess.user, ess.host , (a.total ...

  2. MySQL 日志初探

    目录 MySQL 日志初探 零.概述 一.Error Log(错误日志) 二.General Query Log(通用查询日志) 三.Slow Query Log (慢查询日志) 四.Binary L ...

  3. mysql视图初探

    mysql视图初探 官方例子如下,从官方的例子就可以看出来视图就是提供一种快捷查询.用视图来查询一些常用的结果. mysql> help create view; Name: 'CREATE V ...

  4. mysql performance_schema 和information_schema.tables了解

    这个是关于mysql的系统表,性能表,核心表操作的一些介绍,深入算不上 我们一般很少去动 mysql  information_schema 信息相关  performance_schema 性能相关 ...

  5. mysql performance_schema/information_schema授权问题

    mysql> grant all on performance_schema.* to 'testuser'@'%';ERROR 1044 (42000): Access denied for ...

  6. MySQL全文检索初探

    本文目的 最近有个项目需要对数据进行搜索功能.采用的LAMP技术开发,所以自然想到了MySQL的全文检索功能.现在将自己搜集的一些资料小结,作为备忘. MySQL引擎 据目前查到的资料,只有MyISA ...

  7. MySQL索引初探

    一.什么是索引? 帮助数据库系统实现高效获取数据的数据结构 索引可以帮助我们快速地定位到数据而不需要每次搜索的时候都遍历数据库中的每一行. 二.常见实现方式有哪些? 常见索引模型有三种:哈希表.有序数 ...

  8. 转 mysql 存储过程初探

    https://www.cnblogs.com/qmfsun/p/4838032.htmlMySQL命令执行sql文件的两种方法 https://www.cnblogs.com/mark-chan/p ...

  9. mysql 存储过程初探

    使用存储过程好处在于: 1.隐藏敏感的算法,避免被正常的开发人员看到,把业务逻辑隐藏在数据库中,而非程序代码里 2.简化应用代码程序,放到数据库里肯定就对程序代码简化有好处了 3.不同的开发语言都可以 ...

随机推荐

  1. Java API ——Collection集合类 & Iterator接口

    对象数组举例: 学生类: package itcast01; /** * Created by gao on 15-12-9. */ public class Student { private St ...

  2. 完美配置Tomcat的HTTPS

    Tomcat配置HTTPS的文章到处都有,过程也比较简单,随后文中会转一段过来. 但对于启用APR情况下报异常“java.lang.Exception: Connector attribute SSL ...

  3. linux下操作PostgreSQL的常用命令

    一般性: \copyright 显示PostgreSQL的使用和发行许可条款          \g [文件] or; 执行查询 (并把结果写入文件或 |管道) \h [名称] SQL命令语法上的说明 ...

  4. redis sentinel 配置

    在最小配置:master.slave各一个节点的情况下,不管是master还是slave down掉一个,“完整的”读/写功能都将受影响,这在生产环境中显然不能接受.幸好redis提供了sentine ...

  5. Java关键字static、final使用小结

    static  1. static变量     按照是否静态的对类成员变量进行分类可分两种:一种是被static修饰的变量,叫静态变量或类变量:另一种是没有被static修饰的变量,叫实例变量.两者的 ...

  6. next_permutation()函数 和 prev_permutation() 按字典序求全排列

    next_permutation功能:    求一个排序的下一个排列的函数,可以遍历全排列,要包含头文件<algorithm> 与之完全相反的函数还有prev_permutation 这个 ...

  7. iOS开发:iOS的整体架构以及API介绍

    iOS的整体架构分为4层——Cocoa Touch层.Media层.Core Services层和Core OS层,下面概要介绍一下这4层. Cocoa Touch:构建iOS应用的一些基本系统服务, ...

  8. BZOJ_1624_ [Usaco2008_Open]_Clear_And_Present_Danger_寻宝之路_(最短路_Floyd)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1025 给出\(n\)个点以及之间的边的长度,给出必须访问的点的顺序,求最短路线长度. 分析 用 ...

  9. 修改数据库中group_concat的返回结果的长度限制

    修改数据库中group_concat的返回结果的长度限制 我们可以使用Mysql的客户端管理工具,Sqlyog 新建一个查询编辑器 显示  SHOW VARIABLES LIKE "grou ...

  10. uvalive 3523 Knights of the Round Table 圆桌骑士(强连通+二分图)

    题目真心分析不出来.看了白书才明白,不过有点绕脑. 容易想到,把题目给的不相邻的关系,利用矩阵,反过来建图.既然是全部可行的关系,那么就应该能画出含奇数个点的环.求环即是求双连通分量:找出所有的双连通 ...