Nginx caching methods - FastCGI

Nginx caching methods - FastCGI

When it comes to webserver optimization a lot of people seem to forget to utilize the proper caching mechanics. Most people will use a full-page cache, which writes to a local cache file on the filesystem. That's decent, but not enough.

A lot of websites which are using php are still running with a simple LAMP (Linux, Apache, MySQL, PHP) setup. This suffices for small-time blogs and small informational websites. But when sites become slightly busier and especially when they are running a webshop, performance really matters.

Optimization can be done from all angles, but most of the time rewriting the code of the site for optimization is costly and time inefficient (though very important!), so most of the time people will use a full-page cache method or plugin to speed up access time. This mainly benefits nginx versus apache as nginx is a lot speedier when dealing with accessing files directly.

When a site gets bigger and there's a lot of people using the site, this mechanism can still bog down. Some CMS's create hundreds of thousands or millions of cached files depending on a category, product, etc. This bogs down the server with writing and looking up files.

That's when FastCGI (sometimes referred to MicroCache) comes in to save the day.
You can define a certain amount of memory to use for caching responses. Imagine that the main page and main category pages would be in this cache, generated every X-minutes. From that moment all those visitors will get the cached version directly from nginx itself, no calculation required. A nice statistical benefit is that this will lower the Time To First Byte (TTFB) to ~10-20ms.

Practical example - festival site

There's a festival website which once close to the event and on the day of the festival gets at least 1.5 million visitors a day, in peaks of 300.000 an hour. This can be handled easily with a well-configured machines running nginx with fastcgi cache. We could get away with only a 4GB Memory, 4 CPU cloudserver which you can set up somewhere in minutes for a couple of euro. You don't need hardware - you need a proper setup.

TL;DR:
Don't underestimate the power of using a proper microcache. It always delivers an incredible performance boost to your website!

Marco Arts

Marco Arts

Linux, Networking, Reader, Gamer.

  • Nijmegen
  • ------

You maight also like

Comments powered by Disqus