Mid September 2010
July 16th, 2009 • Posted in Magento
Tweet
I still read a huge number of comments on both the Magento forums and via Twitter indicating that people think Magento is slow or a resource hog or performs poorly. In many cases this is a misconception. I think most people familiar with Magento would agree that it is a bit of a beast – it’s developed for maximum flexibility and extensibility meaning there are a lot of files, lots of templates and in places the HTML & CSS is not entirely ideal. I think the argument that Magento is over-engineered in places does have some value.
I have found it difficult to get a good performance level out of a simple local installation on OS X 10.5.x – not helped by a multitude of issues getting PHP setup and running with the required modules for Magento.
However… I do have a remote Magento server running with a UK hosting company which is lightning fast with very little modification whatsoever. The key to it seems to be three-fold:
Magento is a pretty processor-intensive and memory-intensive application so having a server that can handle this is a good start. The specification for my development server is:
On the face of it this seems like a fairly meaty server but it’s relatively inexpensive – it costs under £100 per month from Melbourne Hosting in Manchester who I would highly recommend.
I am by no means a Linux expert and don’t pretend to be but found that by following some pretty straightforward advice from Varien I was able to significantly improve the database element of the setup. There is already plenty of detail on this subject – this article is a good place to start – particularly the my.cnf modifications.
In addition, the recommendations in that article to install a PHP opcode cache and use a memory-based file system for /var/cache are recommendations you should seriously consider.
Out of the box, the Magento front-end isn’t particularly quick – even with the Blank interface as a starting point (you are creating your own interface based on the Blank interface, right?). The main culprit here is Prototype & Scriptaculous – they are bulky frameworks and are included uncompressed. Magento funnels these files through a PHP conduit to compress them in to a single file but in my opinion that still isn’t ideal – you are just giving your server more work to do.
Web servers like Apache are brilliant at serving static files – so let them serve static files.
On most sites I build using Magento, I choose not to use the included javascript framework files but instead to roll my own. I have found the best way to do this is to create a packed version of the latest Prototype file and then a minified version of the Scriptaculous files and the various Magento specific javascript files. (For some reason when I packed the Scriptaculous and Magento/Varien-specific files I had some issues).
The result is my typical javascript usage is something like this:
<script type="text/javascript" language="javascript" src="/skin/frontend/[theme]/default/js/framework.pack.js"></script>
<script type="text/javascript" language="javascript" src="/skin/frontend/[theme]/default/js/application.min.js"></script>
Even though I have two javascript calls rather than one in the standard Magento configuration, the improvements in speed are huge – largely because Apache is doing what it does best – serving a packed, gzipped static file.
I will write up point 3 in more detail at some point when I have more time as it’s quite an involved process to determine which files you need and which you don’t and of course it varies depending on the site configuration, multi-language requirements etc. however the key points to take away for the amateur performance tweaker are:
There is no silver bullet for perfect performance – but the advice above will certainly point you in the right direction.
Joe Greenwood
March 7, 2010 at 5:41 pm
Hi Simon — wondering if you could expand on #3 above .. it appears my Magento install calls the .js in /app/code/core/Mage/Page/Block/Html/Head.php … can you explain how to make edits here to get the customized .js links in place? Also, how do you pack and minify these files? Thank you for this post, it is what I was thinking might help speed up my site! (esp. #3)
Simon Young
March 8, 2010 at 10:26 am
In Magento 1.4, there are some pretty significant changes to the way in which JavaScript files are minified which address most, if not all, of the concerns on JS performance. I’d recommend using the standard approach for 1.4 onwards.