Title: AMP plugin causing high database load
Last modified: August 31, 2018

---

# AMP plugin causing high database load

 *  Resolved [vich11](https://wordpress.org/support/users/vich11/)
 * (@vich11)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/amp-plugin-causing-high-database-load/)
 * According to my server host this plugin is using a lot of dbase resources. Like,
   a LOT.
 * I am using New Relic and the wp_posts select is by far the most time consuming
   resource in the dbase, by a factor of 20X above the next highest usage resource.
 * My host looked into it and said the following:
 * “It appears that the wp_posts selects that you mentioned are in fact a major 
   contributor to your poor database performance. The main driver behind these queries
   is the amp plugin.”
 * It looks like there is an issue with the cache settings, causing it to bypass
   the cache and execute PHP every time? Here is an example page:
 * curl -I [https://gamerant.com/far-cry-5-it-easter-egg-stephen-king/amp/](https://gamerant.com/far-cry-5-it-easter-egg-stephen-king/amp/)
   
   HTTP/1.1 200 OK Date: Fri, 31 Aug 2018 15:06:59 GMT Content-Type: text/html; 
   charset=UTF-8 Connection: keep-alive Set-Cookie: __cfduid=d6e130d3b7ec0adb615b02f541ea7233f1535728019;
   expires=Sat, 31-Aug-19 15:06:59 GMT; path=/; domain=.gamerant.com; HttpOnly Cache-
   Control: max-age=0, must-revalidate, no-cache, no-store
 * I need some help with this, please.
 * Thanks

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [Weston Ruter](https://wordpress.org/support/users/westonruter/)
 * (@westonruter)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/amp-plugin-causing-high-database-load/#post-10644741)
 * 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](https://wordpress.org/support/users/vich11/)
 * (@vich11)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/amp-plugin-causing-high-database-load/#post-10664590)
 * 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/](https://gamerant.com/destiny-2-get-more-seeds-of-light-super-skill-trees/amp/)
 * Every single image has both a height and width attribute.
 *  Plugin Author [Weston Ruter](https://wordpress.org/support/users/westonruter/)
 * (@westonruter)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/amp-plugin-causing-high-database-load/#post-10664611)
 * > 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/](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](https://wordpress.org/support/users/vich11/)
 * (@vich11)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/amp-plugin-causing-high-database-load/#post-10664708)
 * 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?
 * ![Destiny 2: How to Get More Seeds of Light for New Super Skill Trees](https://
   i0.wp.com/cdn.gamerant.com/wp-content/uploads/destiny-2-forsaken-patch-notes-
   void-hunter.jpg.webp?resize=1080%2C600&ssl=1)
 * [⌊GR gamerant⌉⌊GR gamerant⌉[
 * 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](https://gamerant.com/ampusage.PNG)
 *  Plugin Author [Weston Ruter](https://wordpress.org/support/users/westonruter/)
 * (@westonruter)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/amp-plugin-causing-high-database-load/#post-10664735)
 * > 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](https://wordpress.org/support/users/vich11/)
 * (@vich11)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/amp-plugin-causing-high-database-load/#post-10664763)
 * Ah! Thanks, I will look into that ASAP and see what happens if I remove it.
 *  Thread Starter [vich11](https://wordpress.org/support/users/vich11/)
 * (@vich11)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/amp-plugin-causing-high-database-load/#post-10664802)
 * 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!
 *  Plugin Author [Weston Ruter](https://wordpress.org/support/users/westonruter/)
 * (@westonruter)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/amp-plugin-causing-high-database-load/#post-10664987)
 * 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](https://wordpress.org/support/users/vich11/)
 * (@vich11)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/amp-plugin-causing-high-database-load/#post-10664993)
 * Gotcha. Thanks again very much.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘AMP plugin causing high database load’ is closed to new replies.

 * ![](https://ps.w.org/amp/assets/icon.svg?rev=2527602)
 * [AMP](https://wordpress.org/plugins/amp/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/amp/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/amp/)
 * [Active Topics](https://wordpress.org/support/plugin/amp/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/amp/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/amp/reviews/)

## Tags

 * [Google AMP](https://wordpress.org/support/topic-tag/google-amp/)

 * 9 replies
 * 2 participants
 * Last reply from: [vich11](https://wordpress.org/support/users/vich11/)
 * Last activity: [7 years, 8 months ago](https://wordpress.org/support/topic/amp-plugin-causing-high-database-load/#post-10664993)
 * Status: resolved