Magento Optimization Guide

This topic provides instructions for optimizing the performance of your production deployment. This process should be followed by technical users responsible for stores running in production to optimize performance.

Assumptions

  • You installed Magento using Composer or a compressed archive
  • You will be using this environment to run your live production instance of Magento 2

Server - Software Recommendations

The following is a list of recommended software for production instances in order of impact:

For multi-server deployments or for merchants planning on scaling their business we recommend the following:

  • Redis for sessions (from 2.0.6+)
  • A separate Redis instance as your default cache
  • Do not use this instance for page cache

Server - Composer Optimization

After running setup:di:compile to generate classes, use composer to update the autoloader.

Run the following composer command to generate an optimized composer class map that supports faster auto-loading.

composer dump-autoload -o

Server - PHP Configuration

We recommend enabling and tuning PHP opcache for maximum performance. Edit your opcache.ini file to include the following:

opcache.enable_cli=1
opcache.memory_consumption=512
opcache.max_accelerated_files=100000
opcache.validate_timestamps=0
opcache.consistency_checks=0

When you fine tune the memory allocation for opcache, take into account the size of Magento’s code base and all your extensions. Magento’s performance team uses the values in the preceding example for testing because it provides enough space in opcache for the average number of installed extensions.

If you are on a low memory machine and you do not have many extensions or customizations installed, use the following settings to get a similar result:

opcache.memory_consumption=64
opcache.max_accelerated_files=60000

Server - Redis Configuration & Tuning

Sessions

Consider how sessions are flushed from the cache and your merchants abandoned cart strategy.

Caches

Estimate a memory size to fit the total number of effective skus, product pages and content pages you expect will be used.

Magento - Performance Optimizations

Enable these performance optimizations to improve the store front responsiveness of your Magento instance.

Go to the Admin in default of developer mode and change the following settings for store front asset optimization:

Stores -> Configuration -> Advanced -> Developer

Settings Group Setting Value
Grid Settings Asynchronous indexing Enable
CSS Settings Minify CSS Files Yes
Javascript Settings Minify JavaScript Files Yes
Javascript Settings Enable JavaScript Bundling Yes
Template Settings Minify HTML Yes

Stores -> Configuration -> Sales -> Sales Emails

Settings Group Setting Value
General Settings Asynchronous Sending Enable

System -> Index Management

Set all indexers to “Update by Schedule” mode.

Production Mode

Switching to production mode improves store front responsiveness and prevents long initial page load times that can occur in default mode.

Run the following commands to switch to production mode:

bin/magento deploy:mode:set production