Magento / Web Apps

Magento 2 Performance Checklist

by , , revisited on

We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you.
Active subscription is required.

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 latest PHP 7

Magento 2 is 100% compatible with the latest versions of 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 the 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 an additional caching layer, but it never hurts to have more.
What’s great is that the new Magento supports full page cache in the Community edition for free! There is no longer a need for a 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.

By default Magento 2 search is slow. No need to worry, as you can leverage the 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.

Medium or large servers will benefit from ElasticSearch installation instead.

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 the 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 a 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 set up a cron to clean those unneeded session files. Otherwise, they will contribute to a slower session start.

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

The above fix applies to sessions stored in files.

We recommend storing sessions in Redis.

Make sure you fix up unnecessary sessions creating by using a module.

12. Dynamic ETags

You can save bandwidth and improve performance by adding conditional GET feature to your NGINX.

13. A better cron

Magento default cron tasks implementation is errr.. bad. You can use an alternative cron module here

14. Enable DNS cache

Magento 2 makes use of some external APIs and sure enough, this results in many DNS lookups produced by it. You can speed up your checkout experience, and squeeze out more performance from it, by enabling DNS cache. Here is how to enable DNS cache on your server.

15. Stay away from bad themes and modules

Be sure to stay away from the Argento theme or at least disable SEO modules that it comes with. There is a serious issue.

16. Enable Flat Catalog

Advice from here:

Using Flat Catalog instead of managing catalog data in many tables by the EAV will help you to speed up your product collection.
In order to enable Flat Catalog, navigate to Stores ➡ Settings ➡ Configuration in the Admin panel. Then select Catalog on the left panel under the Catalog tab. Expand the Storefront section and scroll down to Use Flat Catalog Category and Use Flat Catalog Product. Select “Yes” in both sections.

17. Maintain your database

Magento 2 does not scale well when your database is growing. Reason? Bugs!
Make sure to clean up your huge Magento 2 database.

18. Reduce session locking

Session locking is a problem, especially with AJAX requests, which do not even need locks.
Resolve session bottleneck in Magento AJAX Requests by using a special module.

Install and enable it, using clearmage2:

clearmage2 --install getpagespeed/magento2-session-unblocker --enable IntegerNet_SessionUnblocker

19. Schedule your maintenance

Don’t do upgrades, fixes, and other things at a random time. If you are not experiencing serious issues, or simply want to do a maintenance upgrade, do it on a rare schedule. E.g. updating once a month, on the 7th day, is a fine schedule.

The purpose of reducing maintenance windows serves well both the customers and performance. A maintenance results in having to clear cache completely. It takes many days, and for some store weeks to fully warm up / refill the cache. An efficient cache is the one that is not cleared often!

20. Clean up unused media

Over time, the media file directory can grow huge. To clean it up, use EAVCleaner.
Furthermore, the image cache (thumbnails), grows over time with unused image’s thumbnails. Do image cache clearing around once in 1 year:

n98-magerun media:cache:image:clear
# flush cache especially FPC, so that Magento can dynamically recreate thumbnails upon access
n98-magerun cache:flush
# prewarm cache for your visitor's convenience and faster pages
php bin/magento catalog:image:resize

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

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

%d bloggers like this: