Book Image

Instant Magento Performance Optimization How-to

By : Nayrolles Mathieu (USD), Mathieu Nayrolles
Book Image

Instant Magento Performance Optimization How-to

By: Nayrolles Mathieu (USD), Mathieu Nayrolles

Overview of this book

The optimization of an attractive commercial website is a non-trivial task that demands time and knowledge. Optimization is a critical point for all growing businesses because a misconfiguration could make you lose money, a lot of money. If your server is overloaded, a browser that wants to turn into a buyer will not be able to, and you will lose customers. "Instant Magento Performance Optimization How-To" is a practical, hands-on guide that provides you with a number of clear, step-by-step exercises to help you reach a high performance level for your Magento stores and keep your customers satisfied.This book looks at tweaks and tips used to boost your Magento Performance, and breaks down the confusion that surrounds the subject.You will learn how to compress your pages, styles, and scripts by almost 80%. We will also take a look at controversial optimization settings such as Magento core compilation or enabling all caching systems. You will discover new applications that improve performance. If you wish your e-businesses to grow and want to keep your customers satisfied, you definitely need this book.
Table of Contents (7 chapters)

Replicating the database (Become an expert)


After getting a bunch of new web servers, we probably could increase the number of database servers; but how to ensure the data integrity if two or more servers want to write new data at the same time?

Getting ready

What we aim at in this recipe is database replication with a master database and slave database(s).

In this architecture, each database belonging to one web server is called a slave database, and they can only retrieve data. They will handle most of the data-related operations, because there is very little new data in Magento (such as new articles and orders). When a web server has to write something, it will do it in the master database (the big one; for the sake of readability, the communication arrows between web servers and the master database are not shown). The block that comprises one web server, one database server, and one CDN server is for reference only. Indeed, you have to adjust the number of servers to your traffic. You could need only one database server for three web servers and only one CDN server. Installations and configurations of MySQL databases and their replications are not treated here. You can find an excellent tutorial on database replication at http://www.howtoforge.com/mysql_database_replication.

How to do it...

In order to replicate the database, we have to configure our Magento servers on our different web servers with two database connections. The first one for writing—this one will be the same for all our servers—and a second one for reading. The reading connection could change if you have many other MySQL servers. Locate and modify the following bunch of code in app/etc/local.xml:

<default_setup>
<connection>
    <host><![CDATA[MASTER_SERVER_ADDRESS]]></host>
    <username><![CDATA[MASTER_USER_NAME]]></username>
    <password><![CDATA[MASTER_PASSWORD]]></password>
    <dbname><![CDATA[MASTER_DATABASE_NAME]]></dbname>
    <initStatements><![CDATA[SET NAMES utf8]]></initStatements>
    <model><![CDATA[mysql4]]></model>
    <type><![CDATA[pdo_mysql]]></type>
    <pdoType><![CDATA[]]></pdoType>
    <active>1</active>
</connection>
</default_setup>

Then add the highlighted lines that follow:

<default_read>
<connection>
    <host><![CDATA[SLAVE_SERVER_ADDRESS]]></host>
    <username><![CDATA[SLAVE_USER_NAME]]></username>
    <password><![CDATA[SLAVE_PASSWORD]]></password>
    <dbname><![CDATA[SLAVE_DATABASE_NAME]]></dbname>
    <initStatements><![CDATA[SET NAMES utf8]]></initStatements>
    <model><![CDATA[mysql4]]></model>
    <type><![CDATA[pdo_mysql]]></type>
    <pdoType><![CDATA[]]></pdoType>
    <active>1</active>
</connection>
</default_read>

All your Magento servers will now write to the master database and read information from the slave servers.

Let's have a look at our website if we turn on all the options we studied before:

  • All the options in the previous recipes

  • Turn on Expires

  • Turn on KeepAlive

  • Turn on the sessions in the database

  • Turn on MySQL tuned on a dedicated server

  • Turn on the memory-based filesystem for the cache directory

  • Turn on gzip

Due to hardware limitations, we cannot benchmark the following settings:

  • Load balancing

  • Database replication

Type

Requests

Load time

Size (KB)

CSS (before)

1

35 milliseconds

110.6

CSS (after)

1

30 milliseconds

21

JS (before)

1

62 milliseconds

360

JS (after)

1

50 milliseconds

85.8

Overall (before)

35

1.12 seconds

713.4

Overall (after)

35

662 milliseconds

330.3

With this recipe, we have increased the loading time by 41 percent and reduced the size by 53 percent. Compared with our first launch in this book, we have won almost two full seconds in displaying exactly the same page.

All your servers are fully configured to focus on performance and your Magento is faster than light! Everything is now ready to keep your innumerable customers satisfied.

In the next recipes we will learn how to use several debugging tools with the aim of finding out where the problems are and being able to choose the appropriate solutions. The tools you'll learn to use are the same as the ones that we used to find more appropriate settings in the previous recipes.

In the past recipes, we have used several tools for identifying the best settings of our Magento instances. These tools have enabled us to find the most adapted tweaks, tips, and tricks in order to speed up our servers. In the coming recipes, you will learn what these amazing tools are and how to use them.