11 min read

 

Magento 1.4 Development Cookbook

Magento 1.4 Development Cookbook

Extend your Magento store to the optimum level by developing modules and widgets

  • Develop Modules and Extensions for Magento 1.4 using PHP with ease
  • Socialize your store by writing custom modules and widgets to drive in more customers
  • Achieve a tremendous performance boost by applying powerful techniques such as YSlow, PageSpeed, and Siege
  • Part of Packt’s Cookbook series: Each recipe is a carefully organized sequence of instructions to complete the task as efficiently as possible
        Read more about this book      

(For more resources on Magento, see here.)

The reader can benefit from the previous article on How to Overcome the Pitfalls of Magento.


Users really respond to speed.—Marissa Mayer, Google vice president of the research section and user experience.

We will explain why this quote is true throughout this article. Her key insight for the crowd at the Web 2.0 Summit is that “slow and steady doesn’t win the race”. Today people want fast and furious. Not convinced? Okay, let’s have a look at some arguments:

  • 500ms lost is to lose 20 percent of traffic for Google (this might be why there are only ten results per page in the research).
  • Increased latency of 100ms costs 1 percent of sales for Amazon.
  • Reducing by 25 percent the weight of a page is to win 25 percent of users in the medium term for Google.
  • Losing 400ms is to have a 5-9 percent drop in addition to Yahoo!, an editorial site.

This is the era of milliseconds and terabytes, so we have to pay a big price if we can’t keep up. This article will describe how to ensure the optimum performance of your Magento store.

Measuring/benchmarking your Magento with Siege, ab, Magento profiler, YSlow, Page Speed, GTmetrix, and WebPagetest

The very first task of any website’s performance optimization is to know its pitfalls. In other words, know why it is taking too much time. Who are the culprits? Fortunately, we have some amicable friends who will guide us through. Let’s list them:

  • ab (ApacheBench): This is bundled with every Apache as a benchmarking utility.
  • Siege: This is an open source stress/regression test and benchmark utility by Joe Dog.
  • Magento profiler: This is a built-in Magento profiler.
  • YSlow: This is a tool from Yahoo! We have been using it for years. This is in fact a firebug add-on.
  • Page Speed: This is yet another firebug add-on from Google to analyze page performance on some common rules.
  • GTmetrix: This is a cool online web application from which you can get both YSlow and Page Speed in the same place. Opera fanboys who don’t like Firefox or Chrome might use it for YSlow and Page Speed here.
  • WebPagetest: This is another online tool for benchmarking as GTmetrix. It also collects and shows screenshots with the reports.

Okay, we are introduced to our new friends. In this recipe, we will work with them and find the pitfalls of our Magento store.

Getting ready

Before starting the work, we have to make sure that every required tool is in place. Let’s check it.

ab: This Apache benchmarking tool is bundled with every Apache installation. If you are on a Linux-based distribution, you can give it a go by issuing the following command in the terminal:

ab -h

Siege: We will use this tool in the same box as our server. So make sure you have it installed. You can see it by typing this command (note that the option is capital V):

siege -V

If it’s installed, you should see the installed version information of Siege. If it’s not, you can install it with the following command in any Debian-based Distro:

sudo apt-get install siege

You can also install it from source. To do so, grab the latest source from here: ftp://ftp.joedog.org/pub/siege/siege-latest.tar.gz, then issue the following steps sequentially:

# go the location where you downloaded siege
tar xvzf siege-latest.tar.gz
# go to the siege folder. You should read it with something like
siege-2.70
./configure
make
make install

If you are on a Windows-based box, you would find it as:

apache/bin/ab.exe

Magento Profile: This is also a built-in tool with Magento.

YSlow: This firebug add-on from Firefox could be installed via the Internet from here: http://developer.yahoo.com/yslow/. Firebug add-on is a dependency for YSlow.

Page Speed: This is also a firebug add-on that can be downloaded and installed from: http://code.google.com/speed/page-speed/download.html.

For using GTmetrix and WebPagetest, we will need an active Internet connection. Make sure you have these.

How to do it…

Using the simple tool ab:

  1. If you are on a Windows environment, go to the apache/bin/ folder and if you are on Unix, fire up your terminal and issue the following command:
    ab -c 10 -n 50 -g mage.tsv http://magento.local.com/
  2. In the previous command, the params denote the following:
    • -c: This is the concurrency number of multiple requests to perform at a time. The default is one request at a time.
    • -n: This requests the number of requests to perform for the benchmarking session. The default is to just perform a single request, which usually leads to non-representative benchmarking results.
    • -g (gnuplot-file): This writes all measured values out as a gnuplot or TSV (tab separate values) file. This file can easily be imported into packages like Gnuplot, IDL, Mathematica, Igor, or even Excel. The labels are on the first line of the file.
    • The preceding command generates some benchmarking report in the terminal and a file named mage.tsv in the current location, as we specified in the command.
    • If we open the mage.tsv file in a spreadsheet editor such as Open Office or MS Excel, it should read as follows:

      Magento 1.4 Development Cookbook

    • You can tweak the ab params and view a full listing of params by typing ab -h in the terminal.

Using Siege:

  1. Let’s lay Siege to it! Siege is an HTTP regression testing and benchmarking utility. It was designed to let web developers measure the performance of their code under duress, to see how it will stand up to load on the Internet. Siege supports basic authentication, cookies, HTTP, and HTTPS protocols. It allows the user to hit a web server with a configurable number of concurrent simulated users. These users place the web server ‘under Siege’.
  2. Let’s create a text file with the URLs that would be tested under Siege. We can pass a single URL in the command line as well. We will use an external text file to use more URLs through a single command. Create a new text file in the terminal’s current location. Let’s assume that we are in the /Desktop/mage_benchmark/ directory. Create a file named mage_urls.txt here and put the following URLs in it:

    http://magento.local.com/
    http://magento.local.com/skin/frontend/default/default/favicon.ico
    http://magento.local.com/js/index.php?c=auto&f=,prototype/
    prototype.js,prototype/validation.js,scriptaculous/builder.
    js,scriptaculous/effects.js,scriptaculous/dragdrop.
    js,scriptaculous/controls.js,scriptaculous/slider.js,varien/
    js.js,varien/form.js,varien/menu.js,mage/translate.js,mage/cookies.js
    http://magento.local.com/skin/frontend/default/default/css/print.css
    http://magento.local.com/skin/frontend/default/default/css/stylesie.css
    http://magento.local.com/skin/frontend/default/default/css/styles.css
    http://magento.local.com/skin/frontend/default/default/images/np_
    cart_thumb.gif
    http://magento.local.com/skin/frontend/default/default/images/np_
    product_main.gif
    http://magento.local.com/skin/frontend/default/default/images/
    np_thumb.gif
    http://magento.local.com/skin/frontend/default/default/images/
    slider_btn_zoom_in.gif
    http://magento.local.com/skin/frontend/default/default/images/
    slider_btn_zoom_out.gif
    http://magento.local.com/skin/frontend/default/default/images/
    spacer.gif
    http://magento.local.com/skin/frontend/default/default/images/
    media/404_callout1.jpg
    http://magento.local.com/electronics/cameras.html
    http://magento.local.com/skin/frontend/default/default/images/
    media/furniture_callout_spot.jpg
    http://magento.local.com/skin/adminhtml/default/default/boxes.css
    http://magento.local.com/skin/adminhtml/default/default/ie7.css
    http://magento.local.com/skin/adminhtml/default/default/reset.css
    http://magento.local.com/skin/adminhtml/default/default/menu.css
    http://magento.local.com/skin/adminhtml/default/default/print.css
    http://magento.local.com/nine-west-women-s-lucero-pump.html

  3. These URLs will vary with yours. Modify it as it fits. You can add more URLs if you want.
  4. Make sure that you are in the /Desktop/mage_benchmark/ directory in your terminal. Now issue the following command:
    siege -c 50 -i -t 1M -d 3 -f mage_urls.txt
  5. This will take a fair amount of time. Be patient. After completion it should return a result something like the following:

    Lifting the server siege.. done.
    Transactions: 603 hits
    Availability: 96.33 %
    Elapsed time: 59.06 secs
    Data transferred: 10.59 MB
    Response time: 1.24 secs
    Transaction rate: 10.21 trans/sec
    Throughput: 0.18 MB/sec
    Concurrency: 12.69
    Successful transactions: 603
    Failed transactions: 23
    Longest transaction: 29.46
    Shortest transaction: 0.00

  6. Repeat the steps 1 and 3 to produce reports with some variations and save them wherever you want.
  7. The option details could be found by typing the following command in the terminal:
    siege -h

Magento profiler:

  1. Magento has a built-in profiler. You can enable it from the backend’s System | Configuration | Advanced | Developer | Debug section.
  2. Now open the index. php file from your Magento root directory. Uncomment line numbers 65 and 71. The lines read as follows:

    line 65: #Varien_Profiler::enable(); // delete #
    line 71: #ini_set(, 1); // delete #

  3. Save this file and reload your Magento frontend in the browser. You should see the profiler data at the bottom of the page, similar to the following screenshot:

    (Move the mouse over the image to enlarge.)

Yslow:

  1. We have already installed the YSlow firebug add-on. Open the Firefox browser and let’s activate it by pressing the F12 button or clicking the firebug icon from the bottom-right corner of Firefox.
  2. Click on the YSlow link in firebug.
  3. Select the Rulesets. In my case I chose YSlow (V2).
  4. Click on the Run Test button.
  5. After a few seconds you will see a report page with the grade details. Here is mine:

  6. You can click on the links and see what it says.

Page Speed:

  1. Fire up your Firefox browser.
  2. Activate the firebug panel by pressing F12.
  3. Click on the Page Speed link.
  4. Click on the Performance button and see the Page Speed Score and details. The output should be something like the following screenshot:

    Magento 1.4 Development Cookbook

Using GTmetrix:

This is an online tool to benchmark a page with a combination of YSlow and Page Speed. Visit http://gtmetrix.com/ and DIY (Do It Yourself).

Using WebPagetest:

This is a similar tool as GTmetrix, which can be accessed from here: http://www.webpagetest.org/.

How it works…

ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many requests per second your Apache installation is capable of serving.

The analysis that Siege leaves you with can tell you a lot about the sustainability of your code and server under duress. Obviously, availability is the most critical factor. Anything less than 100 percent means there’s a user who may not be able to access your site. So, in the above case, there’s some issue to be looked at, given that availability was only 96.33 percent on a sustained 50 concurrent, one minute user Siege.

Concurrency is measured as the time of each transaction (defined as the number of server hits including any possible authentication challenges) divided by the elapsed time. It tells us the average number of simultaneous connections. High concurrency can be a leading indicator that the server is struggling. The longer it takes the server to complete a transaction while it’s still opening sockets to deal with new traffic, the higher the concurrent traffic and the worse the server performance will be.

Yahoo!’s exceptional performance team has identified 34 rules that affect web page performance. YSlow’s web page analysis is based on the 22 of these 34 rules that are testable. We used one of their predefined ruleset. You can modify and create your own as well. When analyzing a web page, YSlow deducts points for each infraction of a rule and then applies a grade to each rule. An overall grade and score for the web page is computed by summing up the values of the score for each rule weighted by the rule’s importance. Note that the rules are weighted for an average page. For various reasons, there may be some rules that are less important for your particular page.

In YSlow 2.0, you can create your own custom rulesets in addition to the following three predefined rulesets:

  • YSlow(V2): This ruleset contains the 22 rules
  • Classic(V1): This ruleset contains the first 13 rules
  • Small Site or Blog: This ruleset contains 14 rules that are applicable to small websites or blogs

Page Speed generates its results based on the state of the page at the time you run the tool. To ensure the most accurate results, you should wait until the page finishes loading before running Page Speed. Otherwise, Page Speed may not be able to fully analyze resources that haven’t finished downloading.

Windows users can use Fiddler as an alternative to Siege. You can download it from http://www.fiddler2.com/fiddler2/, which is developed by Microsoft.

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here