{"id":39744,"date":"2022-10-08T19:22:52","date_gmt":"2022-10-08T12:22:52","guid":{"rendered":"https:\/\/harry.sufehmi.com\/?p=39744"},"modified":"2022-10-08T19:24:24","modified_gmt":"2022-10-08T12:24:24","slug":"your-wordpress-website-is-slow-perhaps-you-have-wp-statistics-plugin-installed","status":"publish","type":"post","link":"https:\/\/harry.sufehmi.com\/archives\/2022-10-08-your-wordpress-website-is-slow-perhaps-you-have-wp-statistics-plugin-installed\/","title":{"rendered":"Your WordPress Website is Slow? – perhaps you have WP-Statistics plugin installed?"},"content":{"rendered":"\n
\"\"<\/a><\/figure>\n\n\n\n

A few days ago a client contacted me and said that their website is down. I checked the server, and indeed the server is very overloaded. In total it got 36 cores – and they’re all 100% utilized.<\/p>\n\n\n\n

As usual I checked the whole stack, but today it’s something different – the MySQL \/ database server was the culprit. It was performing very slowly, and in turn caused the webserver to slow down as well.<\/p>\n\n\n\n

In the slow query log, some queries kept showing up with crazy query times, in tens of seconds.
For comparison – all of the other queries finishes in less than a second.<\/p>\n\n\n\n

MySQL’s slow query log is your friend – it enable you to find problematic queries very quickly.<\/p><\/blockquote>\n\n\n\n

And all those slow queries are in these tables:<\/p>\n\n\n\n

wp_statistics_useronline
wp_statistics_visitor<\/code><\/p>\n\n\n\n

I checked the currently running queries with “mysqladmin processlist<\/em>“, and almost all (hundreds of them) queued queries are those involving those tables, looking for specific content in the field “ip”. They’re all looked like these:<\/p>\n\n\n\n

SELECT location FROM wp_statistics_visitor WHERE ip = '88.88.88.88'
SELECT * FROM wp_statistics_useronline WHERE ip = '99.99.99.99'<\/code><\/p>\n\n\n\n

On a hunch, I checked the structure of those tables. And right enough, there’s no index for “ip”<\/p>\n\n\n\n

An index can increase a query’s performance by a, very, significant amount.<\/p><\/blockquote>\n\n\n\n

When the size of those tables are big enough, and you have a higher traffic than usual (they just published a very important information that’s of interest to a lot of people) – then suddenly these seemingly innocent queries were able to bring down a 36-core server to its knees.<\/p>\n\n\n\n

Anyway, now we know the culprit, the solution is easy enough:<\/p>\n\n\n\n

alter table wp_statistics_useronline add index (ip);
alter table wp_statistics_visitor add index (ip);<\/code><\/p>\n\n\n\n

And voil\u00e0 – in an instant, the website was up again, and the CPU utilization dropped to nearly zero.<\/p>\n\n\n\n

Everyone’s happy, and I have also notified<\/a> the developers about the issue as well.<\/p>\n","protected":false},"excerpt":{"rendered":"

A few days ago a client contacted me and said that their website is down. I checked the server, and indeed the server is very overloaded. In total it got 36 cores – and they’re all 100% utilized. As usual I checked the whole stack, but today it’s something different – the MySQL \/ database … Continue reading Your WordPress Website is Slow? – perhaps you have WP-Statistics plugin installed?<\/span> →<\/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":[7],"tags":[],"class_list":["post-39744","post","type-post","status-publish","format-standard","hentry","category-etc"],"_links":{"self":[{"href":"https:\/\/harry.sufehmi.com\/wp-json\/wp\/v2\/posts\/39744"}],"collection":[{"href":"https:\/\/harry.sufehmi.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/harry.sufehmi.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/harry.sufehmi.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/harry.sufehmi.com\/wp-json\/wp\/v2\/comments?post=39744"}],"version-history":[{"count":3,"href":"https:\/\/harry.sufehmi.com\/wp-json\/wp\/v2\/posts\/39744\/revisions"}],"predecessor-version":[{"id":39748,"href":"https:\/\/harry.sufehmi.com\/wp-json\/wp\/v2\/posts\/39744\/revisions\/39748"}],"wp:attachment":[{"href":"https:\/\/harry.sufehmi.com\/wp-json\/wp\/v2\/media?parent=39744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/harry.sufehmi.com\/wp-json\/wp\/v2\/categories?post=39744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/harry.sufehmi.com\/wp-json\/wp\/v2\/tags?post=39744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}