MySQL源代码:由参数query_response_time_stats想到的
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
|
评论暂时关闭