Magento Commerce is very robust system which make me happy with its complexness, but on the other hand this robustness implied bad performance. There are few but reliable tips for Magento Performance Enhancements before you should upgrade your server. You can tune Apache web server, PHP engine configuration and modules, MySQL server configuration, and at last you have to setup Magneto to use this tunes.
- Apache tuning
- PHP tuning
- MySQL tuning
- Magento configuration
1. Apache tuning
There is few tips how to speed up Apache quickly. You need edit your apache.conf or httpd.conf file, or your virtual named host configuration file. First of all you should read official Apache Performance Tuning, or Configuring Apache for Maximum Performance at Linux Gazette. Before you start experimenting with this you want backup your apache.conf or httpd.conf especialy if you dont know what you are doing :-)
Few simple advices noted in articles above - setup apache to worker if you can, disable unused apache modules, use mod_deflate and mod_expires. Documentations: Apache 2.0 mod_deflate, Apache 2.0 mod_expires. After making changes to Apache you 100% sure wanna test the server performance in load. Last tip - if you disabled AllowerOverride Magento .htaccess file will not work, so you have to copy the content to your Apache Virtual named Host configuration.
2. PHP tuning
As above the basic tip is - you should disable all unused PHP modules wasting useful resource. Then you could enable few good modules to enhance performance.
2.1.1. eAccelerator
eAccelerator is must have extension of PHP which can help your Magento performance a lot, because it can do few tricks to speed up Magento Scripts and what is even better - "eAccelerator typically reduces server load and increases the speed of your PHP code by 1-10 times." You can find informations at official site. Example configuration for eAccelerator is:
zend_extension = "/usr/lib/php5/20060613+lfs/eaccelerator.so" eaccelerator.shm_size = "128" eaccelerator.cache_dir = "/var/cache/eaccelerator" eaccelerator.enable = "1" eaccelerator.optimizer = "1" eaccelerator.check_mtime = "1" eaccelerator.debug = "0" eaccelerator.filter = "" eaccelerator.shm_max = "0" eaccelerator.shm_ttl = "0" eaccelerator.shm_prune_period = "0" eaccelerator.shm_only = "0" eaccelerator.compress = "1" eaccelerator.compress_level = "9" eaccelerator.allowed_admin_path = "/var/www/eaccelerator"
More informations on eAccelerator configuration you can find at official site eAccelerator settings.
2.1.2. APC (Alternative PHP Cache)
APC have some code accelerating features like eAccelerator above, but my personal experience said when you have APC and enable eAccelerator above, you can got anoteher 30% speed enhancements. But combination of eAccelerator and APC cache isnt recommended. But APC is supported as cache engine by Magento Commerce. So its very simle to configure Magneto to use APC Cache. Example configuration of local.xml with enabled APC cache:
<config> <global> <cache> <prefix>apc</prefix> <backend>apc</backend> </cache> <install> <date><![CDATA[Thu, 16 Oct 2008 10:14:54 +0000]]></date> </install> ... rest of your local.xml file
But remember to setup different prefixes per Magento installation, otherwise you can get funky results.
2.1.3. Memcache
Its almost the same like APC cache. It cache data into RAM and create very fast cache backend. You can enable it in local.xml like APC above, just change backend to "memcache" (without quotes).
2.2. Configuration enhancements
There is few significant PHP configuration attributes to setup with Magento. If your installation have thousands of products, few store views, and per view product attributes Magento require to setup bigger memory_limit. Another case is when you write your own long running / memory consuming script which need setup longer running time. In some cases i needed more than 384 MB RAM handling data in Magento with custom script. Ideal way of changing this values is in .htaccess file of your Magento installation (backup before change anything). Another way to enhance speed of your scripts is to enable zlib output compression for your scripts. This is definitively wrong idea, when you using mod_deflate in Apache or another alike zlib.
<IfModule mod_php5.c> php_value memory_limit 128M php_flag zlib.output_compression on </IfModule>
; memory limit for PHP memory_limit = 128M ; max script running time max_execution_time = 60 ; enable zlib output compression zlib.output_compression = on
If you cant setup this values in php.ini, then you can try set them in .htaccess (look in .htacces of Magento php4 or php5 section), you can hopefully set them in index.php like that:
ini_set('memory_limit', '128M');
3. MySQL tuning
You can enhance Magento script very well with proper MySQL tunning. This pay double, when you are using Dataflow import / export features for thousands of products etc. Anyway Magento accelerate pretty when you enhance MySQL buffers and caches. Magento use Innodb engine, so you have to enhance innodb settings as well. Before using this tunes be sure backup your my.ini or my.cnf files.
This section is inspired by Performance is Key! - Notes on Magento’s Performance article at Magento Blog.
[mysqld] # innodb tuning innodb_buffer_pool_size = 64M innodb_additional_mem_pool_size = 8M innodb_log_buffer_size = 8M innodb_flush_log_at_trx_commit = 2 # key buffer key_buffer = 96M # query cache size and limit query_cache_size = 128M query_cache_type = 1 query_cache_limit = 16M # max opened tables table_cache = 1024 # sort buffers myisam_sort_buffer_size = 64M # temporary table size tmp_table_size = 128M thread_cache = 16 max_allowed_packet = 64M sort_buffer_size = 4M read_buffer_size = 4M read_rnd_buffer_size = 4M thread_cache_size = 8 max_connections = 128 wait_timeout = 200
4. Magento configuration
Some another tips cover Magento configuration, and they are short:
- let Magento put session data in database instead of files. Part of configuration to do that in local.xml
</resources> <session_save><![CDATA[db]]></session_save> </global>
If you dont have fast connection enough or you want speed up user connections to your Magento you should do few optimalization. You can batch resize product images, or merge and compress CSS files.
5.1. Image size optimalizationYou can simply follow tips for resizing images from this How to Article - Resizing images that are too big or too small for the product pages, en-masse. (Tips from this article need linux compatible OS with some basic programms installed.)
5.2. CSS files compressionOpen your Magento layout definition XML in your view. And copy all CSS files contents to one css file, and include it instead of multiple files. Then use CSS Compressor to compress CSS files by removing unnecessary space and definitions. There is possibility all files in one will not work together, then you will have to experiment with right combination (eg. reset + menu + clears , boxes , your own ... ).
5.3. Javascript files compressionIs used by Magento by default i think, otherwise you should enable it in your Magento administration.
5.4. Gzip / Deflate compressionAs written above, you can use PHP gzip output filter, or Apache module mod_deflate. Be noticed, than you can use just one of them :)
I hope you liked this post, and find it useful.












