Get Free Audit

Magento 2 Advanced Performance

Feb 20, 2018

2936 Andrey Litvin

Magento 2 Advanced Performance

Magento advanced performance is one of the main factors to lead work more successful. In case you want to keep shoppers stay longer on the webshop, it should provide an excellent shopping experience. Improve Magento 2 performance and enhance customers experience by using modern methods. Here is a couple of techniques that will speed up your webshop even more.

Varnish caching

Varnish Cache is a web application accelerator also known as a caching HTTP reverse proxy. Varnish caches you web server response, stores it in memory and provides this stored response to any equivalent requests without accessing your application directly. Varnish is designed to provide a very fast response and then provide up to 300x speedup depending on the architecture. Magento 2 supports versions 3.0.5 or later or any Varnish 4.x version.

Magento 2 Advanced Performance_1

Using Varnish with Magento 2

Apache 2 configuration

In order to use Varnish with Magento 2, first off, make sure Varnish is installed on your web server. Installation procedure may vary depending on your OS. Varnish responds directly to incoming HTTP request, so your web server (e.g. Apache 2) should be configured to listen on a port other than default port 80. Edit your Apache 2 configuration file and change the value of the listen port to 8080 as an example.

Varnish system configuration

Open /etc/sysconfig/varnish (or /etc/default/varnish on Debian and Ubuntu) and set the Varnish listen port to 80:


For Varnish 4.*, make sure that DAEMON_OPTS contains the correct listening port for the -a parameter:

Magento 2 configuration

Log in to the Magento Admin as an administrator and go to Stores->Configuration->Advanced->System->Full Page Cache. From the Caching Application list, click Varnish Caching. Enter a value in the TTL for the public content field. Expand Varnish Configuration and fill in the required information.

Magento 2 Advanced Performance_2

Database Sharding (Magento Commerce only)

Magento Commerce comes with the ability to use three separate databases for different functions of Magento application. These areas are Checkout, Orders and product data. This separation allows independent scaling and replication and provides additional flexibility how Magento 2 database can be scaled depending on your needs.

Igor Dragun
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor

This Split Database functionality requires you to set up three master databases (they can be hosted on the same server or spread to other servers):

  • One master database for checkout tables.
  • One master database for sales tables (also referred to as Order Management System, or OMS, tables).
  • One master database for the remainder of the Magento 2 application tables.

In addition, you can optionally set up any number of slave databases that serve as load balancers and backups.

Magento 2 Advanced Performance_3Magento 2 Advanced Performance_4

Creating Split Database

In order to create additional databases (in this example they will be hosted on the same server), you need to log in to database server and enter the following command to get to a MySQL command prompt:


Enter the MySQL root user’s password when prompted. Enter the following commands in the order shown to create database instances named magento_quote and magento_sales with the same usernames and passwords:

Configuring Magento Commerce to use the checkout and sales databases

After setting up a total of three master databases, apply the Magento command line to configure Magento to use them. These commands set up database connections and distribute tables among the master databases.

Igor Dragun
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Igor

3 Comments

  1. You’re right, because any WRITE/DELETE/UPDATE query to the slave servers would break the replication, but you still can readdress READ queries to slaves, which will allow to unload the Master MySQL server.

  2. You stated:

    In addition, you can optionally set up any number of slave databases that serve as load balancers and backups.

    The slaves would be asynchronous and therefore not useful for load balancing the production system. That being said, they’d be useful for any number of tasks where you wanted to crunch data but not affect the master.

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *