
Over the past few months, we've dedicated significant resources to diagnose and optimize Magento's performance. Now that Magento's 1.0 feature set is mostly complete, we are glad to share some of our work and the effort that has gone towards the goal of making Magento fast and furious. We are extremely happy with the results of our testing and benchmarks.
With such extensive features, functionality and flexibility performance may sometimes take a hit, and Magento is no exception to this rule. But there are performance gains in every incremental improvement, and we're starting to see significant results in the latest release. Below are a few of the performance improvements that appear in Magento's latest release.
From our performance and load tests we have found that the latest Magento release outperforms version 0.8.17240 by almost double. Below we show a graph of one of the load tests we ran using Apache Benchmark (ab) comparing the two Magento versions. We experienced similar results throughout our tests and comparisons of the two versions.
While we continue to improve Magento's core performance, there are additional improvements that Magento users can implement to yield performance gains in a single-server environment:
Example my.cnf:
As any successful online retailer knows, a growing business means growing pains. If your store is a huge success, then you'll undoubtedly require more horsepower to keep your customers happy. This means leaving the world of single-server websites and moving to a clustered environment with two or more servers.
There are varying ways to accomplish this, but a typical first step is to add more web servers and place them all behind a load balancer, which will distribute the load fairly among all web servers. This method is popular because (a) web servers are cheaper than database servers; and (b) there's really no limit to the amount of web servers you can add.
Note: One current limitation in Magento is that there is no official method to propagate catalog images to each web node. If you're not comfortable setting up some sort of facility to do this, then you may want to hire a professional or try a different method of scaling.
A second method involves a performance tactic called “database replication.” When using replication, you will have two or more database servers in your cluster. One will be the “master” and the rest will be called “slaves.” The master is the only database server that accepts any sort of write-based queries. These write queries are then replicated by each of the slaves in real-time (or very close to it). The advantage of this setup is that Magento can issue read queries to any of the slave servers, saving all the write queries for the master database. A database is traditionally a difficult component to scale horizontally, so replication is a happy compromise.
The initial setup and configuration for MySQL replication is out of the scope of this document, but we can refer you to the experts. Here is a tutorial that explains all the details.
Once you have MySQL replication functioning, configuring Magento to use multiple database servers is a relatively simple task. The only file you will have to edit is app/etc/local.xml. An example is shown below. As you can see, there are two database connections configured, one called default_setup and one called default_read. The default_setup connection will be used for all write-based queries, and the default_read connection will be used for all read-based queries.
Example app/etc/local.xml:
This article has only covered a few of the well-known tactics for improving site performance. However, every website's scenario is slightly different, so it's often worth hiring a professional to appraise the needs of your site and provide you with possible upgrade options. But if you're comfortable with Linux and confident when working with configuration files, try out a few of our suggestions above. You may be pleasantly surprised.
Have any ideas of your own? We'd love to hear your thoughts. Leave a comment or join the Magento Performance and Optimization Group.