• Hi,

    About two days ago my posts started to take a long time to load. They were working
    fine before that and there have been no changes made. I’ve run debug, used testing sites, checked the bandwidth at the server – it’s on an Azure VM -I can’t find the cause.

    I’ve been having issues with the admin dashboard – it takes about 2 minutes, literally, to add a new post or page and many other options take as long to open/edit – but many seem to be having that issue and the front-end was always working very fast.

    If anybody can take a look or point me in the right direction I’d very much appreciate it!
    Rob

Viewing 15 replies - 1 through 15 (of 19 total)
  • Most likely your database is fragmented and needs to be cleaned up. Try the following:

    1. Do a database backup just to be safe.
    2. Install WP Optimize and then run the optimizer.
    3. Install WP Super Cache for overall speed improvements and to lessen the number of database transactions.

    Whats the website URL and did you install any plugins lately?

    It can be hosting related, do you have other websites on the same server loading slow?

    Thread Starter Robert

    (@robg48)

    Sorry about that!

    https://healthitlink.com

    No new plugins – I’ve tried it with no plugins installed, using the default theme, and that didn’t change anything.

    I don’t have other sites on this server but I do have this site on other servers – and they all do the same thing.

    Thread Starter Robert

    (@robg48)

    The database is very clean – the size is unchanged from 2 months ago – give or take 2mb (and it’s 1gb db), the data is static, no changes/edits, etc…no orphans, and I’m running W3 for caching – Super Cache wasn’t quite as good on my site.

    Thread Starter Robert

    (@robg48)

    I posted the url but that post isn’t displaying.

    https://healthitlink.com

    no plugins added. And I don’t have other sites on the same server – but I do have this site on other server – and on those testing servers posts are just as slow.

    In that case, try installing the Query Monitor and seeing how long the queries are taking.

    If nothing jumps out there, it may be a server-level PHP misconfiguration.

    Thread Starter Robert

    (@robg48)

    Thanks! I installed Query Monitor – great tool! – and seeing some errors – this php error:

    Trying to get property of non-object

    And then two slow query notifications

    SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
    FROM wp_posts
    WHERE 1=1
    AND wp_posts.post_type = 'post'
    AND (wp_posts.post_status = 'publish'
    OR wp_posts.post_status = 'private')
    ORDER BY RAND()
    LIMIT 0, 1
    
    SELECT post_id, meta_key, meta_value
    FROM wp_postmeta
    WHERE post_id IN (248075)
    ORDER BY meta_id ASC

    but those .5 seconds and .06 seconds – doesn’t seem that would account for such a delay. I also get similar notification when loading the home page – which isn’t slow at all.

    So the problem doesn’t have to do with the queries, we’ve at least narrowed it down. At this point I would do something a little more drastic to find exactly where the slowdown is occurring.

    In your wp-includes/plugin.php file, find this line:

    function do_action($tag, $arg = '') {

    Below that line, add this:

    if (!defined('DEBUG_START')) define('DEBUG_START', microtime(true));
    echo "<!-- [ACTION] " . $tag . ": " . (microtime(true) - DEBUG_START) . "-->\n";

    Then reload your page and look at the HTML source. It shows the execution time throughout the entire page building process.

    Thread Starter Robert

    (@robg48)

    Will do Acchia – I just created an image and loaded it onto a new server and going to run the optimization as well. brb.

    Thread Starter Robert

    (@robg48)

    Hello again – and thank you again – that code is very handy!

    Going through the source I will paste below the section that shows the largest jump in time – it goes from 1.x seconds to over 9 seconds (if I’m reading this right). It seems to be related to my postmeta table – which is 510mb in size. My system, by the way, is running at 1% capacity, 24% hard drive space is used, 6% of memory, the swap file isn’t being touched, and my WP admin – I have Server IP & Memory Usage plugin installed – shows 2% out of 256mb being used.

    <!-- [ACTION] it_get_template_part: 1.2125279903412-->
    
    <!-- [ACTION] it_before_content_page: 1.2327218055725-->
    <!-- [ACTION] update_post_meta: 1.234071969986-->
    <!-- [ACTION] update_postmeta: 1.2340857982635-->
    <!-- [ACTION] updated_post_meta: 5.5960309505463-->
    <!-- [ACTION] updated_postmeta: 5.5961148738861-->
    <!-- [ACTION] update_post_meta: 5.5985569953918-->
    <!-- [ACTION] update_postmeta: 5.5985748767853-->
    <!-- [ACTION] updated_post_meta: 9.4862499237061-->
    <!-- [ACTION] updated_postmeta: 9.4862818717957-->

    Is it just my db size? I have caching going on so when I reload the same post it, of course, loads much quicker – still slow I feel – at around 3-7 seconds.

    The problem is specifically in the update_meta_cache() function or something that hooks into it. But in query monitor you didn’t notice any 4 second queries?

    Have you tried disabling W3 caching?

    Thread Starter Robert

    (@robg48)

    Exactly the same with W3 disabled. Query monitor only show “1 slow query” and it’s only .3s, it’s: “SELECT SQL_CALC_FOUND_ROWS wp_posts.ID…”

    Also, when I reload that same page that I posted those actions for, that same section shows this:

    <!-- [ACTION] it_get_template_part: 1.2804729938507-->
    
            <!-- [ACTION] it_get_template_part: 1.2859311103821-->
    
    <!-- [ACTION] it_get_template_part: 1.2939331531525-->
    
    <!-- [ACTION] it_before_content_page: 1.3134970664978-->
    
    <div class="row solo single-page post-loop">

    And optimization is still running on my other site – when that is done I will try disabling, and removing, all remants of W3, do this testing again, and then try Super Cache again.

    Let’s do a little more hacking of the update_meta_cache() function. We’re going to be adding several lines so make a backup of the wp-includes/meta.php file to overwrite with when we’re done.

    • Open wp-includes/meta.php and find this line:

      function update_meta_cache($meta_type, $object_ids) {

    • Beneath it add this:
      if (!defined('DEBUG_START')) define('DEBUG_START', microtime(true));
      echo "<!-- [update_meta_cache] CHECKPOINT 1: " . (microtime(true) - DEBUG_START) . "-->\n";
    • Then find this line:
      if ( empty( $ids ) )
    • and ABOVE it add this:
      echo "<!-- [update_meta_cache] CHECKPOINT 2: " . (microtime(true) - DEBUG_START) . "-->\n";
    • Then find this line:
      foreach ( $ids as $id ) {
    • and ABOVE it add this:
      echo "<!-- [update_meta_cache] CHECKPOINT 3: " . (microtime(true) - DEBUG_START) . "-->\n";
    • Then find this line:
      return $cache;
    • and ABOVE it add this:
      echo "<!-- [update_meta_cache] CHECKPOINT 4: " . (microtime(true) - DEBUG_START) . "-->\n";

    This will narrow down which function is running slowly.

    Thread Starter Robert

    (@robg48)

    Here are two sections that show as taking some time – the first is the same section as previously.

    <!-- [ACTION] it_get_template_part: 1.4426918029785-->
    
    <!-- [ACTION] it_before_content_page: 1.4653308391571-->
    <!-- [ACTION] update_post_meta: 1.4667270183563-->
    <!-- [ACTION] update_postmeta: 1.4667398929596-->
    <!-- [ACTION] updated_post_meta: 5.4673058986664-->
    <!-- [ACTION] updated_postmeta: 5.467325925827-->
    <!-- [update_meta_cache] CHECKPOINT 1: 5.4675908088684-->
    <!-- [update_meta_cache] CHECKPOINT 2: 5.4676129817963-->
    <!-- [update_meta_cache] CHECKPOINT 3: 5.4685289859772-->
    <!-- [update_meta_cache] CHECKPOINT 4: 5.4685518741608-->
    <!-- [ACTION] update_post_meta: 5.4693229198456-->
    <!-- [ACTION] update_postmeta: 5.4693369865417-->
    <!-- [ACTION] updated_post_meta: 9.2980518341064-->
    <!-- [ACTION] updated_postmeta: 9.2980778217316-->

    And I scrolled further down and noticed this one:

    <!-- [ACTION] parse_tax_query: 9.3279869556427-->
    <!-- [ACTION] parse_tax_query: 9.3287329673767-->
    <!-- [ACTION] posts_selection: 9.3342018127441-->
    <!-- [update_meta_cache] CHECKPOINT 1: 10.379915952682-->
    <!-- [update_meta_cache] CHECKPOINT 2: 10.379976987839-->
    <!-- [ACTION] parse_tax_query: 10.380240917206-->
    <!-- [ACTION] parse_tax_query: 10.381052970886-->
    <!-- [ACTION] posts_selection: 10.384323835373-->
    <!-- [update_meta_cache] CHECKPOINT 1: 11.458623886108-->
    <!-- [update_meta_cache] CHECKPOINT 2: 11.458719968796-->
    <!-- [ACTION] parse_tax_query: 11.459155797958-->
    <!-- [ACTION] parse_tax_query: 11.460553884506-->
    <!-- [ACTION] posts_selection: 11.462005853653-->
    <!-- [update_meta_cache] CHECKPOINT 1: 23.613695859909-->
    <!-- [update_meta_cache] CHECKPOINT 2: 23.613754987717-->
    <!-- [ACTION] parse_tax_query: 23.614023923874-->
    <!-- [ACTION] parse_tax_query: 23.614811897278-->
    <!-- [ACTION] posts_selection: 23.616005897522-->
    <!-- [update_meta_cache] CHECKPOINT 1: 23.630491018295-->
    <!-- [update_meta_cache] CHECKPOINT 2: 23.630545854568-->
    <!-- [update_meta_cache] CHECKPOINT 3: 23.632313966751-->
    <!-- [update_meta_cache] CHECKPOINT 4: 23.632360935211-->
    <!-- [update_meta_cache] CHECKPOINT 1: 23.633262872696-->
    <!-- [update_meta_cache] CHECKPOINT 2: 23.633307933807-->
    <!-- [update_meta_cache] CHECKPOINT 1: 23.633466959-->
    <!-- [update_meta_cache] CHECKPOINT 2: 23.633487939835-->
    <!-- [update_meta_cache] CHECKPOINT 3: 23.634235858917-->
    <!-- [update_meta_cache] CHECKPOINT 4: 23.634253978729-->
    <!-- [ACTION] parse_tax_query: 23.635660886765-->
    <!-- [ACTION] parse_tax_query: 23.636511802673-->
    <!-- [ACTION] posts_selection: 23.642235994339-->
    <!-- [update_meta_cache] CHECKPOINT 1: 23.64460682869-->
    <!-- [update_meta_cache] CHECKPOINT 2: 23.64465880394-->
    <!-- [ACTION] begin_fetch_post_thumbnail_html: 23.654094934464-->
    <!-- [ACTION] end_fetch_post_thumbnail_html: 23.656200885773-->
    <!-- [ACTION] begin_fetch_post_thumbnail_html: 23.657423973083-->
    <!-- [ACTION] end_fetch_post_thumbnail_html: 23.663047790527-->
    <!-- [ACTION] begin_fetch_post_thumbnail_html: 23.664436817169-->
    <!-- [ACTION] end_fetch_post_thumbnail_html: 23.666075944901-->
    <!-- [ACTION] begin_fetch_post_thumbnail_html: 23.667264938354-->
    <!-- [ACTION] end_fetch_post_thumbnail_html: 23.673214912415-->
    <!-- [ACTION] begin_fetch_post_thumbnail_html: 23.674466848373-->
    <!-- [ACTION] end_fetch_post_thumbnail_html: 23.676244020462-->
    <!-- [ACTION] begin_fetch_post_thumbnail_html: 23.677374839783-->
    <!-- [ACTION] end_fetch_post_thumbnail_html: 23.683256864548-->

    Sorry, just realized I had you add that code to the wrong function.

    Go back into /wp-includes/plugin.php to the do_action() function and after this line:

    global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;

    add this:

    if ($tag == 'update_postmeta') {
      echo '<!--';
      print_r($wp_filter[$tag]);
      echo '-->';
    }

    That will tell us what is hooking into that action event.

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Posts taking up to 30 seconds to load’ is closed to new replies.