Simple Magento performance/load testing with Mage-Perftest

Mage-Perftest is a simple Linux command line tool to test the performance of your Magento store, it can perform a number of clever operations which makes it far more suitable than siege or ab. Its not a replacement for fully fledged simulation tools (like jMeter), but it is simple to set up and run.

You can use it for a number of different things,

  1. PHP TTFB (time to first byte) performance testing
  2. Whole page (including static content & assets) performance testing
  3. Load/stress testing
  4. Concurrency testing
  5. Repeat testing
  6. Site cache priming/crawling

It also has the ability to,

  1. Use sessions during crawling
  2. Supports keepalives
  3. Bypass Varnish cash (to test actual server performance)
  4. Read and parse Magento sitemaps (eg. <loc></loc> format)
  5. Use fixed and random seeds when parsing sitemaps 1. for either completely random tests, or fixed random tests
  6. Simulate traffic over a defined period of time (eg. 1000 unique visitors in a single hour)

What it doesn't do,

  • Take into account CSS/JS render time (this is deliberate, the tool is there to test server performance, not browser)
  • Replicate exact customer behavior (eg. add to cart, login, purchase) - although you could somewhat simulate this by making a sitemap that consists of these URLs

Downloading Mage-Perftest

There are two pre-compiled binaries,

Using Mage-Perftest

First download the binary and make it executable

chmod +x mage-perftest

Then execute it to see the available options

~#  ./mage-perftest

      -a [0-9]+      Abort/discard requests if CPU load percent is above defined limit
      -b             PHP benchmark only (no assets downloaded)
      -c [0-9]+      Concurrency level (# users)
      -d [0-9]+      Duration (minutes) runs test over period by setting delay
      -D             IP Address (force DNS resolution to different IP)
      -f             Ignore font files in full page test (woff|woff2|eot|ttf|otf)
      -g             Enable gzip request headers
      -l [0-9]+      Load average limit - pauses test when load avg. exceeds
                      the defined limit (local testing only). [Default: 30]
      -r [0-9]+      Test repetitions
      -R             Randomise sitemap requests
      -s [URL|FILE]  URL/Path for XML sitemap (use with -r to limit URLs crawled)
      -t [0-9]+      Time delay (seconds) between requests (use with -c and/or -z)*
                      automatically, overrides -t setting (use with -r)
      -u [URL]       URL to test
      -v             Bypass Varnish (if possible)
      -x             Use fixed seed with random requests
      -z             Load test - run requests without waiting between responses*

      * May mean final figures are skewed/meaningless

Examples of use

Single URL, full page test (including static content)

./mage-perftest -u

Single URL, full page test (including static content, without fonts)

./mage-perftest -u -f

Single URL, PHP TTFB only (excluding all content)

./mage-perftest -u -b

Use sitemap for URLS, selects 10 seeded random URL from sitemap, full page test (including static content)

./mage-perftest -u -s -r 10

Use sitemap for URLS, selects 10 seeded random URL from sitemap, PHP TTFB only (excluding all content)

./mage-perftest -u -s -r 10 -b      

Use sitemap for URLS, selects 10 completely random URL from sitemap, full page test (including static content)

./mage-perftest -u -s -r 10 -R

Single URL, PHP TTFB only (excluding all content), 25 concurrent users

./mage-perftest -u -c 25 -b

Use sitemap for URLS, selects 100 completely random URL from sitemap, runs PHP load test (ie. every URL is requested at the same time)

./mage-perftest -u -s -r 100 -b -z -R

Use sitemap for URLS, selects 100 completely random URL from sitemap, runs PHP load test over the course of 10 mins (eg. 1 request every 6 seconds)

./mage-perftest -u -s -r 100 -b -R -d 10 -z

Simulate load of 1000 unique visitors per hour, viewing 8 pages per visitor (1000 * 8 = 8000 requests), ( 1 hour = 60 minutes)

./mage-perftest -u -s -r 8000 -R -d 60 -z

Prime caches, use sitemap for URLS, selects 100 URLs from sitemap, crawls 1 request every 3 seconds

./mage-perftest -u -s -r 100 -b -t 3 -z

Prime caches, use sitemap for URLS, selects all URLs from sitemap, crawls over the course of 1 day

./mage-perftest -u -s -r auto -b -d 1440 -z

Prime caches, use sitemap for URLS, selects all URLs from sitemap, crawls over the course of 1 day and pauses test if load average of 5 is reached

./mage-perftest -u -s -r auto -b -d 1440 -z -l 5

Generate Sitemaps on MageStack

You can also get pretty creative with the content you might need in your crawler/load-tester. Using the following command, it parses the web server access logs on MageStack to find all the accessed URLs, then sorts them by the most frequently accessed (apart from requests from the server itself eg. mage-perf) and outputs it to a file called mageperf_sitemap.xml.

This way, you can performance test the URLs that are most commonly hit (or prime your cache for the common URLs).

apt-get install -y ack-grep
ack-grep "^(?=.*$DOMAIN)(?"'!'"172.16.[0-9.]+).*GET (/[^s]+)" /microcloud/logs/web/nginx-access.log --output='<loc>$1</loc>' | sort | uniq -c | sort -nr > mageperf_$DOMAIN_sitemap.xml
./mage-perftest -u $DOMAIN -s mageperf_$DOMAIN_sitemap.xml -r auto -b -d 1440 -z
  • Magento Search

    How do you deal with

    ./mage-perftest: Operation not permitted

    • sonassi

      Could be anything ... what environment are you running it in?

      • Magento Search

        Tested on Linux Mint 13 and Ubuntu 12.04 and still broken

        • sonassi

          Could you be a bit more vebose than "Still broken". Its a utility we use on a daily basis on a myriad of different platforms without issue...

          • Magento Search

            The error is below, when running it from the shell I got
            $ ./mage-perftest
            ./mage-perftest: Operation not permitted

  • Dan Shields

    What about if the site has HTTP AUTH, can we get around it? What is a site needs a user to be logged to get to the pages you need to test?

  • I was looking for the Magento testing software and I think this will be useful for me. Some tasks I cannot attend with this but up to certain limit this software must help me a lot. Please suggest me another one which can fulfill that lacking of this software.

  • Drew Gillson

    Does mage-perftest support sites where the entire site is forced to https?

    • sonassi

      No reason why not, its just based off curl

  • David Kuei

    Excellent and light-weight tool! Hit a bit of a snag when attempting to prime the cache though. With the "-z" flag set, the tool appears to fire all requests simultaneously even when the "-d [0-9]" and/or "-t [0-9]" options are present. On our store with 31,000+ URLs in the site map, this very quickly brings down our servers due to the sheer volume of concurrent requests. I am trying to use this tool to crawl our entire site (using site map URLs) with maybe 5-10 concurrent crawlers max. Is there a way to do set this up? My only success has been dropping the "-z" option altogether and setting a "-t 1", but this naturally takes extremely long to crawl 31,000+ URLs.

    • sonassi

      Hi David,

      Yes, there was a slight bug in the last release, I fixed it a few weeks ago - but didn't recompile the public release. I've re-compiled it now (version 1.12). Its also wise to use the "-l" argument, so that you can pause the process at a given load load average.

      A recommended config for automated (and limited) crawling would be,

      ./mage-perftest -u -s -r auto -R -d 600 -l 10 -b -z

      This basically says to read all the URLs in the sitemap, and determine the crawl rate automatically to run over a 600 minute period, pausing if the load average hits 10, and to only download PHP content.

  • Matthias Zeis


    thanks for this great script! When I start a test (the staging system is executing mage-perftest testing the future live system) using the sitemap the script hangs for me on random points without returning an error.

    ./mage-perftest -u -s -r 10
    Downloading sitemap
    Spawning 10 Mage crawlers ...

    Testing URL
    Testing URL
    Testing URL
    Testing URL
    Testing URL

    Sometimes the script will finish but most of the times it will hang after a random number of items (2, 5, 9, ...). The script never finishes. Ctrl+C doesn't work, I have to really kill the process. The last URL shown is never the same, I can "curl" all the pages just fine and the server loads for the target system are negligible (<= 0.1 for webserver, 0.00 for database). I don't get any errors in the Magento logs.

    Both the staging system and the live system have host entries as the domain is currently pointing to an old server. The staging system IP is whitelisted on the live system so that the requests do come through. Both servers are situated in the same data center.

    Do you have an idea why the script may be hanging or how I can find the reason? Thanks!

  • how to pass by HTTP Authentication with Mage-Perftest?

  • Guest

    Great script - awesome. Thanks for this.

  • Jacek Myƛlicki

    Does "mage-perftest" supports changing the User Agent?