Magento performance hosting
The system requirements of Magento are quite extensive, it requires at least PHP 5.2.0 extended with mcrypt, PDO_MySql and simplexml. For the database Magento needs at least MySQL 4.1.20 with InnoDB storage engine. At MagentoCommerce.com you can find a complete list of requirements. But how do you know if your server meets these system requirements? Check this and follow these three steps.
How to get the most out your Magento install?
Magento is notorious for it speed and performance. But isn’t necessary to have a killer web server to get very reasonable performance, it is all about the configuration of your server and the code of your template. However, after the 1.3 release there are some performance improvements, like Frontend Flat Catalog, and people measure reduction of loading times up to 40%. Another recent development is the Magento Compiler this module compiles all Magento files. From tests this module gave between 25% to 50% better performance. This module is still in beta and should not be used in a production environment for now.
The question is, what else can you do to speed up your Magento install?
Optimize your template for speed
More information can be found at the Magento SEO article.
Enable compression of your files
Mod_deflate allows output from your server to be compressed. To enable it for Magento edit your .htaccess, around line 74, in Magento root directory.
<ifmodule mod_deflate.c> ############################################ ## enable apache served files compression ## http://developer.yahoo.com/performance/rules.html#gzip # Insert filter SetOutputFilter DEFLATE # Netscape 4.x has some problems... BrowserMatch ^Mozilla/4 gzip-only-text/html # Netscape 4.06-4.08 have some more problems BrowserMatch ^Mozilla/4.0 no-gzip # MSIE masquerades as Netscape, but it is fine BrowserMatch bMSIE !no-gzip !gzip-only-text/html # Don't compress images SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary # Make sure proxies don't deliver the wrong content Header append Vary User-Agent env=!dont-vary </ifmodule>
Apache Module mod_expires
mod_expires controls the setting of the Expires HTTP header and the max-age directive of the Cache-Control HTTP header in server responses. To enable Expires HTTP header for Magento you had to change the code underat your .htaccess to.
<ifmodule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 1 month" </ifmodule>
Use PHP Accelerator
Tune your MySQL configuration
You can modify the configuration of the MySQL server to take advantage of the server’s RAM. The efficiency of this step are different, it seems to depends mainly on the number of products. When you have only 100 products, difference will be hardly to notice (below 100ms). But for shops with over 50.000 products there is a huge reduction of the loading time. To give an idea about the settings, for shops with only a limit number of products a query_cache_limit of 1MB will be enough. For larger stores the optimal query cache value can be 64MB. To get the optimal value you really need some testing. A good start point for your Query Cache configuration can be found here.
Speed up your Cache files
Magento makes extensive use of file-based storage for caching and session storage. The slowest component in a server is the hard drive, so if you use a memory-based file system such as tmpfs, you can save all those extra disk IO cycles by storing these temporary files in memory instead of storing them on your slow hard drive.
Let´s do this with tmpfs
Let’s say your Magento install is at
/var/www/domain.com/ so your cache and session directories are
/var/www/domain.com/var/session/ For cache we will allocate a max of 256MB RAM and for sessions 64MB RAM. It is important to give access to everyone (e.g your webserver Apache)
mount -t tmpfs -o size=256M,mode=0744 tmpfs /var/www/domain.com/var/cache/ mount -t tmpfs -o size=64M,mode=0744 tmpfs /var/www/domain.com/var/session/
Now it might be a good idea to restore these volumes each time your server boots. Just add the following lines to your
tmpfs /var/www/domain.com/var/cache/ tmpfs size=256,mode=0744 0 0 tmpfs /var/www/domain.com/var/session/ tmpfs size=64,mode=0744 0 0
Please note, your tmpfs is temporary in the sense that nothing will be created on your hard drive. If you reboot, everything in tmpfs will be lost.
Save the sessions in your database
Another option for the sessions is to save them in your database. Magento supports this very well and it is one small step to make this work. Just edit
it will then save all sessions in the database which is a much quicker access than the filesystem. When you use a cluster enviroment you had to use this option.
Enable Apache KeepAlives
Enable Apache KeepAlives, this allows persistent connections. These long-lived HTTP sessions allow multiple requests to be send over the same TCP connection, this can result in an almost 50% speedup in latency times for HTML documents with lots of images. An example setting can be:
KeepAlive On KeepAliveTimeout 2
Need more Magento Performance?
Ok, you are a very successful online retailer and it is time to cluster, no problem. This means that one single-server doesn’t have enough power to keep your customers happy and so you need a clustered environment with two or more servers. A first step can be to start using a Content Delivery Network (CDN).
The most easy to start is using an separate media server, e.g. media.domain.com. Magento has native support for this. You can configure ‘Base Media URL’ secure and unsecure under web configurations. This allow you to serve media form one server without the needs to synchronize any directory. Another option is to start using a Content Delivery Network (CDN) for delivering the static files like images. MaxCDN has some options for Magento that are quite nice.
Another option is to use more than one database servers this tactic is called “database replication”. One database will be the “master” and all others will be called “slaves”. The master is the only database that accepts any sort of write-base queries. These write queries are then replicated to any of the slave servers in real-time. A post at the Magento blog will get you on the right track.
To summarize, 5 quick wins
- move the the rules in the .htaccess files from the directories to virtualhost configuration directives
- install Xcache or APC PHP cache accelerator
- clean up your template and layout
- make sure Apache KeepAlives is enabled
- use a memory-based file system for Magento’s
This article give a introduction how to improve your Magento site performance, none of these tips are revolutionary. Because every website’s scenario is different, when you really want to get the most out of your Magento install you need to hire a professional. The only way to discover the optimal server configuration is testing, a really great tool to use is Browsermob, load testing with real web browsers so you will able to put even the Magento checkout process under load testing.
Now, all of the above you can’t do on your average host, you need a VPS that provides you full control of your server environment. Check out WestHost’s sister company, VPS.net, for a VPS environment that would give you full control.