Magento / Web Apps

Magento 2 Performance Checklist

by , , revisited on

Magento 2 is good and great, but it is a very large framework with many files. If installed on a misconfigured server, Magento 2 performance can lead to a store that your customer will leave immediately.

Let’s review best practices and software required to run Magento 2 with excellent performance.

1. Use PHP 7

Magento 2 is 100% compatible with new and shiny PHP 7, which is all about performance. PHP 7 performs twice as fast compared to previous versions.

Order professional Magento 2 server setup to get your new Magento 2 store up and running with PHP 7, Varnish and Percona MySQL

2. Use Varnish

We are really excited that Magento 2 supports Varnish out of the box. You absolutely must use it if you want lightning fast performance. Here is our fine tuned Varnish VCL for Magento 2.

Make sure to set your TTL setting to highest possible, e.g. 2 weeks.

3. Use HTTP2 and its Server Push

Magento 2 doesn’t support HTTP 2 server push but you can make it. This should be coupled with a server side solution (Varnish VCL or nginx) to track down repeat visitors in order to avoid unnecessary pushes.

4. Build your own CDN

Cloudflare provides simply inconsistent results. You may be getting as much as 600ms for a cached asset in Cloudflare, tested from the same location (e.g. LAX). That is instead of expected max of ~100ms.

So if you’re after consistent performance for your user and you know particular locations they mostly originate from, it’s time to setup your own CDN. The DYI CDN solutions can be found online:

  • How to build your own CDN using BIND, GeoIP, Nginx, and Varnish – a bit dated article from year 2010, but overall providing an overview on how you can implement CDN of your own. Note that you should use nginx for SSL termination only, and Varnish can cache things differently. So don’t follow everything that post says.

  • BIND can be configured for GeoIP just fine without any patching. All the articles out there are outdated. If you search well you will find a good reference to configuring GeoDNS in BIND: example1, example2. However, BIND does not support newer .mmdb GeoIP format (yet) and the free .dat format is no longer available for free autoupdates.

  • PowerDNS software has got GeoIP backend, with support for newer .mmdb file format. However, this its documentation is a bit buggy.mmdb support start at version 4.2 which is yet to be released and distributed.

  • ClouDNS provides free GeoDNS trial for their service, so this can be used as alternative to setting up BIND with GeoIP.

Route53 by Amazon is another GeoDNS provider.

5. Use Redis

You can still use Full page cache Redis cache even with Varnish configured. This is additional caching layer, but it never hurts to have more. What’s great is that new Magento supports full page cache in Community edition for free! There is no longer a need for third party full page cache plugin.

Follow this instructions to configure Redis cache in Magento 2.

Use Memcached

Get additional performance gain by storing sessions in RAM. Due to some incompatibility in configuring session store to Redis, we recommend to use Memcached for storing Magento 2 sessions.

Starting with Magento 2.0.6, there is no issue in storing sessions in RAM with Redis. Here is how to configure Magento sessions to be stored in Redis.

6. Speedup your search

By default Magento 2 search is slow. No need to worry, as you can leverage open source Sphinx search engine which will not only index your products and provide very accurate results. It will also increase the speed of searches a lot! We recommend Advanced Sphinx Search Pro for Magento 2 for implementing Sphinx support in your Magento 2.

7. Improve product image display performance

The default M2 installation uses very slow AJAX-ified image loading. For performance reasons, we recommend using Magic Zoom Plus plugin. Just check their demo to see how faster it is! And it works without Javascript.

While we’re at at it. Make sure to setup Magento 2 cron jobs properly!

8. Magento 2 Settings

Ensure optimal Magento 2 settings in admin area or through command line.

9. Disable unused modules


 n98-magerun2 module:disable Dotdigitalgroup_Email

10. Pre-generate URLs

On a large store you can fix URL issues as well as “warm-up” the URL cache after importing large set of products, by using this plugin.

So if you have a problem with messed up URLs (products displaying wrong URLs), run:

DELETE FROM catalog_product_entity_varchar where attribute_id =(SELECT attribute_id FROM eav_attribute WHERE attribute_code LIKE 'url_key' and entity_type_id=4 );

Then run URL regeneration.

11. Fix sessions

Magento 2 with Varnish has a bug resulting in dozens, hundreds or thousands of extraneous session files.
Until this is resolved, you may want to setup a cron to clean those unneeded session files. Otherwise they will contribute to slower session start.

find . -type f -name "sess_*" -exec grep '"remote_addr";s:9:""' {} \; -exec rm {} \;

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.