Debug Performance Issues

There are essentially two very different cases how WP site typically bring server down with symptoms of CPU overload:

Your site is not fast enough for your traffic

Simply put if your server can serve page every tenth of a second and you get more than 10 pageviews in that second – your resources are bankrupt. If your site going down heavily correlates with traffic spikes then you need either to make it faster or give it more resources.

You have a bug and/or configuration issue

This is much sneakier since it’s not really performance issue. It’s issue that causes some kind of crazy loop in a way that really burns CPU. It might not even be in PHP code, for example that tends to happen on some configurations when site attempts HTTP request to itself.

Things to do

  1. Install profiler, the lower level the deeper insight it will give you. NewRelic, munin, xdebug, xhprof, something WP level (P3 Profiler, Time Stack, Laps). Not at the same time! 🙂 Depends on what is your hosting type, etc. Be careful not to crank it up too much from the start since any active debugger/profiler makes site slower to certain degree (ranging from unimportant to killer 300% slowdowns), which might instantly escalate the issue.

  2. Crank up the logging. Turn on WP_DEBUG, disable showing errors, log them to file.

  3. Drag site down to local install, apply the same (sans hiding errors), see how it behaves.

From there it’s either having glaring performance issue light up like supernova (consider yourself lucky) or slow hunt for what goes wrong and under which circumstances it manifests.