Magento Performance Optimization

Exclusive offer: get 50% off this eBook here
Instant Magento Performance Optimization How-to [Instant]

Instant Magento Performance Optimization How-to [Instant] — Save 50%

Improve performance of your Magento stores, using practical, handson recipes with this book and ebook

$14.99    $7.50
by Nayrolles Mathieu | May 2013 | e-Commerce Open Source

In this article by Nayrolles Mathieu author of Instant Magento Performance Optimization How-to [Instant], we will help you learn Magento's built-in caching system for saving frequently asked requests. It also introduces you to the slowest component of a computer, the hard drive, and how Magento makes massive use of it. This lets you use your available RAM. It will show you how to configure a set of loosely connected computers working together for handling more and more customers.

(For more resources related to this topic, see here.)

Using the Magento caching system

A cache is a system that stores data so that future requests for that data can be served faster. Having cache is definitely a good thing, but the caching system of Magento is not super effective.

How to do it...

Let's begin with cache enabling, even if most users are well aware of this one. Go to your backend console and then go to System | Cache Management.

By default, all caches are enabled; but some have a negative impact. You have to disable caches for the following items:

  • Collections Data

  • EAV types and attributes

  • Web Services Configuration

The following table shows the improvement made due to the previous settings, that is, by disabling the selected caches:

Type

 

Requests

 

Load time

 

Size

 

All caches enabled

 

35

 

1.12 seconds

 

713.4 KB

 

Selected cache enabled

 

1

 

903 milliseconds

 

713.4 KB

 

 

Another little win, 200 milliseconds, just enough to fulfill the promise made in the previous recipes.

How it works...

A cache is a system that stores data so that future requests for that data can be served faster. A web cache stores copies of documents passing through it, and subsequent requests may be satisfied from the cache if a set of conditions exists.

There are many hypotheses out there to explain this weird optimization. The main one is that the Magento core has to parse the cache and check in MySQL to compare updated data, and this causes a huge delay. In fact, by allowing Magento to do these kinds of operations, we don't use the full resources of our systems.

Using a memory-based filesystem for caching

We can easily say that the slowest component of a computer is its hard drive. Moreover, the Magento caching system makes massive use of this component. It would be amazing if we could store the Magento cache files directly inside the memory.

How to do it...

Open a new console on your Unix server and enter the following command:

sudo mount -t tmpfs -o size=256M,mode=0777 tmpfs /var/www/YOUR_DOMAIN.
COM/var/cache/

The path is based on a common installation of Apache with Magento; pay attention to your configuration when typing this command.

You have to repeat this command every time the server starts up or you can automatize it by adding the following line into your /etc/fstab file:

tmpfs /var/www/YOUR_DOMAIN.COM/var/cache/ tmpfs size=256,mode=0777 0 0

All the caching mechanisms of Magento will now work with a memory-based filesystem instead of the classical filesystem.

How it works...

This newly created filesystem is intended to appear as a mounted filesystem, but takes place in the RAM. Of course, the access time of this kind of filesystem is extremely slow in comparison with a classical hard drive. However, all files updated or created are temporary because of the nature of this filesystem. Nothing will be written in the hard drive, and if you reboot everything will be lost. If you plan to reboot your server, you have to save the volatile files in your hard drive, unmount the memory-based system, and then copy the saved data from tmpfs in the cache folder. With the second command, the folder will be remounted automatically after the reboot.

Clustering

If you have successfully applied all the techniques and your Magento is still slow, it means that you are a very prosperous online retailer and it's time to leave the comfortable world where there is a single server. To keep your customers satisfied, you have to invest in hardware; the tweaking time is now over.

How to do it...

If you own a single server, you can begin by separating your database in a dedicated server. In order to do this, you have to invest in another server and install MySQL on it (get your host to do it for you), and then extract your database from your first server and import it to your new server. Magento stays on your first server; you have to modify the database connection. Go to /app/etc/local.xml and modify the following lines to fit the new server parameters:

<connection>|
<host>|<![CDATA[NEW_SERVER_ADDRESS]]>|</host>|
<username>|<![CDATA[NEW_USER_NAME]]>|</username>|
<password>|<![CDATA[NEW_PASSWORD]]>|</password>|
<dbname>|<![CDATA[NEW 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>|

As simple as that. You now use a dedicated database server and improve your store performance.

The second step in clustering our environment could be using a CDN for our images, CSS, and scripts. A CDN is an independent server optimized for delivering static content such as images, CSS, and scripts. In this way, our web server can focus on running Magento and the CDN can focus on displaying static content. The good news is that Magento has native support to do this.

In your Magento backend, navigate to System | General | Web | Unsecure.

If you still have CSS and JavaScript compressed from the previous recipes, you just have to copy your media directory from your main server to your CDN server. If it's not the case anymore, you have to modify the Base Skin URL field and the Base JavaScript URL field. Also, if for some reason you use the secure URL for that kind of content, don't forget to apply the changes to the secure part as well.

How it works...

That's a very good start. Let's summarize it. We were using a single server for all requests, and now, depending on the request, we use three different servers. The first one handles all the Magento work for building pages, the second one handles the data-related operations, and the last one provides static content. With this kind of architecture, each server can focus on only one purpose.

Summary

This article helped you learn Magento's built-in caching system for saving frequently asked requests. It also introduced you on Magento makes massive use of hard drive which lets you use your available RAM. It also helped you on how to configure a set of loosely connected computers working together for handling more and more customers.

Resources for Article :


Further resources on this subject:


Instant Magento Performance Optimization How-to [Instant] Improve performance of your Magento stores, using practical, handson recipes with this book and ebook
Published: February 2013
eBook Price: $14.99
See more
Select your format and quantity:

About the Author :


Nayrolles Mathieu

Nayrolles Mathieu was born in France, and it is where he started his studies in Computing Sciences at eXia.Cesi and passed the Diploma in Information Systems Management. He travelled to Europe and completed various internships, where he learned how to optimize in industrial environments.

In the fourth year, he decided to pursue a double diploma course at UQAM, Québec, Canada. During his study at UQAM, he was awarded for one of his publications, Specification and Detection of SOA Antipatterns, in the 10th International Conference on Service-Oriented Computing. He is still completing his last year in both schools, and has written two Master's theses in the Artificial Intelligence and Quality fields.

He has worked for companies worldwide, such as Eurocopter and Saint-Gobain. Currently, he is giving courses on agile development, service-oriented architectures, business intelligence, and data mining at the bachelor level in UQAM and eXia.Cesi, along with his own studies.

You can find out more about him on his website, www.mathieu-nayrolles.com.

Books From Packt


Magento 1.3 Sales Tactics Cookbook
Magento 1.3 Sales Tactics Cookbook

Magento 1.3 Theme Design
Magento 1.3 Theme Design

Magento 1.4 Themes Design
Magento 1.4 Themes Design

Magento 1.4 Theming Cookbook
Magento 1.4 Theming Cookbook

Magento 1.4 Development Cookbook
Magento 1.4 Development Cookbook

Magento 1.3: PHP Developer's Guide
Magento 1.3: PHP Developer's Guide

Mastering Magento
Mastering Magento

Magento: Beginner's Guide
Magento: Beginner's Guide


No votes yet

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
g
w
P
Q
w
j
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software