Percona provides the query_response_time_stats parameter to observe the database Response Time on the server side.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)
Set this global variable to 'on' to observe the response time.
Root @ test 02:29:47> set globalquery_response_time_stats = 'on ';
Query OK, 0 rows affected (0.00 sec)
The response time information is recorded in a built-in I _S plug-in: QUERY_RESPONSE_TIME. Its structure is as follows and contains three fields:
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 |
| 1, 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 indicates the RT interval (you can set it by the query_response_time_range_base parameter). count indicates the number of SQL statements collected in the interval, and total indicates the total execution time of these SQL statements.
This I _s table is implemented in the Code SQL/query_response_time.cc. Initialize (empty function) at system startup (init_server_components function) and declare the built-in I _s table in SQL _show.cc
Field definition:
ST_FIELD_INFO query_response_time_fields_info []
The definition in the I _s table description array (ST_SCHEMA_TABLEschema_tables []) is as follows:
# 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