# CPU usage at 100% 24-7 after last update

**URL:** <https://www.patreondevelopers.com/t/cpu-usage-at-100-24-7-after-last-update/383>\
**Category:** Wordpress Plugin\
**Created:** [March 27, 2018, 9:26pm UTC](https://www.patreondevelopers.com/t/cpu-usage-at-100-24-7-after-last-update/383 "2018-03-27T21:26:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dreadcentral](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@dreadcentral](https://www.patreondevelopers.com/u/dreadcentral)\
**Post date:** [March 27, 2018, 9:26pm UTC](https://www.patreondevelopers.com/t/cpu-usage-at-100-24-7-after-last-update/383/1 "2018-03-27T21:26:34Z")

</div>

We run a very large content website and after the recent update was pushed out or server’s CPU usage spiked to 100% and has not come down. Way too many SQL calls going on prior to the plugin update wp\_posts select was called 17 times. Now wp\_posts select is called 75 times on a single page.

You can see exactly when the update was pushed in this screenshot

 ![2018-03-21_16-33-39](https://canada1.discourse-cdn.com/flex036/uploads/patreondevelopers/original/1X/0e4f20839eb611190e16b8c6d9508646c918a714.png)

This is wreaking havoc on a bunch of other areas of the site. Facebook API can not pull Opengraph data consistently because the connection times out, our WP to Twitter plugin is timing out, the Media Library takes almost 2 minutes to load.

The problem seems to be related to Patreon\_Protect and looking for protected images on every page load.

Whatever was pushed out though has made this plugin completely unusable for a large website and we have had to disable it much to the frustration of people paying for an ad free experience.

---

<div class="post-metadata">

**Author:** ![codebard](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/codebard/32/14_2.png) [@codebard](https://www.patreondevelopers.com/u/codebard)\
**Post date:** [March 27, 2018, 9:27pm UTC](https://www.patreondevelopers.com/t/cpu-usage-at-100-24-7-after-last-update/383/2 "2018-03-27T21:27:43Z")

</div>

Very curious…

Do these posts have many images embedded?

---

<div class="post-metadata">

**Author:** ![dreadcentral](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@dreadcentral](https://www.patreondevelopers.com/u/dreadcentral)\
**Post date:** [March 27, 2018, 9:28pm UTC](https://www.patreondevelopers.com/t/cpu-usage-at-100-24-7-after-last-update/383/3 "2018-03-27T21:28:38Z")

</div>

1 image per post at most and a Featured image. Nothing out of the norm I would say.

---

<div class="post-metadata">

**Author:** ![dreadcentral](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@dreadcentral](https://www.patreondevelopers.com/u/dreadcentral)\
**Post date:** [March 27, 2018, 9:31pm UTC](https://www.patreondevelopers.com/t/cpu-usage-at-100-24-7-after-last-update/383/4 "2018-03-27T21:31:08Z")

</div>

I have some more detailed screen grabs from New Relic and a few other tools I can provide if it would help at all as well.

---

<div class="post-metadata">

**Author:** ![codebard](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/codebard/32/14_2.png) [@codebard](https://www.patreondevelopers.com/u/codebard)\
**Post date:** [March 27, 2018, 9:33pm UTC](https://www.patreondevelopers.com/t/cpu-usage-at-100-24-7-after-last-update/383/5 "2018-03-27T21:33:46Z")

</div>

Hmmm…

We actually reduced cpu usage with this version since we are now caching the patronage details that are queried from API - we query now once per page load.

In Patreon\_Protect class we have new code that checks for protected images, only for logged in users. (If you are using a cache already).

This should do an extra query for attachment info, but not to the order you mention.

However what is eye-catching is that before the update you mention that there were already 17 queries being made to wp\_posts table. Even before the update plugin didnt have code that could do that many queries. We actually use the $post global in most of the operations, so the post info should already exist in a single post context and therefore shouldnt be queried.

Chances are that there is a plugin (or more plugins) which apply or re-apply the\_content filter, and since our protection mechanism hooks into that it gets called as many times as the\_content filter is called.

Have you run Plugin Performance Profiler to detect precise cpu usage of plugins?

If you can provide me WP admin access, we can look into this very curious situation together. In that case, please create a new admin user with a sufficiently complex password and mail it to me at [ozgur@c.patreon.com](mailto:ozgur@c.patreon.com) . This account should be deleted after we are done with debugging.

---

<div class="post-metadata">

**Author:** ![dreadcentral](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@dreadcentral](https://www.patreondevelopers.com/u/dreadcentral)\
**Post date:** [March 27, 2018, 9:46pm UTC](https://www.patreondevelopers.com/t/cpu-usage-at-100-24-7-after-last-update/383/6 "2018-03-27T21:46:33Z")

</div>

> [@codebard](#):
>
> [ozgur@c.patreon.com](mailto:ozgur@c.patreon.com)

Much appreciated! I just sent over some login credentials and some more info.

Thanks @codebard!

---

<div class="post-metadata">

**Author:** ![codebard](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/codebard/32/14_2.png) [@codebard](https://www.patreondevelopers.com/u/codebard)\
**Post date:** [March 27, 2018, 10:00pm UTC](https://www.patreondevelopers.com/t/cpu-usage-at-100-24-7-after-last-update/383/7 "2018-03-27T22:00:38Z")

</div>

My pleasure. I’ll be looking into this soon. I’ll update you from direct message with the findings.

---

<div class="post-metadata">

**Author:** ![codebard](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/codebard/32/14_2.png) [@codebard](https://www.patreondevelopers.com/u/codebard)\
**Post date:** [March 28, 2018, 1:24am UTC](https://www.patreondevelopers.com/t/cpu-usage-at-100-24-7-after-last-update/383/8 "2018-03-28T01:24:15Z")

</div>

## I debugged queries and performance using Query Monitor. Im posting the results with permission of dreadcentral with site-specific info redacted.

Before.jpg is the performance of your #1 page with our plugin disabled. There are a total of 235 queries.

 ![Before](https://canada1.discourse-cdn.com/flex036/uploads/patreondevelopers/original/1X/233de8026e0230ff4b4baa6c47f7aba57a2b4927.jpg)

After.jpg is performance of the #1 page with our plugin on. There are 236 queries. Only one more.

 ![After](https://canada1.discourse-cdn.com/flex036/uploads/patreondevelopers/original/1X/caf775dd670c0cad2db5df75d56e0217fec131f1.jpg)

Checking query details, Slow.jpg shows that there are 4 slow sql queries which in total add a ~1.5 sec to query time, which would also cause high cpu spikes.

 ![Slow-Queries](https://canada1.discourse-cdn.com/flex036/uploads/patreondevelopers/original/1X/d9f20a157567c61eca8bc622be14d1bdcb792c2e.jpg)

These are not related to our plugin. It seems your theme is pulling related posts from the same category and showing them under the post being viewed. This means that ~4 more times everything related to a post will run in every one of your single post pages - because you show 4 posts in one go.

Long story short this is a situation with your related posts plugin or related posts functionality that is built into your theme. If you show 4 posts in one go while showing a single post, anything related to posts will be called 4 times - naturally.

Speaking of the theme/plugins:

Warning.jpg shows that there is an issue in code relevant to a query which gets next/previous posts (probably to show them in your single post page), that causes a warning to be given by WordPress core. The code causing this seems to be in your theme - Zox News, inside its single post display template single.php. Line 383.

 ![Warning](https://canada1.discourse-cdn.com/flex036/uploads/patreondevelopers/original/1X/621ff86c3197353d20ce43bbf4e0984a71f8dfc6.jpg)

I advise against changing the theme or doing major changes to the theme since this could affect your SEO ranking for your popular pages. However the code that causes the warning must be looked at first.

I wasnt able to notice any notable change in total time the queries take. With our plugin disabled, or enabled, it seems to take in between ~1.1 seconds and ~2.5 seconds randomly.

Summary; this seems to be related to your theme displaying 4 posts in one go while showing 1 single post. Any plugin that uses the\_content filter will kick in 4 times with this setup.

We can see if we can do some optimizations on our end, after you have that PHP warning looked at.

For the time being, you can just drop the below code to your theme’s functions.php or any plugin to disable image protection:

define(‘PATREON\_BYPASS\_IMAGE\_FILTERING’,true);

---

<div class="post-metadata">

**Author:** ![codebard](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/codebard/32/14_2.png) [@codebard](https://www.patreondevelopers.com/u/codebard)\
**Post date:** [March 29, 2018, 7:37am UTC](https://www.patreondevelopers.com/t/cpu-usage-at-100-24-7-after-last-update/383/9 "2018-03-29T07:37:17Z")

</div>

The first paragraph of the above post stays bold and heading-size for some reason…
