Speeding up Magento

Magento is a great piece of software, but people often complain about it's performance. We did some tests to determine how we can improve our configuration to speed up the Magento installations hosted on our servers.

Tests

We took a basic Magento install (v1.1.2) with sample data using this script from the Magento wiki. We then tested the opening time of the front page against different server configurations.  Every configuration was opened 300 times with a GET command and the wall clock time was logged.  The tests were done during the working day thus with considerable load on our webcluster.

We used four different hardware setups:

  1. byte cluster: our shared cluster as available for the customers
  2. web13: a server removed from the cluster (called web13), so same hardware but no interfering traffic
  3. localdisk:the same web13 server but the site was installed in /var/www, thus on a server's local disk
  4. localnfs: web13 but on a local NFS mount (/var/www-local exported and mounted as /var/www to test NFS impact without network latency

Other configuration options were:

  • mod php/cgi - the site was run as mod_php or as a standalone CGI script
  • php opcode caching / nocaching - we tested APC and XCache

Results

Magento tests MOD

Magento tests CGI


Observations

  1. the use of NFS has great impact on performance when using mod php
  2. Magento run with mod_php over NFS is very slow.
  3. opcode caching gives visible performance gains for mod_php installations on a local disk
  4. opcode caching does not help with CGI (which is logical - the code is cached every time the script is run)

Open questions

  1. Why is mod php so slow when served from NFS? It must be some locking issue, but is it due to Magento using flock or is it rather a Apache/mod_php + NFS issue?
  • Vinai

    Why is CGI so much faster?
    Shouldn’t mod_php be faster because it has less overhead? The php/zend engine is running all the time, also the communication through stdin/stdout isn’t required.
    If the two charts where swapped it would make more sense to me. Any explanations?

  • wojtek

    Well, that’s the question. It must have something to do with NFS and/or locking. Please notice that mod_php on ‘localdisk’ IS faster (blue bars). We did the tests, because we realized those insane delays with mod_php.

  • Patrick

    Hi,
    had the same problem. Which NFS Version did u use?
    In my case it was a problem of locking, lstat and nfs. I use NFS Version 2 and now everything works fine.

    Greetz

  • wojtek

    We are using nfsversion=3
    mount options are: rw,bg,nosuid,intr,hard,rsize=32768,wsize=32768,nfsvers=3.
    I was going to try v4, but will have a look at v2 as well.
    Thanks for the tip!!

    BTW placing magento/var on a ramdisk can also be a solution. Haven’t tried yet but I have it on a todo list.

  • Jonathan

    I’m assuming you didn’t do this testing manually? Could you provide the script used to do this testing?

  • wojtek

    Hi Jonathan,
    My script did something like this:
    $ntries = 100
    for i in `seq $ntries`; do
    /usr/bin/time -p -o $outfile –append GET $URL>/dev/null;
    done
    I then pasted the results into a spreadsheet to get the graphs.
    This is not a perfect way of testing as it only fetches the index file without scripts/css/images.

    I will soon update this post with new test results GETting all the content.
    greetz

  • Jakub

    Please tell me what is the difference between mod_php and cgi.
    How can I set this mod? Or does it have to set the server administrator? How can I find out if we are using mod_php or cgi? Can I tell from php info?

    We have a normal server with magento on local hard drive. If I understand it good, mod_php with xcache is fastest, right?

  • http://www.openstream.ch Nick Weisser

    Very interesting tests! I’m currently experimenting with a Magento optimized AMI on Amazon’s EC2.

    Have you considered MySQL query caching, too?

  • http://pictureitlikethis.com Nate

    We currently run Magento with NFS and mod_php. In order to get it to perform, we had to move the /var/ directory to a location on the local disk and not on nfs. It’s still not fast enough for me, but I’m curious to see your tests with this scenario.

  • pratham

    Hi ,How can i enable cgi in apache and run the application under the cgi configuration .

  • http://www.josephlancaster.com Joseph Lancaster

    I am trying to get Magento to speed up even on a dedicated server and it is still slow. I am thinking of switching if I can get it to work faster. Not just the admin section but any of it. The site only gets about 30 unique visitors a day. It is on a dedicated server over at godaddy. Any clues?