How does the host identify AMP as being the problem? What queries specifically are out of control?
Do you have a persistent object caching plugin active on your site? If you have a lot of images that lack width and height attributes, then the plugin has to fetch the images on store the dimensions in a transient. If you do not have a persistent object caching plugin active, then this will cause the plugin to hit the database for each image to obtain the transient data. If you don’t have such a plugin, look into using the object cache plugins for Redis or Memcached, depending on what your host supports.
Thread Starter
vich11
(@vich11)
Redis object caching is now active on the site, but this doesn’t seem to be helping.
When I look at the AMP version of a page, it seems to have width and height attributes so I’m not sure what you’re referring to. For example when I look at the source of this page:
https://gamerant.com/destiny-2-get-more-seeds-of-light-super-skill-trees/amp/
Every single image has both a height and width attribute.
When I look at the AMP version of a page, it seems to have width and height attributes so I’m not sure what you’re referring to.
I am referring to the non-AMP version of the page. AMP requires width and height attributes, so the plugin has to supply them.
If I look at the non-AMP version of the page at https://gamerant.com/destiny-2-get-more-seeds-of-light-super-skill-trees/ then over 75% the images do not have width or height:
document.querySelectorAll('img[width]').length / document.querySelectorAll('img:not([width])').length > 0.75
Redis object caching is now active on the site, but this doesn’t seem to be helping.
What queries specifically are causing the slow responses? How was it determined to be a database issue?
Thread Starter
vich11
(@vich11)
I don’t understand the use of JS to determine 75% of images don’t have those attributes, but images used in posts do have height/width, and what’s that got to do with the AMP version of the page?


I see two items with no height/width but those are inside javascript, not actual images.
Here is an example from New Relic:
Query
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE ?=? AND wp_posts.ID NOT IN (?) AND (
wp_term_relationships.term_taxonomy_id IN (?,?,?,?,?)
) AND wp_posts.post_type = ? AND (wp_posts.post_status = ?) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT ?, ?
Database instance
vps-gamerant-cluster.cluster-czvuylgsbq58.us-east-1.rds.amazonaws.com:3306
Database name
db_dom9972
Stack trace
in mysqli_query called at /wordpress-4.9.8/wp-includes/wp-db.php (1924)
in wpdb::_do_query called at /wordpress-4.9.8/wp-includes/wp-db.php (1813)
in wpdb::query called at /wordpress-4.9.8/wp-includes/wp-db.php (2454)
in wpdb::get_col called at /wordpress-4.9.8/wp-includes/class-wp-query.php (2821)
… WP_Query::get_posts called at /wordpress-4.9.8/wp-includes/
class-wp-query.php (3230)
in WP_Query::query called at /wordpress-4.9.8/wp-includes/class-wp-query.php (3336)
…WP_Query::__construct called at /dom9972/wp-content/themes/8.9K/amp/
single.php (54)
…/dom9972/wp-content/plugins/amp/includes/templates/
class-amp-post-template.php (441)
…/dom9972/wp-content/plugins/amp/includes/templates/
class-amp-post-template.php (211)
…/dom9972/wp-content/plugins/amp/includes/templates/
class-amp-post-template.php (200)
in AMP_Post_Template::load called at /dom9972/wp-content/plugins/amp/amp.php (328)
in amp_render_post called at /dom9972/wp-content/plugins/amp/amp.php (279)
in amp_render called at /wordpress-4.9.8/wp-includes/class-wp-hook.php (286)
…P_Hook::apply_filters called at /wordpress-4.9.8/wp-includes/
class-wp-hook.php (310)
in WP_Hook::do_action called at /wordpress-4.9.8/wp-includes/plugin.php (453)
in do_action called at /wordpress-4.9.8/wp-includes/template-loader.php (12)
in require_once called at /wordpress-4.9.8/wp-blog-header.php (19)
in require called at /wordpress-4.9.8/index.php (17)
I’m not an expert on all this, so I’m not sure. You can see here the relative usage of AMP compared to the next couple of plugins: https://gamerant.com/ampusage.PNG
I don’t understand the use of JS to determine 75% of images don’t have those attributes, but images used in posts do have height/width, and what’s that got to do with the AMP version of the page?
If the non-AMP version has images without width/height then the plugin has to find out the dimensions. I used JS in the browser console to do a quick check of the images in the non-AMP page to see if there weren’t any without widths. I can see, however, that images inside the content all do seem to have dimensions supplied in the non-AMP version, so this shouldn’t be a problem.
Here is an example from New Relic:
That stack trace is extremely helpful. It seems that there is a query being made in the 8.9K/amp/single.php template that is causing the slowdown. I’m guessing it is the query that is populating the “MORE FROM GAME RANT” section. If so, then this query isn’t coming from the AMP plugin but rather from the 8.9K theme.
Thread Starter
vich11
(@vich11)
Ah! Thanks, I will look into that ASAP and see what happens if I remove it.
Thread Starter
vich11
(@vich11)
You are the man. That was it. For my own edification, how did that stack trace point you to that? I never would have deduced that.
Thanks very much!
Great.
I looked down the list of function calls to find ones that were not in core (wp-includes). I could see these lines:
in WP_Query::query called at /wordpress-4.9.8/wp-includes/class-wp-query.php (3336)
…WP_Query::__construct called at /dom9972/wp-content/themes/8.9K/amp/
single.php (54)
So that code in the theme then calls functionality in core. So I figured it was the theme template was making a very expensive WP_Query.
Thread Starter
vich11
(@vich11)
Gotcha. Thanks again very much.