Column: Optimize Magento Performance

By Tim Quax on 20 january 2011

It's no secret. No one can hide from it, nor deny it. Magento requires a lot more resources than most web applications. A lot more.

Below are a few optimizations which I think are worthwhile for your Magento install. I'm not going to tell you to turn on indexing (which can be reached at System -> Index management), and I'm not going to tell you to enable caching ( System -> Cache management ). This article is focusing on the more advanced subjects.

I first noticed these flaws when I had chosen it as the platform on which Priodas was to be built. I haven't finished my own webshop software yet, which I am building for my own company. Thus I was searching for suitable webshop software which has so many features I don't have to start coding in someone else's project. That, or switch webshop software simply because of new required features. Priodas is a webshop for wedding accessories. That means the template has to look awesome, and everything still has to be fast.

That's sort of where the problem kicked in. The default Magento installation had load times ranging from 5 - 6s. Yes, that ' S ' stands for seconds. That default theme didn't do too much with graphics, so I knew I was screwed for when I finally got around to creating the template.

And so the battle begins. The battle for decent load times. It's on. It's so very on.

MySQL Optimization

As Magento is especially fond of databases, it relies on it quite heavily. Magento, on a default installation, starts off with a whopping 300+ tables. Even if you don't have any MySQL experience. Just look at the number. Its huge. It's like a drug addict, only to relational architectures.

Whatever the reason for so many tables, optimizing MySQL is the first step in getting your Magento install to live up a little. First off some tools for optimizing MySQL. You can get the most relevant data in a nice format using MySQL Report.

Mysql status report:

Or, if you're inexperienced or just quite lazy, you can use MySQLTuner. MySQLTuner can display statistics about your MySQL server, thus showing the areas where improvements can be made. Just remember it can assist you with your server, but it is not an all-time solution. The only answer to a slacking bad-performing MySQL server is getting your hands dirty.


As far as getting your hands dirty goes, you'll appreciate

Apache Optimization

Caching resources can be a great performance boost. Not only will a client fetch all resources once, instead of downloading them again and again and again, this very decrease in requests results in a decrease in bandwidth and increase in speed. If you want to go beyond the basics and read about ETags, go at it.

If you don't know that much about caching, you can use something like the snippet below. Put it in the apache.conf or httpd.conf or whatever it's called on your server.

<IfModule mod_expires.c>
        ExpiresActive On
        ExpiresDefault "now"
        ExpiresByType image/gif "access plus 2 days"
        ExpiresByType image/png "access plus 2 days"
        ExpiresByType image/jpeg "access plus 2 days"
        ExpiresByType image/jpg "access plus 2 days"
        ExpiresByType image/ico "access plus 2 days"
        ExpiresByType image/icon "access plus 2 days"
        ExpiresByType image/x-icon "access plus 2 days"

        ExpiresByType text/css "access plus 2 days"

        ExpiresByType application/javascript "access plus 2 days"
        ExpiresByType application/x-javascript "access plus 2 days"
        ExpiresByType text/javascript "access plus 2 days"

        ExpiresByType application/x-shockwave-flash "now"
        ExpiresByType video/x-flv "now"
        ExpiresByType application/octet-stream "now"

Compressing resources can be a real timesaver too. It works like a charm, and its the most effective on text files such as HTML and javascript files.

To enable compressing, set this in your .htaccess:

SetOutputFilter DEFLATE

HTML Optimization

If you do have influence over the templates that will be installed, you can optimize your HTML and CSS. This is a great performance boost, as most Magento templates are slow as hell. The biggest win, for me personally on default templates, was getting rid of most of the javascript files that were loaded. The ones that have to be loaded can be transferred to the bottom of the page. See, everything in the <head> section is downloaded before the downloading is continued. Furthermore, at the time of actually loading the javascript files, everything slows down quite a bit. The default template had like 9 js files, of which 6 weren't used. Opportunities, opportunities.

For further HTML optimization, YSlow is a great tool to help you with this task. Going into the details of optimizing HTML and CSS requires a lot of expertise, therefore it's a bit out of scope for the article.

Server optimization

Although it is the last, its certainly not least. I can't stress this enough when I say that you need good hosting. Magento relies heavily on its caching (partly due to its magnificent design), that very caching needs a lot of disk I/O. Oh, and so does MySQL, which Magento happens to be in love with. It all bottles down to this; Magento is a very heavy application, if your server isn't up for it you're simply screwed.


Magento will run like a charm once you spent a week optimizing and tweaking the system.

But most of all I think it's hilarious that an Open Source platform needs a developer in order for it to run properly. Hah. The irony. Seriously.

This is a column from Tim Quax's blog. For more of his posts, check out his site.

React on this article

Enter the code here: