Instant Magento Performance Optimization How-to [Instant] — Save 50%
Improve performance of your Magento stores, using practical, handson recipes with this book and ebook
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:
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:
All caches enabled
Selected cache enabled
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.
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.
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:
<initStatements>|<![CDATA[SET NAMES utf8]]>|</initStatements>|
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.
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.
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 :
- Magento: Exploring Themes [Article]
- Getting Started with Magento Development [Article]
- Integrating Facebook with Magento [Article]
|Improve performance of your Magento stores, using practical, handson recipes with this book and ebook|
eBook Price: $14.99
About the Author :
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.