{"id":370,"date":"2015-07-01T22:14:58","date_gmt":"2015-07-01T22:14:58","guid":{"rendered":"http:\/\/www.corrspt.com\/blog\/?p=370"},"modified":"2015-07-02T08:59:42","modified_gmt":"2015-07-02T08:59:42","slug":"mysql-very-high-cpu-usage","status":"publish","type":"post","link":"http:\/\/www.corrspt.com\/blog\/2015\/07\/01\/mysql-very-high-cpu-usage\/","title":{"rendered":"MySQL very high CPU usage (and other processes)"},"content":{"rendered":"<p>Hi everyone<\/p>\n<p><strong>TL;DR (or Summary)<\/strong>\u00a0&#8211; Leap second added on 30 June 2015 caused MySQL (and other processes to have very high CPU usage)<\/p>\n<p>This is just a quick post on an issue that I faced today (01\/07\/2015). I arrived at work and found a warning from our monitoring tool that we had high cpu usage beginning at 01.00 AM. On\u00a0top we saw several processes using a very high amount of CPU, namely:<\/p>\n<ul>\n<li>mysql<\/li>\n<li>jenkins<\/li>\n<li>tomcat<\/li>\n<li>ruby (god)<\/li>\n<li>ksoftirqd (several of these)<\/li>\n<\/ul>\n<p>On Tomcat we\u00a0can have legitimate high cpu usage, but jenkins was not building anything and mysql (version 5.5.31) was not used in anything important. We ran through the logs and analytics to check if we were having an abnormally high visitor access\u00a0and found nothing, nada, zero. We logged into mysql and issued the <em>SHOW PROCESSLIST<\/em> command and <strong><em>nothing<\/em><\/strong> was happening.<\/p>\n<p>ksoftird was particularly weird, because it is &#8220;<em>is a per-cpu kernel thread that runs when the machine is under heavy soft-interrupt load&#8221; <\/em>which didn&#8217;t make any sense to us.<\/p>\n<p>What the&#8230;. ? (X-Files theme song playing in the background)<\/p>\n<p>After a certain time and more attempts (like trying to use jstack on tomcat to see if it showed anything unusual) we decided to restart mysql, tomcat, jenkins and god, but it all went back again to high cpu usage. We even restarted the server without better luck.<\/p>\n<p>We then read this <a href=\"http:\/\/stackoverflow.com\/a\/11293475\/688359\" target=\"_blank\">stack overflow question<\/a> more carefully and noticed the &#8220;leap second issue&#8221;, and someone said &#8220;hey I remember seeing something about a leap second not to long ago&#8221;&#8230; I went and check <a href=\"https:\/\/en.wikipedia.org\/wiki\/Leap_second\" target=\"_blank\">wikipedia<\/a>, and sure a leap second was added on June 30th 2015.<\/p>\n<p>We tried the following:<\/p>\n<pre class=\"lang-sql prettyprint prettyprinted\"><code><span class=\"pun\">$<\/span> <span class=\"pun\">\/<\/span><span class=\"pln\">etc<\/span><span class=\"pun\">\/<\/span><span class=\"pln\">init<\/span><span class=\"pun\">.<\/span><span class=\"pln\">d<\/span><span class=\"pun\">\/<\/span><span class=\"pln\">ntpd stop\r\n<\/span><span class=\"pun\">$<\/span><span class=\"pln\"> date <\/span><span class=\"pun\">-<\/span><span class=\"pln\">s <\/span><span class=\"str\">\"`date`\"<\/span>\r\n<span class=\"pun\">$<\/span> <span class=\"pun\">\/<\/span><span class=\"pln\">etc<\/span><span class=\"pun\">\/<\/span><span class=\"pln\">init<\/span><span class=\"pun\">.<\/span><span class=\"pln\">d<\/span><span class=\"pun\">\/<\/span><span class=\"pln\">ntpd <\/span><span class=\"kwd\">start<\/span><\/code><\/pre>\n<p>Some people said that restarting ntp was not required, but&#8230; we did it anyway \ud83d\ude42 And, <strong>it worked<\/strong>. <strong><em>Magically<\/em> everything went back to normal<\/strong>. Apparently <a href=\"http:\/\/www.wired.com\/2015\/07\/leap-second-causes-sporadic-outages-across-internet\/\" target=\"_blank\">we weren&#8217;t the only ones affected<\/a>. I think the next time I see a leap second announcement I&#8217;m going to put it on my calendar and warning to a day before \ud83d\ude42<\/p>\n<p><a href=\"https:\/\/blog.mozilla.org\/it\/2012\/06\/30\/mysql-and-the-leap-second-high-cpu-and-the-fix\/\" target=\"_blank\">Mozilla&#8217;s blog<\/a>\u00a0also documents the issue.<\/p>\n<p>I know this issue is documented, but I wanted to have one more post contributing to people finding this stuff on the internet, could save someone a couple of hours next time.<\/p>\n<p>Happy coding and stay safe of leap seconds!<\/p>\n<p>P.S &#8211; <a href=\"https:\/\/www.reddit.com\/r\/programming\/comments\/3buqys\/mysql_and_others_very_high_cpu_usage_after_leap\/\">Reddit comments over here<\/a>, <a href=\"https:\/\/news.ycombinator.com\/item?id=9817612\">Hacker News comments over here<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi everyone TL;DR (or Summary)\u00a0&#8211; Leap second added on 30 June 2015 caused MySQL (and other processes to have very high CPU usage) This is just a quick post on an issue that I faced today (01\/07\/2015). I arrived at &hellip; <a href=\"http:\/\/www.corrspt.com\/blog\/2015\/07\/01\/mysql-very-high-cpu-usage\/\">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":{"footnotes":""},"categories":[18],"tags":[37,35,36,38],"class_list":["post-370","post","type-post","status-publish","format-standard","hentry","category-linux","tag-devops","tag-linux","tag-mysql","tag-sysadmin"],"_links":{"self":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/370","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/comments?post=370"}],"version-history":[{"count":4,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/370\/revisions"}],"predecessor-version":[{"id":374,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/370\/revisions\/374"}],"wp:attachment":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/media?parent=370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/categories?post=370"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/tags?post=370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}