Performance Optimized Magento 1 Instance
On a recent development project I was involved with I was responsible for the frontend, backend & AWS infrastructure. It gave me the perfect opportunity to build a highly optimized Magento 1 instance.
These are the strategies & techniques I implemented to create a lightning fast magento 1.9.2 website.
AWS & INFRASTRUCTURE
For the project we chose to use a single EC2 instance & a separate RDS database server. It had no need for more than this for it’s catalog size and amount of visitors. I also set up a separate EC2 instance for a staging server and git server.
We used NGINX as our webserver & HHVM for just-in-time (JIT) compilation to improve the performance of PHP executions. HHVM was developed & is maintained by Facebook for speeding up PHP5 applications. For more information on using HHVM checkout this excellent MageTitans talk from Daniel Sloof. You can get the slides here. Two gotchas I remember was that for Magento you need to add the following to
; enable the support for Zend PHP alike sort stability\ hhvm.enable_zend_sorting = 1 ; enable hhvm to call destructors for objects\ hhvm.enable_obj_destruct_call = 1
Additionally we used Redis for Magento’s backend cache & session. Redis stores Magento’s backend cache & sessions in RAM which is a lot faster than reading from the file system, which is where it is normally stored by Magento. Like everyone else we used Collin Mollenhour’s CmCacheBackend_Redis & Cm_RedisSession modules for to configure Magento for this. Cm_RedisSession actually comes out of the box with Magento as a pre installed community module.
Finally we used Varnish caching HTTP reverse proxy to sit infront of our webserver and provide lightning fast web pages. It can be tricky to configure for Magento but thankfully there is a good module for this, Nexcessnet_Turpentine. It can take some time to configure properly for your Magento instance & modules but is definitly worth it.
Images main culprit for slowing down webpages in the frontend so I helped to set up an aggressive image policy for content managers to follow when adding content and used a single sprite for all our icons to reduce http server requests.
With these optimisations our webpages are loading well within 2 seconds, TTFB is at 284ms and DOM content loads at approx 600ms. Not bad for Magento which is known for being a slow application if not configured properly.