Best ways to speed up your Magento e-commerce webstore

- Magento tips & tricks

There are several reasons why speed is very important for websites. First of all visitors. They can become dissatisfied with slow performance and loose trust to your website. The second reason is web search ranking. Google is using site speed as a part of the whole process. These are obvious things and we are not going to talk about them. Instead we will talk about all possible tips and tricks to speed up your Magento performance.

magento speed

Don’t forget to check our new guide: 

Magento Performance Ultimate Guide

Working with Hosting Environment

  1. Firsе of all you should find reliable and dedicated server.

  2. The website should be hosted in the same country with your customers.

  3. Try to remove all unnecessary files from your server.

  4. Remember! You should install only necessary Apache modules.

  5. In MySQL Admin repair & optimize all tables

  6. Use a PHP accelerator. It can be ZendOptimizer+, APC, Xcache or something similar. APC – (http://pecl.php.net/package/APC). Apc should cache more data, so increased the APC.shm.size to 128. The same about Xcache (http://xcache.lighttpd.net/)

  7. Use Apache mod_expires and set time for file caching. This is the example:

  8. In htaccess, don’t forget to turn on Gzip Compression.

  9. Also, to improve your Magento store performance you use mod_deflate or zlib.output_compression to compress output.

  10. Another important detail is parallel transfer of static content. You should use a Content Delivery Network (CDN) for it. Several extension can be useful here, for example One Pica Image CDN.

  11. Don’t forget that too many different external sources use extra time and create an extra dependency on other 3rd party servers, so the performance of your magento e-commerce store could be reduced.

  12. Do everything to minimize redirects.

  13. Errors are one of the main reasons of browser slowdown so make your output W3C compliant.

  14. Turn on Apache KeepAlives. This will funnel multiple HTTP requests through a single TCP connection.

  15. Take care of Swap Apache (for NginX or Litespeed).

  16. If it is possible you can turn off web server logging, if not – reduces disk writes.

  17. Instead of your OS’s package manager you can сompile MySQL from source. This will also speeds up your Magento e-commerce website

  18. Another useful tip is to modify the configuration for your MySQL server. As a result, you should get better advantage of your server’s RAM.

  19. You can also set ‘php_value memory_limit 128M’ in php configuration or add it to .htaccess file. This will provide you with the information about memory usage.

  20. Remember, that memory-based filesystem is the best option for dynamic data. If you store it (var/cache, var/session) on tmpfs or RAMdisk, the disk I/O is decreased.

  21. Furthermore, you can change realpath_cache_size in php.ini to get better performance from your e-commerce store.

  22. If you are hardcore user you can work with memcache.

  23. You can also disable the PHP open_basedir directive, if you know what are you doing, of course.

  24. Don’t forget to upgrade to the latest Magento version.

  25. And here is the trick for .htaccess files: eliminate their directory structure scans.

  26. Moreover, try to keep up recommended innodb_buffer_pool_size: for combined web and db server with 6 GB RAM – 2-3 GB; for dedicated database server with 6GB RAM – 5 GB; for dedicated database server with 12 GB RAM – 10 GB.

  27. Use 64MB for query_cache_size and 2MB for query_cache_limit

  28. innodb_thread_concurrency – 2 * [numberofCPUs] + 2

  29. Don’t forget to use separate backend server for handling admin users, processing backend activity (cron), pre generating full page caching and handling media queries.

  30. Use multiple frontend servers (web nodes) to handle browsing and checkout.

  31. Use Varnish reverse proxy caching. It will significantly change your Magento store performance.

  32. For popular (heavily crawled by search engines) sites it is recommended to tweak robots.txt. This will save some resources.

  33. Useful extensions for better Magento store performance:

    • http://www.artio.net/magento-extensions/m-turbo-accelerator

    • http://www.aitoc.com/en/magento_booster.html

    • http://www.tinybrick.com/magento-modules/performance.html/

Template

  1. Mostly all of your (template) images should be at least below 10kb. To achieve such a result you can crop the white space; use PNG8 or GIF instead of Jpegs; scale images; use image compression and CSS Sprites.

  2. And don’t forget to specify Image dimensions.

  3. You can also remove unused code and minimize the use of Javascript.

  4. It is also recommended to work with lightweight template to create your own template.

  5. Remember, that you can block cache and HTML output for extensions and apply Javascript Lazy Loader for prototype.

Magento configuration

  1. Uninstall all unnecessary extensions.

  2. And disable useless modules. To do this go to System -> Configuration -> Advanced -> Advanced.

  3. Go to System -> Cache Management and enable all Magento Caches.

  4. Use Google Analytics or other offsite stats tracker instead of onsite one.

  5. Go to System ->Configuration ->Advanced ->Developer -> “Javascript settings” / “CSS Settings” and merge Javascript and CSS files or use the appropriate extension.

  6. There are several Magento performance extensions which can speed up your webstore

  7. If you have very large catalogs on your site you can enable the Magento Flat Catalog, It will help you to gain some extra performance.

  8. Remember! Layered navigation consumes a lot of resources, so use it wisely.

  9. Go to System > Tools > Compilation and enable Magento’s Compilation feature.

  10. It is strongly recommended to use “file system” for most installations if your site runs on one server. If it runs on multiple servers, you should choose “database”. So use the correct session storage.

  11. For product overview page reduce the number of products.

  12. Go to Catalog -> Attributes -> Manage Attributes -> Frontend Properties and set to “Yes” attribute frontend properties that you’re going to use. All other – to “No”.

  13. Go to System -> Configuration -> Advanced -> Developer -> Log Settings and turn off the Magento log.

  14. For Enterprise you can disable Enterprise_CatalogEvent (Admin -> System -> Configuration -> Catalog -> Catalog Events); turn off settings for “Enable Catalog Event Widget” and “Enable Catalog Events Functionality “; turn on Solr search and Full Page Caching.

  15. For speed tests, analyses and monitoring use Magento Speed Test; websiteoptimization.com; Google Page Speed Firefox extension and Yahoo Yslow; Analytics; Mon.itor.us or Pingdom.

A) Work with the server environment

  1. Find a dedicated server: get the whole server power; become flexible in terms of new versions for database, webserver, php; don’t work with customers which run “bad” scripts and slow down other shops (or you can use google to block the ip  which affects search ranking); don’t use the same ip.

  2. Split database and webserver because they have different requirements: fast hard disks and much memory for database serverA webserver needs; less memory and more CPU for webserver.

  3. Work with Multi Server Environment – a separate Backend Server. Handle all admin users and run all cronjobs there.

  4. Don’t forget about updates: use latest MySQL Version.

  5. Optimize the MySQL configuration. It can improve the performance of your store up to 65%.

Configurations for innodb_buffer_pool_size parameter

MySQL settings

  • innodb_flush_log_at_trx_commit = 2

  • innodb_thread_concurrency = 2 * [numberofCPUs] + 2

  • thread_cache_size = 32

  • thread_concurrency = [number of CPUs] * 3

  • table_cache = 1024

  • query_cache_limit = 2M

  • query_cache_size = 64M

  • tmp_table_size = 256M

  • key_buffer = 32M

  • join_buffer_size = 8M

  • innodb_autoextend_increment=512

  • max_heap_table_size = 256M

  • max_allowed_packet = 16M

  • read_rnd_buffer_size = 16M

  • read_buffer_size = 2M

  • myisam_sort_buffer_size = 128M

  • myisam_max_extra_sort_file_size = 10G

  • myisam_max_sort_file_size = 10G

  • myisam_repair_threads = 1

  • bulk_insert_buffer_size = 64M

  1. Use the MySQLTuner, which is a Perl script. With the MySQLTuner you can quickly review a MySQL installation and make all necessary adjustments to increase the performance of Magento web-store.

  2. Mount disk with noatime option. It will also help you to get more performance from the site.

  3. Use memory-based filesystem for dynamic data

You can use these key parameter for your php.ini:

  • realpath_cache_size = 32k

  • realpath_cache_ttl = 7200

  • max_execution_time = 90

  • max_input_time = 90

  • memory_limit = 256M

  • default_socket_timeout = 90

  • pdo_mysql.cache_size = 2000

  • output_buffering = 4096

  1. Use a byte code cache like APC, it will prevent file system from slowing down in case of rising amount of requests.

php.ini configuration

  • apc.enabled = 1

  • apc.optimization  = 0

  • apc.shm_segments = 1

  • apc.shm_size = 768M

  • apc.ttl = 48000

  • apc.user_ttl  = 48000

  • apc.num_files_hint = 8096

  • apc.user_entries_hint = 8096

  • apc.mmap_file_mask = /tmp/apc.XXXXXX

  • apc.enable_cli = 1

  • apc.cache_by_default  = 1

  • apc.max_file_size = 10M

  • apc.include_once_override = 0

  1. Swap Apache webservers with NGINX webservers.

  2. Turn on Gzip Compression in NGINX configuration.

  3. Set expiration header for static files and don’t forget to enable mod_expire.

nginx vhost configuration

[code language=”php”]

location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|eot|mp4|ogg|ogv|webm)$ {

expires max;

access_log off;

}

[/code]

  1. Use just necessary Apache modules and Eliminating .htaccess directory structure scans.

  2. Uninstall xdebug or zend debugger on production, because they can slow down the overall performance up to 10-15%.

B) Magento configuration

  1. Remember, that for Single Server Environment you can use APC as a magento cache storage (app/etc/local.xml)

For Multi Server Environment – memcached

  1. Store sessions in memory

  2. Disable extensions that you don’t need in app/etc/modules/*.xml and uninstall all the unnecessary.

  3. Turn on all caches: System -> Cache Management

  4. Go to System -> Configuration -> Catalog -> Catalog -> Frontendand activate “Use Flat Catalog Category” and “Use Flat Catalog Product” options.

  5. You can also reduce the number of http requests. For this, you should turn on “Merge JavaScript Files” and “Merge CSS Files” options in JavaScript Settings.

  6. To gain extra performance from your e-commerce store you can use a Full Page Cache.

  7. Remember, that ioncube encrypted extensions slow down your online store and it’s impossible to use debuggers like xdebug or zend to step into the code.

  8. Go to System > Configuration > Advanced > System -> Log Cleaning and activate cron and log cleaning

C) Magento Templating/Frontend

  1. Remove all the unnecessary blocks from layout xml. To remove poll from the right column you should:

  2. Don’t forget that for loading images on demand you can use Lazy Image Loader.

Modules for caching and extra performance

Lesti::Fpc

Lesti::Fpc is very powerful and free solution. Being internal full page cache for Magento stores Lesti::Fpc needs no varnish, no external software and no works with events. It is an internal cache which replaces dynamic blocks before sending response to customer.

Main features

  • cms_page_index, cms_index_index, catalog_product_view and catalog_category_view can be cached by default with Lesti::Fpc. You can also add your own layout-handles in the configurations.

  • global_messages, messages, right.reports.product.viewed and global_notices are default dynamic blocks.

  • top.links, catalog.compare.sidebar, cart_sidebar, wishlist_sidebar and welcome (in Magento 1.8) are default Lazy blocks.

  • to refresh the lazy blocks you can use such actions as: catalog_product_compare_clear; catalog_product_compare_add;  catalog_product_compare_remove; checkout_cart_delete; checkout_cart_add; checkout_cart_updatePost; wishlist_index_remove; wishlist_index_add; wishlist_index_configure, wishlist_index_update; wishlist_index_allcart; .

  • id, page_id, category, p, dir, limit, order, mode are default uri-params, which can be handled in Lesti::Fpc. It is also possible to add some other params in the configurations.

  • And limit_page, sort_direction, sort_order, display_mode are the session-parmas of the extension.

  • multicurrency, multistore, different Prices for different customergroups and mobilethemes  are possible in Lesti::Fpc.

  • default lifetime for every cached page is 24 hours, but you can change it in app/etc/fpc.xml.

  • apc, redis, memcached and other cachebackend can be set in app/etc/fpc.xml and app/etc/local.xml. To work with redis you need Cm_Cache_Backend_Redis.

  • To work with cach go to System => Cache Management. To find configurations visit System => Configuration => Advanced => System => Lesti FPC.

  • Lesti_Fpc works with Magento CE 1.5, 1.6, 1.6.1, 1.6.2.0, 1.7, 1.8.

  • Extension rewrites the block core/messages

For more information visit this page.

Fooman Speedster

Fooman Speedster is another poцerful extension, which you can get for free. The core controls are implemented by advanced self testing framework. Perform all self tests and make all the adjustments and configuration to enable the extension. And don’t forget that self tests doesn’t include testing for existing JS, so you should do this separately before installation.

Key features

  • Fooman Speedster combines multiple Javascript files into a single one. The same works for CSS files. The combined Javascript and CSS files get far future expire headers. This helps to reduce page load time

  • For empty and primed caches, extenыion also reduces the total size of files to be loaded and the number of HTTP requests.

  • Fooman Speedster is fully automated

  • It doesn’t need gzip support on the server to compress files

  • Fooman Speedster can be used for multi store

  • The extension uses the Minify library by Steve Clay, which was released under a BSD license.

More information.

Nitrogento

Another powerful tool for Magento compatible with 1.7+. Nitrogento is a toolbox for optimization, which can be configured and deployed from the back office. It helps to reduce page load time and leads to faster reindex. Nitrogento costs €299.00.

Key features

  • Nitrogento adds new blocks to Magento’s cache mechanism. It can also learn blocks you are using automaticly and allows custom blocks.

  • Nitrogento also supports Full Page Cache.

  • It adds Expire headers, Etags and Gzip compression to the backoffice.

  • There is the Reindexation booster in Nitrogento. It can make reindexation performances up to 20 times faster.

For more information visit the official site of Nitrogento.

Some other important extensions, modules and speed up solutions