e-Zest members share technology ideas to foster digital transformation.

Performance tuning for Magento Community Edition

Written by Vidya Palaskar | Mar 14, 2013 12:20:42 PM

Magento is a very popular, robust and enterprise grade open source e-commerce framework built in PHP. On one side these are the positive aspects of this application but on the other side this mammoth is reported to have slow performance. Page load time is high which adversely affects customers and SEO efforts. Below are some useful steps that will improve the performance of Magento Community Edition.

  1. Enable cache into Magento admin section
    Go to Magento admin section -> System -> Cache Management, and enable all the Cache Types.
  2. Enable Compilation
    Go to Magento admin section -> Tools -> Compilation -> Click on “Enable” button.
  3. Enable Flat Data
    Go to System -> Configuration -> CATALOG -> Catalog -> Set “Use Flat Catalog Category” = “yes”
    And “Use Flat Catalog Product” = “Yes”
  4. Disable modules that you don’t use:
    System -> Configuration -> Advanced -> Advanced.
  5. Disable the Magento log
    System -> Configuration -> Advanced -> Developer -> Log Settings (default is disabled).
  6. Combine JavaScript and Combine CSS files
    System ->Configuration ->Advanced ->Developer -> ‘JavaScript settings’ and ‘CSS Settings’. Here you can merge all JavaScript files into one file. And all CSS files into one single file
  7. Keep Alive settings in Apache
    KeepAlive On
    KeepAliveTimeout  Default 5 seconds
    MaxKeepAliveRequests  Default 100
    

    Apache KeepAlive settings provide long-lived HTTP sessions which allow multiple requests to be sent over the same TCP connection. In some cases this has been shown to result in an almost 50% speedup in latency times for HTML documents with many images.

  8. ExpiresActive On setting (for text/css, image/gif, image/jpg, image/png) in .htaccess file

    This module controls the setting of the Expires HTTP header and the max-age directive of the Cache-Control HTTP header in server responses. The expiration date can set to be relative to either the time the source file was last modified, or to the time of the client access.

    These HTTP headers are an instruction to the client about the document's validity and persistence. If cached, the document may be fetched from the cache rather than from the source until this time has passed. After that, the cache copy is considered "expired" and invalid, and a new copy must be obtained from the source

    For this you can do below settings in your .htaccess file.

    ExpiresActive On
    ExpiresByType text/css "access plus 2 day"
    ExpiresByType image/gif "access plus 2 day"
    ExpiresByType image/jpg "access plus 2 day"
    ExpiresByType image/png "access plus 2 day"
    

    Here you can set max age to day, month or year.

  9. Use APC – Alternative PHP Cache (opcode cache for PHP)

    APC engine cache the compiled bytecode of PHP scripts to avoid the overhead of parsing and compiling source code on each request. And it is improving performance around 50%.
    Steps to install APC on Linux:

    1. Install php-pecl-apc package using below command through putty -
      yum install php-pecl-apc
    2. After installation of APC you will find apc.ini file at
      ls /etc/php.d/apc.ini
    3. Edit apc.ini file and do the below settings -
      apc.enabled=1
      apc.shm_size=512M
      apc.num_files_hint=10000
      apc.user_entries_hint=10000
      apc.max_file_size=5M
      apc.stat=0
      apc.optimization=0
      apc.shm_segments=1
      apc.enable_cli=1
      apc.cache_by_default=1
      apc.include_once_override=1
    4. Activate APC support in Magento configuration:

      Go to your Magento installation
      Open local.xml file /app/etc/local.xml and add below lines in between <global>...</global> tags.

      <cache>
        <backend>apc</backend>
        <slow_backend>File</slow_backend> 
      <prefix>Myproject_</prefix>
      </cache>
      
    5. Now clear the Magento older cache and refresh your site.
    6. To check whether cache is stored using APC, go to var/cache directory you will find mage-- directories , open any one and you can see the cache files having prefix provided by you (i.e. Myproject_</prefix>).</li> </ol> </li> <li>Modify my.cnf or my.ini file as below (The values for parameters should be according to your RAM size) - <pre> [mysqld] a. key_buffer_size = 512M (It should be 30% of Memory.) b. max_allowed_packet = 64M c. table_open_cache = 512 d. sort_buffer_size = 4M e. read_buffer_size = 4M f. read_rnd_buffer_size = 2M g. myisam_sort_buffer_size = 64M h. tmp_table_size = 128M i. query_cache_size = 96M j. query_cache_type = 1M k. thread_cache_size = 8 l. max_connections = 400 m. wait_timeout = 300 n. query_cache_limit: 2MB