WordPress.org

Ready to get started?Download WordPress

Forums

Sudden spike in the number of queries used (8 posts)

  1. hitormiss
    Member
    Posted 8 years ago #

    My blog (hitormiss.org) has gone from using around 60 queries (taking less than 1 second) per page load to using around 770 (taking 3 to 10 seconds to generate the page). I used a debug statement in wp-db.php to determine that the WP code was requerying the database each time it used an option value (from wp_options). Shouldn't it be caching those variables?

    I've reloaded all the core WP files and tried using different themes, but I'm always getting a massive number of queries hits.

    Note: I do run another website on the same account which uses the MySQL server (but doesn't use WP code).

    Any ideas to fix this?

  2. hitormiss
    Member
    Posted 8 years ago #

    Note: I also tried disabling all the plugins I use, and that didn't fix it either.

  3. Mark (podz)
    Support Maven
    Posted 8 years ago #

    WordPress</a> in 5.362 seconds, using 577 MySQL queries<

    Wow.

    If you disable all plugins and switch to the Classic theme does that number go down ?

    Try this:
    /*
    Plugin Name: Jerome's Query Diagnostics
    Plugin URI: http://vapourtrails.ca/wp-plugins
    Version: 1.0
    Description: Simple plugin to output query diagnostics in a HTML comment block in the page footer.
    Author: Jerome Lavigne
    Author URI: http://vapourtrails.ca
    */

    That plugin will show individual parts and times of the code in the footer. Can you install that, check the info is in the footer when viewed then post back so we can see it too please ?

  4. hitormiss
    Member
    Posted 8 years ago #

    Okay, I enabled the Query Diagnostics plugin. None of the queries is taking a long time, it's just that there are 557 of them instead of the usual much fewer amount.

    Most of the quereies are:
    SELECT option_value FROM wp_options WHERE option_name = 'siteurl' LIMIT 1
    or
    SELECT option_value FROM wp_options WHERE option_name = 'home' LIMIT 1

    So, everytime the script is referencing those values, it's requerying MySQL instead of using a variable cache.

    Again, I've already tried disabling all my plugins, using the default templates instead, and reinstalling all of the WordPress files, to no affect/change.

  5. davidchait
    Member
    Posted 8 years ago #

    I believe object caching may be disabled due to certain things on the host machine (php safe_mode, directories not being writeable, etc.).

    But even if the caching is disabled, I'd think it would grab the entire options in one block, or at least in useful chunks. Need the guy who implemented it to deal with this one! ;)

    -d

  6. davidchait
    Member
    Posted 8 years ago #

    Okay, some resolution on this. There is a 'bad server configuration' that can confuse the caching system in 2.0 (and hopefully detected under 2.0.1), which makes it impossible to cache, but WP keeps on trying. You apparently would be on such a config.

    So the quick-fix is:

    define('DISABLE_CACHE', true);

    In something like the top of wp-config.php.

    For the time-being, that'll have to do. Longer-term, it's a problem with safe_mode being used (which breaks lots of things) rather than better/proper manual lockdown of PHP. From the discussions I've seen mention of it being removed from PHP 6 as safe_mode is simply 'broken'.

    -d

  7. n0id
    Member
    Posted 8 years ago #

    I've got the same problem but I'm using still WordPress 1.5. The difference is that I use some plugins which heavily increase the number of queries used, e.g. Ultimate Tag Warrior. I tried

    define('DISABLE_CACHE', true);

    but that didn't changed anything.
    The Query Diagnostic shows too that most of the queries are like

    SELECT option_value FROM wp_options WHERE option_name = 'home' LIMIT 1

    Without plugins the query number goes down but it's still high with around 270 queries.

    Any suggestions ?

  8. bolonki
    Member
    Posted 8 years ago #

    I'm not an expert, but I am having the same problems and want to contribute two little pieces of knowledge:

    1. Have you enabled WP 2.0 built-in cache by creating a 'cache' folder in the WP-Includes directory? For this to work, the 'cache' folder needs to be chmodded to 777. This could solve the issue of WP looking for and not finding the cache.

    2. This is external to WP, but it really lowers the server load if you enable mySQL query cacheing. You should ask your host to do it for you, just ask for it to be enabled. Even if you don't have any issues with WP, I think it is a very good idea to enable MySQL query cacheing --it gets rid of the dreadful "WP cannot establish a database connection" message page.

    Hope this helps.

    PS: Any news on the memcached thingie for WP? I saw Matt mentioning this when announcing 2.0, he said it was available, but I haven't seen this anywhere. Also, would love to see real cacheing in WP, rather than the current disk-based cache (not as efficient).

Topic Closed

This topic has been closed to new replies.

About this Topic