Question

How can I improve the TTFB?

Posted May 15, 2021 399 views
MySQLApacheServer OptimizationUbuntu 20.04

Heya!

I’m running Apache2 on a
CPU-Optimized 32 GB Memory + 4CPUs / 50 GB Disk + 300 GB / SGP1 - Ubuntu 20.04 (LTS) x64. The time-to-first-byte is between 700-790ms and im running my Magento2 Website that contain more then 50k Products.

I’d like to get that down to 100ms, maybe 200ms. Is that a good goal… How do I get that number down without using Varnish? or Varnish must required…? also i try to install varnish its not proper install or work with apache2..... Can I tweak Apache2 some way, or what i do....?

Thanks,
Numan

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi @fadlinco,

Improving TTFB is actually a two-way process. There is your optimization of your Droplet(Apache2,MySQL other service) and your Website (Caching, Optimazint images and so on). You can’t completely optimize one without the other.

Let’s start with your Droplet. First, I’ll recommend starting using some kind of server-based caching. A good solution is Opcache but honestly, Varnish is a lot better.

Now you mentioned you can;t configure/tweak Apache to work with Varnish. Usually, Varnish is used in front of Apache to cache requests which then as proxy to forward to Apache. With that in mind, you can opt in for Opcache and use that one instead. It should help!

The next step after the server-base caching is using PHP-FPM with your PHP. PHP-FPM will help speed up requests a lot just because of how it works.

Another thing I have in my mind is using the latest PHP version there is available.

And one last recommendation on optimizing your Droplet, is using an MPMWORKER with your Apache2 installation if you are not already doing it. There are 3 mpm modules with Apache2. By default it uses mpmprefork but this is an outdated mpm module so people tend to use mpmworker or mpmevent. You can read more about them and then decide which to use but my recommendation is mpm_worker.

All these should help bring down the TTFB Droplet wise.

Regarding your Website, I’m not that familiar with Magento but there should be some plugins that help with caching your website and optimizing images.

Regards,
KFSys