MySQL原始碼:由參數query_response_time_stats想到的

來源:互聯網
上載者:User

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
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.