Speeding up Magento

Optimizing your Magento for fast ecommerce

Since its launch in 2007, Magento has quickly become the most popular opensource e-commerce platform. However, a fresh Magento install is notoriously slow. Even with modern hardware, a default install will see page generation taking up to 10 seconds. So it’s no coincidence that most posts on the Magento forum are speed complaints.

Magento speed issues generally cover two categories. The first is the latency of a single pageview with an otherwise quiet install. The second is the latency of a single pageview among many concurrent pageviews. Both require a different approach and testing methodology. However, to optimize a busy shop for concurrency, it should first be optimized for an isolated pageview. This articles focuses on this very task. For high-concurrency optimization, please refer to the advanced articles elsewhere on this site.

Where to start tuning your own Magento shop? There are long lists of possible tweaks on the web, some of which require significant effort to implement and only yield marginal speed improvement in very specific situations. The tips below cover the most essential optimizations that are currently known and can be applied to 98% of existing Magento shops.

Note: some tips require server administrator access. Unless you are a sysadmin, you should find out whether your hosting provider has implemented these. Also refer to our “How to pick a speedy hosting provider” guide.

The two major Magento bottlenecks of a regular install are disk access and database query time, so read the tips covering these subjects first. After that, you should analyze your own particular template and selection of modules. Third, have a look at the Magento specific methods to cache parts of the page generation output and cache transfer of static content. Fourth, you should study the generic tips for web application stack optimization.

Storage

Due to Magento’s architectural design, a single Magento pageview makes the server open thousands of PHP, CSS, Javascript and image files. Therefore, optimizing random disk access speed should be first on your list. There are two common strategies to achieve this.

First is to use the fastest disks on the market. Solid State Drives (SSD) are pricey but lightning fast. They excel especially in random access since they lack moving parts. Pick your SSDs based on industry reviews such as The SSD Review.

A seconds strategy, if the byte size of your shop permits, is to load the whole shop into RAM. The easiest way is to map part of your system memory as a folder in your filesystem, a.k.a. a ramdisk or tmpfs. For specific instructions, please refer to the Linux Ramdisk Howto. Evident advantage is that RAM is a magnitude faster than SSD storage. Drawbacks include high costs and a theoretical limitation on the amount of RAM that you can fit in a single server. Another important measure: due to the nature of RAM, you should configure periodic synchronization between the ramdisk and a persistant storage medium, otherwise your new SKU’s are lost at the next reboot.

Needless to say that disk access times will be random at best, if you share your storage with other sites. So dedicated storage is the way to go. It follows that separate storage for your front-end shop and database is highly recommended.

MySQL

A defaul Magento install executes over a hundred database queries to generate a single page of content. And if you enable custom plugins, there are even more queries. To speed things up, you should verify that you get the most out of the build-in query cache of MySQL. See the query cache section in our MySQL guide. Note that it’s no use to optimize the index cache (key_buffer) because that only applies to MyISAM tables and Magento mostly uses InnoDB tables.

Webserver

Webserver optimization boils down to a) minimizing latency in the webserver itself and b) configuration the webserver for better interaction the the client.

Decreasing webserver latency can be partially achieved by switching to specific webserver software that has sacrificed features for speed. Examples are Nginx and Lighttpd. People have reported 10s of miliseconds of gain per request compared to Apache, especially on heavily loaded servers.

You could also reconfigure your webserver to smooth interaction with clients. Well known targets:

Practical examples of these tweaks can be found in the Apache section.

Template & configuration

Make sure your site conforms to the generic guidelines for speedy design. If you buy a design or template, confirm that it was build with speed in mind. As a guideline, you should keep the total size of your frontpage (HTML, images, javascript, css) under 200KB.

In the Magento configuration, disable all extensions that you don’t use. Disable all extended features. Enable all caching under System > Cache Management. Use the internal functionality to combine javascript and CSS.

Third party magic

Many commercial components exist that claim to speed up Magento page generation. In general, they replace core Magento code so you should be cautious when updating Magento to a newer release.

Note: we can’t recommend a specific extension. Please post your mileage in the comments.

More extensions at http://www.magentocommerce.com/magento-connect/filter/all/performance.

Conclusion

This article described the most beneficial optimization strategies for Magento. Low hanging fruit is optimizing the disk i/o bottleneck and the MySQL and webserver cache features. Depending on the nature of the shop, optimizing the template and installing a third party caching mechanism are second in line to yield the best speed gain.



16 comments

Leave a comment

optional