• Resolved milos.kostadinovic

    (@miloskostadinovic)


    Hi – we’ve been experiencing “Database connection error” on our blog. When looking into error logs we found out that a query (related to WP Popular Posts plugin) was causing this issue. It seemed like it tried to write some data into MySQL database but, for some reason, it couldn’t.

    At the same time, it caused CPU usage to be 730-750%

    Once we deactivated the WP Popular Posts plugin, everything was normal again.

    We’re using MySQL Ver 14.14 Distrib 5.6.31

    Here is the link to the error log file: https://www.dropbox.com/s/k58q4v25kex4e2j/error%20log.txt?dl=0

    Please let us know if there are any fixes for this issue or any workarounds that could help solve it.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi

    I would need some more details about your site to be sure (eg. number of posts, average daily visitors, etc.) but I bet the problem lies here:

    SELECT p.ID AS id, p.post_title AS title, p.post_author AS uid FROM jmu_popularpostssummary v LEFT JOIN jmu_posts p ON v.postid = p.ID WHERE 1 = 1 AND p.post_type IN(‘post’, ‘page’) AND p.ID NOT IN(6513, 6655, 1579) AND v.view_datetime > DATE_SUB(‘2018-01-04 16:20:18’, INTERVAL 365 DAY) AND p.post_password = ” AND p.post_status = ‘publish’ GROUP BY v.postid ORDER BY SUM(v.pageviews) DESC LIMIT 20 OFFSET 0;

    You’re having WPP try to retrieve an entire year of data from your database.

    If:

    • WPP has been running on your site for some time now,
    • You have a lot of posts,
    • You get a lot of visits everyday

    … chances are your database server can’t handle that and crashes when your site is at its peak hours (specially if your site is on a shared hosting), which would explain the “database connection error” message you’re seeing sometimes.

    So:

    • If you want to keep your “best posts from the past year” list, make sure you cache the result so WPP doesn’t run such a heavy query so often. This doesn’t guarantee that your database server won’t suffer during peak hours but it should be a lot better.
    • Install a caching plugin to reduce the load on your server.
    • If your server has memcached installed and enabled and you’re using W3 Total Cache (or any other caching plugin that supports memcached), consider installing a memcached plugin to further improve the performance of your site.
    • Read the Performance section from the wiki.
    Thread Starter milos.kostadinovic

    (@miloskostadinovic)

    Hi Héctor,

    Thanks for the valuable info. You are right – we have lots of posts and a large number of visits every day, and WPP has been running on our blog for almost 4 years.

    I will try your advice and make sure to set WPP for best performance (i.e. enable caching, log limit, data sampling) and see how it goes.

    Thanks again!

    Plugin Author Hector Cabrera

    (@hcabrera)

    Thanks for the valuable info. You are right – we have lots of posts and a large number of visits every day, and WPP has been running on our blog for almost 4 years.

    Don’t mention it, and thanks for being such a loyal user ??

    I will try your advice and make sure to set WPP for best performance (i.e. enable caching, log limit, data sampling) and see how it goes.

    I recommend starting with the caching part only. Try the rest of the features if/when needed.

    If you have any other questions, don’t hesitate to ask ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Database connection error caused by WP Popular Posts’ is closed to new replies.