{"id":126,"date":"2014-03-19T00:45:42","date_gmt":"2014-03-19T00:45:42","guid":{"rendered":"http:\/\/aadant.com\/blog\/?p=126"},"modified":"2014-03-19T00:55:06","modified_gmt":"2014-03-19T00:55:06","slug":"performance_schema-success-stories-host-summary-tables","status":"publish","type":"post","link":"http:\/\/aadant.com\/blog\/2014\/03\/19\/performance_schema-success-stories-host-summary-tables\/","title":{"rendered":"Performance_schema success stories : host summary tables"},"content":{"rendered":"<p>This question was asked at support by a customer to solve a difficult issue.<\/p>\n<p><strong>How to identify a sporadic burst of queries coming from one of the hosts accessing the database ?<\/strong><\/p>\n<p>If there are hundreds of hosts, it can be challenging, especially if the queries are fast. No chance for them to get logged in the famous slow query log !<\/p>\n<p>Here is the solution using the performance_schema in MySQL 5.6 :<\/p>\n<pre class=\"lang:mysql decode:true\" title=\"Using the performance_schema and ps_helper.format_time\">SELECT\r\nhost,\r\nSUM(essbben.count_star) AS total_statements,\r\nformat_time(SUM(essbben.sum_timer_wait)) AS total_latency,\r\nformat_time(SUM(essbben.sum_timer_wait) \/ SUM(count_star))\r\nAS avg_latency\r\nFROM\r\nperformance_schema.events_statements_summary_by_host_by_event_name essbben\r\nGROUP BY\r\nhost\r\nORDER BY\r\nSUM(sum_timer_wait) DESC;<\/pre>\n<p>Here is the result :<\/p>\n<pre class=\"font:consolas lang:default mark:5 decode:true\">+---------------+------------------+---------------+-------------+\r\n| host          | total_statements | total_latency | avg_latency |\r\n+---------------+------------------+---------------+-------------+\r\n|     localhost |            30791 |         1.22h |   143.19 ms | \r\n|         host1 |          6576077 |         1.14h |   622.17 us |\r\n|         host2 |            53531 |   00:28:56.92 |   324.46 us |\r\n...<\/pre>\n<p>Note that if you use the thread pool plugin, you need to upgrade to 5.6.15 or later because of this bug :\u00a0Bug 17049691 : PROCESSLIST_USER AND PROCESSLIST_HOST ARE ALWAYS NULL WITH THREAD_POOL.<\/p>\n<p>If you want to determine when the burst occurs, you can create an event or a cron job to load the results in a table like this :<\/p>\n<pre class=\"lang:mysql decode:true\">create table log_host\r\n(snapshot_time datetime, host varchar(60), \u00a0total_statements bigint, total_latency bigint) engine=InnoDB;\r\n-- script to run to archive the snapshot\r\nset @now = (select NOW());\r\ninsert into log_host(snapshot_time, host, total_statements, total_latency) SELECT @now, host,\r\n\u00a0 \u00a0SUM(essbben.count_star) AS total_statements,\r\n\u00a0 \u00a0SUM(essbben.sum_timer_wait) AS total_latency\r\n\u00a0 \u00a0FROM\r\n\u00a0 \u00a0performance_schema.events_statements_summary_by_host_by_event_name essbben\r\n\u00a0 \u00a0WHERE 1 = 1\r\n\u00a0 \u00a0GROUP BY host\r\n\u00a0 \u00a0ORDER BY SUM(sum_timer_wait) DESC;<\/pre>\n<p>I created a <a href=\"https:\/\/github.com\/MarkLeith\/mysql-sys\/pull\/3\">pull request<\/a> for mysql-sys, so that host based P_S tables can be accessed using sys views and possibly from MySQL Workbench 6.1.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This question was asked at support by a customer to solve a difficult issue. How to identify a sporadic burst of queries coming from one of the hosts accessing the database ? If there are hundreds of hosts, it can &hellip; <a href=\"http:\/\/aadant.com\/blog\/2014\/03\/19\/performance_schema-success-stories-host-summary-tables\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[8,9,6,1],"tags":[],"class_list":["post-126","post","type-post","status-publish","format-standard","hentry","category-performance_schema","category-success-stories","category-tip","category-uncategorized"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/aadant.com\/blog\/wp-json\/wp\/v2\/posts\/126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/aadant.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/aadant.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/aadant.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/aadant.com\/blog\/wp-json\/wp\/v2\/comments?post=126"}],"version-history":[{"count":13,"href":"http:\/\/aadant.com\/blog\/wp-json\/wp\/v2\/posts\/126\/revisions"}],"predecessor-version":[{"id":139,"href":"http:\/\/aadant.com\/blog\/wp-json\/wp\/v2\/posts\/126\/revisions\/139"}],"wp:attachment":[{"href":"http:\/\/aadant.com\/blog\/wp-json\/wp\/v2\/media?parent=126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/aadant.com\/blog\/wp-json\/wp\/v2\/categories?post=126"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/aadant.com\/blog\/wp-json\/wp\/v2\/tags?post=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}