{"id":15,"date":"2014-02-12T15:03:00","date_gmt":"2014-02-12T20:03:00","guid":{"rendered":"https:\/\/kimsal.com\/blog\/?p=15"},"modified":"2014-02-12T15:03:00","modified_gmt":"2014-02-12T20:03:00","slug":"mysql-speed-boost","status":"publish","type":"post","link":"https:\/\/kimsal.com\/blog\/2014\/02\/12\/mysql-speed-boost\/","title":{"rendered":"MySQL speed boost"},"content":{"rendered":"\n<p>I hit a problem the other day with concurrent queries causing deadlocks. &nbsp;Using innodb gives you a lot of protection with respect to transaction support, but it carries a moderate amount of overhead, and unless you\u2019re aware of what\u2019s going on, you may be paying a higher price which can eventually cause performance or deadlock issues.<\/p>\n\n\n\n<p>FWIW, I thought I knew what was going on, and I *sort of* did, but not entirely.<\/p>\n\n\n\n<p><a href=\"https:\/\/web.archive.org\/web\/20160617125343\/http:\/\/highscalability.com\/blog\/2011\/2\/10\/database-isolation-levels-and-their-effects-on-performance-a.html\" target=\"_blank\" rel=\"noreferrer noopener\">This article<\/a> at high scalability has some good introductory info, but I\u2019ll cut to the chase as to what made a huge improvement for me.<\/p>\n\n\n\n<p>Instead of standard BEGIN to start a transaction, I set a specific isolation level for just *one* query:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SET TRANSACTION ISOLATION LEVEL READ COMMITTED;<\/pre>\n\n\n\n<p>This took my combined queries from 18 seconds down to 3. In addition to the 18 seconds average time, those 18 seconds were often going to 30-60 depending on what other concurrent queries were going on. The default \u2018REPEATABLE_READ\u2019 transaction level in InnoDB does a lot of locking (or waiting to be able to lock) data, and this was the root of my problems.<\/p>\n\n\n\n<p>You need to understand what transaction isolation levels are doing, of course, but changing some queries to READ COMMITTED is still pretty safe for what I was doing there, and made a *HUGE* difference in speed. Of course, your mileage may vary, but definitely something to research if you haven\u2019t yet and are facing performance issues.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I hit a problem the other day with concurrent queries causing deadlocks. &nbsp;Using innodb gives you a lot of protection with respect to transaction support, but it carries a moderate amount of overhead, and unless you\u2019re aware of what\u2019s going on, you may be paying a higher price which can eventually cause performance or deadlock&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/kimsal.com\/blog\/wp-json\/wp\/v2\/posts\/15","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kimsal.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kimsal.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kimsal.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kimsal.com\/blog\/wp-json\/wp\/v2\/comments?post=15"}],"version-history":[{"count":0,"href":"https:\/\/kimsal.com\/blog\/wp-json\/wp\/v2\/posts\/15\/revisions"}],"wp:attachment":[{"href":"https:\/\/kimsal.com\/blog\/wp-json\/wp\/v2\/media?parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kimsal.com\/blog\/wp-json\/wp\/v2\/categories?post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kimsal.com\/blog\/wp-json\/wp\/v2\/tags?post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}