Nginx – Slow TTFB in a single WordPress site in a Nginx environment on DigitalOcean (20$)

digital-oceannginxperformancePHPWordpress

On an all default Ubuntu 16.04 Nginx environment hosted on a 20$ DigitalOcean droplet I have only one WordPress site with a small amount of data: About 10 webpages, 10 images (around 100kb each), and 6 common plugins (all in default configuration).

I experience a bit of a slow general loading time (TTFB), in this site.

Configuration files

WordPress caching (AutoPtimize):

enter image description here

OpCode caching:

enter image description here

My problem

Since I uploaded the site, about a month and half ago, I keep getting the following error, in each Google PageSpeed Insights test (GPI):

Reduce server response time

In our test, your server responded in 0.95 seconds. There are many
factors that can slow down your server response time. Please read our
recommendations to learn how you can monitor and measure where your
server is spending the most time.

It's always 0.93 to 1.20 although I feel, intuitively, that it should have been much lower than that, per the data I've given.

Why WordPress isn't the problem

  1. The site's theme is Astra, without a subtheme. The same problem happened with other themes as well.

  2. I have enabled CSS-JS minification, resource compression and WordPress caching with the plugin AutoPtimize as well as Nginx caching (see below).

  3. I tried to turn off all plugins, yet no serious change was seen; I went down from 900ms to around 450ms while still having the error.

  4. Everything is totally up to date with automatic upgrades coming from the CLI (unattnded-upgrades and WP-CLI).

My question

Given that all my tests indicate that this is an Nginx/PHP problem, what do I lack in my Nginx/PHP configuration to have a much lower loading time (say up to 0.10)? Everything is default for both, so I can't say what will be bad in that.

Update

Activating the free plan of Cloudflare with full (strict) SSL processing, didn't bring any TTFB significant change.

Best Answer

Autoptimize is the main problem here when achieving better TTFB, other factors contribute, but Autoptimize makes TTFB equal to the page generation time by design.

It uses output buffers to scoop up everything output to the browser, intercepting it and storing it. Then, once the page has finished generating, it processes the page output to concatenate CSS and JS, and spits all the bytes out at once at the very end.

I strongly recommend uninstalling it. If you want performance gains, use an object cache coupled with something like memcached or redis. This will take the form of a wp-content/object-cache.php and enabling WP_CACHE in your wp-config.php, coupled with installing and configuring memcached or equivalent. This will give you a significant boost to site performance in pretty much all areas

If you don't uninstall it, then your options are severely limited. By design, TTFB will always be equal to page generation time + however long Autoptimize takes. You also lose all the performance benefits of HTTP/2.

Thus the only way to reduce TTFB with this plugin installed, is to improve page generation time in PHP. This could be via object caches, refactoring DB queries, upgrading PHP, but if your page loading time is already low then there's little to be done.

My recommendation would be to look into and research alternative methods of resolving the google page speed score with regards to stylesheets and scripts, and try to improve page generation speed. Those solutions will improve your site performance, even with Autoptimize activated

Related Topic