Magento Performance Optimization
Magento Performance Optimization
30 Apr 2013
What is Magento? Comparison with other eCommerce platform What people think about Magento?
Performance optimization
Tools and utilities
What is Magento?
Open source rich eCommerce platform developed on PHP Zend framework First stable release in 2008 by Varian now known as Magento Comes in three variant Community edition Magento Go Magento hosted solution Enterprise edition Acquired by eBay in 2011 More than 4 million downloads after first stable release
Flexible Upgradable Scalable
Extendable
Modular
Truth behind it
Magento is resource intensive
Magento is based on EAV database model means to retrieve a single information we need to go through many queries and tables.
Giant XML trees in memory and then "querying" those same trees for information. This takes both memory (storing the trees) and CPU (parsing the trees). Some of these (especially the layout tree) are huge. Also, unless caching is on, these tree are built up from files on disk and on each request. Magento uses its configuration system to allow you to override classes. This is a powerful feature, but it means anytime a model, helper, or controller is instantiated, extra PHP instructions need to run to determine if an original class file or an override class files is needed. This adds up.
Solution
Understand critical parameters for making optimization strategy
Identify the server resources available. Type of hosting server, Web server, RAM, CPU etc Product catalog Number of categories, products etc Number of expected simultaneous users
Optimization methods are available/ applicable depending upon the nature of web server and Magento store
Solutions
.htaccess configuration
MySQL configuration
When enabled, it store products and category information in one table for each.
It is recommended to use flat category navigation in all Magento website Flat product navigation will be helpful when you have more than 1000 SKUs
Merge JS and CSS files. Using this option, we address issue of multiple HTTP requests. When enabled, it merge all JS and CSS files and reduce HTTP requests. Important: While enabling this feature you may face issue of Javascript confliction when multiple JS frameworks used.
Compile Magento. Using this option, we address issue of loading large framework in background by running through multiple directory structure. When enabled, it merge various PHP files into one large file and store them on location includes/src. Therefore instead of reading multiple directories on entry point it will look at only location. It improves Magento performance by 25-40%. Important: Once enabled, you cant upgrade Magento store and modify any core settings including core files. If you want to do then decompile Magento first and modify it.
Disable Magento logs Using this option, we address issues consuming more CPU cycle and diskspace. When enabled, Magento stops writing logs for any error or exception. If any time needed for debugging then we can enable it again.
.HTACCESS tweaks
Enable gzip compression
<IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4\.0[678] no-gzip SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dontvary </IfModule>
<IfModule mod_expires.c> ExpiresActive On ExpiresDefault access plus 1 month ExpiresByType image/x-icon access plus 1 month ExpiresByType text/html access plus 1 month ExpiresByType image/plain access plus 1 month ExpiresByType image/css access plus 1 month ExpiresByType application/x-javascript access plus 1 month ExpiresByType application/x-shockwave-flash access plus 1 month </IfModule>
.HTACCESS tweaks
Enable Apache KeepAlive and disable Etag
FileEtag None KeepAlive On MaxKeepAliveRequests 100 KeepAliveTimeOut 5
MySQL configuration
Increase InnoDB buffer pool - Magento uses InnoDB storage engine which, uses memory pools to cache tables data, indexes to reduce disk I/O. Less disk I/O means faster access to data, indexes etc. The key is to assign as much memory as possible for in-memory cache.
innodb_buffer_pool_size = 512M
Multithreading - Innodb can use multiple cores of server processors to give concurrent connection. The key is to use this ability to boost concurrent connections. Magento recommends to calculate innodb_thread_concurrency value by equation
innodb_thread_concurrency = 2 x [# of CPUs] + 2
MySQL configuration
Enable query cache - MySQL can cache results for queries and return it from cache, when identical query is done. For example queries running for home page will be almost identical for another home page view. Enabling the cache can save a lot of rework on MySQL end.
query_cache_size = 32M
Fooman Speedster For combining, compressing and caching JS and CSS files.
URL - http://www.magentocommerce.com/magentoconnect/FOOMAN/extension/457/fooman-speedster
Page cache with full page cache which is by default not available in community edition of Magento.
URL - http://www.magentocommerce.com/magentoconnect/pagecache-powered-by-varnish.html
Q&A