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.
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.
1 2 3 4 |
Listen 8080 <VirtualHost *:8080> DocumentRoot "/www/example1" ServerName www.example.com |
Varnish system configuration
Open /etc/sysconfig/varnish (or /etc/default/varnish on Debian and Ubuntu) and set the Varnish listen port to 80:
1 |
VARNISH_LISTEN_PORT=80 |
For Varnish 4.*, make sure that DAEMON_OPTS contains the correct listening port for the -a parameter:
1 2 3 4 5 |
DAEMON_OPTS="-a :80 \ -T localhost:6082 \ -f /etc/varnish/default.vcl \ -S /etc/varnish/secret \ -s malloc,256m" |
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.
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.
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.
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:
1 |
mysql -u root -p |
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:
1 2 3 4 5 |
create database magento_quote; GRANT ALL ON magento_quote.* TO magento_quote@localhost IDENTIFIED BY 'magento_quote'; create database magento_sales; GRANT ALL ON magento_sales.* TO magento_sales@localhost IDENTIFIED BY 'magento_sales'; |
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.
1 2 3 |
magento setup:db-schema:split-quote --host="localhost" --dbname="magento_quote" --username="magento_quote" --password="magento_quote" magento setup:db-schema:split-sales --host="localhost" --dbname="magento_sales" --username="magento_sales" --password="magento_sales" |
Thanks !!!
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.
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.