Welcome 微信登录

首页 / 数据库 / MySQL / MySQL源代码:由参数query_response_time_stats想到的

Percona提供了一个参数query_response_time_stats用于在服务器端观察数据库的响应时间

root@test 02:29:35>show variables like"query_response_time_stats";

+---------------------------+-------+| Variable_name             | Value |+---------------------------+-------+| query_response_time_stats | OFF   |+---------------------------+-------+1 row in set (0.00 sec) 将这个全局变量设置为‘ON’即可观察响应时间root@test 02:29:47>set globalquery_response_time_stats = "ON";Query OK, 0 rows affected (0.00 sec) 响应时间信息被记录在一个内建的I_S 插件中:QUERY_RESPONSE_TIME,其结构如下,包含3个字段:root@information_schema 02:56:37>desc QUERY_RESPONSE_TIME;+-------+------------------+------+-----+---------+-------+| Field | Type            | Null | Key | Default | Extra |+-------+------------------+------+-----+---------+-------+| time  | varchar(14)      | NO  |     |         |      || count | int(11) unsigned | NO   |    | 0       |       || total | varchar(14)     | NO   |     |        |       |+-------+------------------+------+-----+---------+-------+3 rows in set (0.00 sec) root@information_schema 04:28:01>select * from QUERY_RESPONSE_TIME;+----------------+-------+----------------+| time           |count | total          |+----------------+-------+----------------+|       0.000001|     0 |       0.000000 ||       0.000010|     0 |       0.000000 ||       0.000100|    16 |       0.000697 ||       0.001000|    11 |       0.002144 ||       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       |+----------------+-------+----------------+ 其中time代表RT区间(可以通过参数query_response_time_range_base)来设置,count表示该区间里收集的SQL数,total表示这些SQL的执行总时间在代码sql/query_response_time.cc里实现了该i_s表。在系统启动时(init_server_components函数)进行初始化(空函数),在sql_show.cc里声明内建i_s表字段定义:ST_FIELD_INFO  query_response_time_fields_info[]在i_s表描述数组(ST_SCHEMA_TABLEschema_tables[])中的定义如下:#ifdef  HAVE_RESPONSE_TIME_DISTRIBUTION  {"QUERY_RESPONSE_TIME",query_response_time_fields_info, create_schema_table,   query_response_time_fill, make_old_format,0, -1, -1, 0, 0},#else  {"QUERY_RESPONSE_TIME",query_response_time_fields_info, create_schema_table,   0, make_old_format, 0, -1, -1, 0, 0},#endif //HAVE_RESPONSE_TIME_DISTRIBUTION
  • 1
  • 2
  • 下一页
MySQL源代码:如何对读写锁进行处理MySQL:如何编写Information Schema Plugin相关资讯      MySQL基础教程 
  • MySQL基础教程:关于varchar(N)  (01月22日)
  • MySQL SELECT同时UPDATE同一张表  (02/19/2013 07:20:18)
  • Linux修改MySQL最大并发连接数  (02/15/2013 15:37:21)
  • 高性能MySQL(第3版) 中文PDF带目  (10/26/2014 10:03:50)
  • 如何在MySQL中的获取IP地址的网段  (02/18/2013 12:23:33)
  • C++和C#访问MySQL的简单代码示例  (12/21/2012 09:04:10)
本文评论 查看全部评论 (0)
表情: 姓名: 字数