Guide for Magento 2 Performance Best Practices

March 26, 2021 | 07 min read

QuickRead

Improving Magento 2 website performance is always good practice to engage customers for a long time, better conversion rate, and improve in sales & revenue. A high-speed website plays a very important role in the success of your online store to target more customers & achieve desired sales.
This guide will help you to boost your site performance by following performance best practices.

Configuration best practices to improve site performance

Magento 2 provides many settings and tools that you can use to improve response time on the pages.

Indexers

In Magento 2 you can run indexer either in Update on Save or Update on Schedule mode. Recommends to use Update on Schedule mode in production, as this mode stores information about data updates and performs indexation by portions in the background through a specific cron job.
To change mode of indexers go to the System > Tools > Index Management
m2-performance-img1

Caches

Cache is a system location, where frequently accessed data gets stored. By using Magento 2 Cache functionality sites content can load faster.
Enable cache from the System-> Tools-> Cache Management.
We highly recommend activating all the caches in your production server.
m2-performance-img2

Varnish Cache

Varnish cache is the most recommended solution for your site speed improvement. Varnish is a proxy server. It is the layer in front of the server. It is useful to deliver content fast. When a visitor requests your site, then this request will not send to Magento, it’s delivered from cache. Varnish checks if visitors request for Home page, Checkout, without firing a mysql query, or without hitting any php code it delivers content from cache.
To configure Magento to use Varnish log in to the Magento Admin:
  • Go to Stores > Configuration > Advanced > System > Full Page Cache
  • From the Caching Application list, click Varnish Caching
  • Enter a value in the TTL for public content field
  • Expand Varnish Configuration and enter the specific information about your Varnish configuration
m2-performance-img3

Set up Redis

Redis keeps data in the server memory (RAM) for the best performance. Redis is one of the most efficient caching mechanisms, particularly for Magento 2.
Redis allows the server to move the most frequently used page content from disk to RAM. This will increase the response rate when the user makes database and API calls or wants to load a webpage.
  • Advantages of using Redis Cache
  • Very fast in-memory storage.
  • It can be used for php session storage.

Advanced JavaScript bundling

Advanced JavaScript bundling helps to reduce the number of server requests and size of server requests. The goal of JavaScript bundling is to reduce the number and size of requested assets for each page loaded in the browser. To do that, we want to build our bundles so that each page in our store will only need to download a common bundle and a page-specific bundle for each page accessed.

Magento merging and bundling

Magento provides Merging and Bundling to reduce the number of server requests.Enable this setting from backend
Store->Settings->Configuration->Advanced->Developer->Javascript Settings.

Basic bundling

To enable Magento’s built-in bundling from the command line:
php -f bin/magento config:set dev/js/enable_js_bundling 1
This is a native Magento mechanism that combines all assets present in the system and distributes them among same-sized bundles (bundle_0.js, bundle_1.js … bundle_x.js):
Basic merging
To enable Magento’s built-in merging from the command line:
php -f bin/magento config:set dev/js/merge_files 1
This command merges all synchronous JavaScript files into one file. Enabling merging without also enabling bundling is not useful because Magento uses RequireJS.

Client side optimization settings

To improve the storefront responsiveness of your Magento site, go to the Admin and change the following settings:
  • Grid Settings->Asynchronous indexing->Enable
  • Minify CSS Files->Yes
  • Minify JavaScript Files->Yes
  • Enable JavaScript Bundling->Yes
  • Minify HTML->Yes
m2-performance-img4

Database maintenance schedule

We Recommend performing periodic database backups for your development and production server. For better performance schedule your backups to run in succession, one at a time, and at an off-peak time.

Hardware Recommendations

PHP

Magento 2 has differing PHP memory requirements, based on how your system is deployed. In general, if you are setting up a single server store, we recommend configuring PHP memory for 2G. If you are setting up a site using pipeline deployment, we recommend 2 GB on your build server and 1 GB on your web nodes.
Scenarios and expected PHP memory requirements:
  • Webnode serving only storefront pages: 256 MB
  • Webnode serving admin pages with a large catalog: 1 GB
  • Magento 2 cron indexing a site with a large catalog: >256 MB
  • Magento 2 compile and deploy of static assets: 756 MB
  • Magento 2 performance toolkit profile generation: >1 GB PHP RAM, >16 MB MySQL
  • TMP_TABLE_SIZE & MAX_HEAP_TABLE_SIZE settings

MySQL

The Magento 2 data set is delicate to the measure of the memory accessible for putting away information and files. To viably use MySQL information indexation, the measure of memory accessible ought to be, at least, near a large portion of the size of the information put away in the data set.

Conclusion:

Follow the Magneto best practices for a faster website. This guide is helpful to understand the best practices guide and apply to your site to achieve the best performance. If any queries are related to this article then Contact Us.

Latest Posts

Leave A Comment