Home›Uncategorised›Magento 2 Performance Tuning: From 7s to 1s TTFB
Uncategorised

Magento 2 Performance Tuning: From 7s to 1s TTFB

📅 21 August 2026 · ⏱ 1 min read · 👤 Maya Simard

A real optimisation case study: Varnish, Redis, Elasticsearch, PHP OPcache, MySQL tuning.

Published 2026-08-21 • Category: Performance • Reading time: 13 min

Baseline metrics

Before optimisation: TTFB 2.1 s, Lighthouse 42, Core Web Vitals — all red.

After: TTFB 0.3 s, Lighthouse 94, every CWV green. Four weeks, $12,000 budget.

Step 1: Varnish

Enabled full Varnish 7.x via the vcl config bundled with M2. Hit rate — 92% for anonymous, 78% for logged-in (ESI for the cart).

Step 2: Redis

Three Redis instances: default cache, page cache, session storage. 2 GB each. The old file-based cache remains only for deployed_version.

Step 3: PHP OPcache + preload

opcache.enable=1
opcache.memory_consumption=512
opcache.max_accelerated_files=65000
opcache.revalidate_freq=0
opcache.save_comments=1
opcache.preload=/var/www/magento/preload.php

Preload shaves another ~40 ms off TTFB.

Step 4: MySQL tuning

innodb_buffer_pool_size = 8G
innodb_log_file_size = 2G
innodb_flush_log_at_trx_commit = 2
query_cache_type = 0
max_connections = 500

Step 5: Elasticsearch

M2 ≥ 2.4 uses Elasticsearch for the catalog. We set up replication, 2 nodes, with a dedicated allocation for product search.

Step 6: CDN + WebP

BunnyCDN in front of /pub/media, automatic WebP on the fly. Mobile LCP went from 3.8 s → 1.6 s.

Step 7: Hyva Theme

Optional but a game-changer. Instead of Knockout + RequireJS + jQuery (~300 KB gzipped JS in Luma) — Alpine.js + TailwindCSS (just ~45 KB). Mobile JS execution time: 2.1 s → 0.3 s.

Leave a Reply

Your email address will not be published. Required fields are marked *