DEV Community

Vuong
Vuong

Posted on

Turning caching performance on Magento 2.x

(I just move this old blog from Medium to dev.to)
Full page cache (FPC) with Varnish & others with Redis

The same with most popular article. This post just mentioned more about plan & server configuration as a specific case for a small project.

Problem

Magento is a big framework, it needs a lot of system resource to initialize instance, running, processing the requests, reading the cached files/media files (Catalog)/static resource files (JS, CSS, template images). The build-in cache of Magento is not good for handling many requests, however it better for a dev env because your computer will cooler than running the web without cache.
Our instance is running on EC2 with small plan.

Magento app/etc/env.php configuration:

MAGE_MODE: default|developer

Those reasons are why we must be considering to have another-faster-cache-engine. In case, we follow this one — Redis.
Use Redis for the Magento page and default cache | Magento 2 Developer Documentation

After installed Redis

It looks better than before. So, we revised session to Redis, faster than file, of course. The backend cache with Redis faster than as well.

The comparison:

Without FPC (build-in backend cache + session in files):
Home page: 2.6 requests/sec
Product list: not updated yet
Product detail: not updated yet
Search: not updated yet
Sample API: not updated yet

With build-in FPC (build-in backend cache + session in files):
Home page: 4.5 requests/sec
Product list: not updated yet
Product detail: not updated yet
Search: not updated yet
Sample API: not updated yet

With Redis for all FPC, backend cache, session:
Home page: 11.5 requests/sec
Product list: not updated yet
Product detail: not updated yet
Search: not updated yet
Sample API: not updated yet

Varnish

Very fast, at least x10 times of Redis FPC. Because the first request will touch your system, your DB, your engine then the Varnish making cache data for all HTML of rendered page. The second users just access to the cached-version of HTML website. Nothing be threats for your server anymore.

But, I’m still facing problem: 503 backend load failed, it’s investigating. Not done yet.

I already left this product. Just write here as my experience.

Read more

  1. Magento 2.3.1 has released with announcement that it has supported for Redis 5 and PHP 7.2.x
  2. Architecture: Magento on AWS

Top comments (0)