|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +group: config-guide |
| 4 | +subgroup: Optimization |
| 5 | +title: Magento Optimization Guide |
| 6 | +menu_title: Magento Optimization Guide |
| 7 | +menu_order: 100 |
| 8 | +version: 2.1 |
| 9 | +github_link: config-guide/prod/prod_perf-optimize.md |
| 10 | +--- |
| 11 | + |
| 12 | +This topic provides instructions for optimizing the performance of your production deployment. |
| 13 | +This process should be followed by technical users responsible for stores running in production to optimize performance. |
| 14 | + |
| 15 | +### Assumptions |
| 16 | + |
| 17 | +* You installed Magento using [Composer][composer-install] or a [compressed archive][zip-install] |
| 18 | +* You will be using this environment to run your live production instance of Magento 2 |
| 19 | + |
| 20 | +### Server - Software Recommendations |
| 21 | + |
| 22 | +The following is a list of recommended software for production instances in order of impact: |
| 23 | + |
| 24 | +* [Varnish cache][config-varnish] |
| 25 | +* PHP 7 |
| 26 | +* (Enterprise only) Use the [Elasticsearch & Elasticsearch Search Adapter][elasticsearch] |
| 27 | +* Nginx and [PHP-FPM][php-fpm] |
| 28 | + |
| 29 | +For multi-server deployments or for merchants planning on scaling their business we recommend the following: |
| 30 | + |
| 31 | +* [Redis][redis-session] for sessions (from 2.0.6+) |
| 32 | +* A separate Redis instance as your [default cache][redis-default-cache] |
| 33 | + * Do not use this instance for page cache |
| 34 | + |
| 35 | +### Server - Composer Optimization |
| 36 | + |
| 37 | +After running `setup:di:compile` to generate classes, use composer to update the autoloader. |
| 38 | + |
| 39 | +Run the following [composer command][composer-dump-autoload] to generate an optimized composer class map that supports faster auto-loading. |
| 40 | + |
| 41 | + composer dump-autoload -o |
| 42 | + |
| 43 | +### Server - PHP Configuration |
| 44 | + |
| 45 | +We recommend enabling and tuning PHP opcache for maximum performance. |
| 46 | +Edit your `opcache.ini` file to include the following: |
| 47 | + |
| 48 | + opcache.enable_cli=1 |
| 49 | + opcache.memory_consumption=512 |
| 50 | + opcache.max_accelerated_files=100000 |
| 51 | + opcache.validate_timestamps=0 |
| 52 | + opcache.consistency_checks=0 |
| 53 | + |
| 54 | +When you fine tune the memory allocation for opcache, take into account the size of Magento's code base and all your extensions. |
| 55 | +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. |
| 56 | + |
| 57 | +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: |
| 58 | + |
| 59 | + opcache.memory_consumption=64 |
| 60 | + opcache.max_accelerated_files=60000 |
| 61 | + |
| 62 | +### Server - Redis Configuration & Tuning |
| 63 | + |
| 64 | +#### Sessions |
| 65 | + |
| 66 | +Consider how sessions are flushed from the cache and your merchants abandoned cart strategy. |
| 67 | + |
| 68 | +#### Caches |
| 69 | + |
| 70 | +Estimate a memory size to fit the total number of effective skus, product pages and content pages you expect will be used. |
| 71 | + |
| 72 | +### Magento - Performance Optimizations |
| 73 | + |
| 74 | +Enable these performance optimizations to improve the store front responsiveness of your Magento instance. |
| 75 | + |
| 76 | + |
| 77 | +Go to the Admin in default of developer mode and change the following settings for store front asset optimization: |
| 78 | + |
| 79 | +#### Stores -> Configuration -> Advanced -> Developer |
| 80 | + |
| 81 | +| Settings Group | Setting | Value | |
| 82 | +| ------------------- | -------------------------- | ------ | |
| 83 | +| Grid Settings | Asynchronous indexing | Enable | |
| 84 | +| CSS Settings | Minify CSS Files | Yes | |
| 85 | +| Javascript Settings | Minify JavaScript Files | Yes | |
| 86 | +| Javascript Settings | Enable JavaScript Bundling | Yes | |
| 87 | +| Template Settings | Minify HTML | Yes | |
| 88 | + |
| 89 | +#### Stores -> Configuration -> Sales -> Sales Emails |
| 90 | + |
| 91 | +| Settings Group | Setting | Value | |
| 92 | +| ---------------- | -------------------- | ------ | |
| 93 | +| General Settings | Asynchronous Sending | Enable | |
| 94 | + |
| 95 | +#### Stores -> Index Management |
| 96 | + |
| 97 | +Set all indexers to "Update on Schedule" mode. |
| 98 | + |
| 99 | + |
| 100 | +### Production Mode |
| 101 | + |
| 102 | +Switching to production mode improves store front responsiveness and prevents long initial page load times that can occur in default mode. |
| 103 | + |
| 104 | +Run the following commands to switch to production mode: |
| 105 | + |
| 106 | +~~~ |
| 107 | +bin/magento setup:static-content:deploy |
| 108 | +bin/magento setup:di:compile |
| 109 | +bin/magento deploy:mode:set -s production |
| 110 | +bin/magento index:reindex |
| 111 | +bin/magento cache:flush |
| 112 | +~~~ |
| 113 | + |
| 114 | +[composer-install]: {{page.baseurl}}install-gde/prereq/integrator_install.html |
| 115 | +[zip-install]: {{page.baseurl}}install-gde/prereq/zip_install.html |
| 116 | +[config-varnish]: {{page.baseurl}}config-guide/varnish/config-varnish.html |
| 117 | +[elasticsearch]: {{page.baseurl}}config-guide/elasticsearch/es-overview.html |
| 118 | +[php-fpm]: https://php-fpm.org/ |
| 119 | +[redis-session]: {{page.baseurl}}config-guide/redis/redis-session.html |
| 120 | +[redis-default-cache]: {{page.baseurl}}config-guide/redis/redis-pg-cache.html |
| 121 | +[composer-dump-autoload]: https://getcomposer.org/doc/03-cli.md#dump-autoload |
0 commit comments