Load testing your moodle install with JMeter scripts
In the previous post i introduced 2 solutions that will allow you to load test your website / application. The 2 applications are HP Load Runner and JMeter. You can read a quick intro about load testing, both software and my take / preferences.
As promised, I am dedicating a second post to show example of how to test your moodle install using JMeter. The example will show how to emulate the following steps :
- user navigates to site
- user logins + testing if login successful
- user views some content like FLV video
There are many reason i chose moodle/Jmeter for this post :
- I had to choose something
- It will be less useful if i show example of load testing on proprietary website that i did – so better show example on how to test some open source package.
- Referring to point 2 – from the open source solutions that are interesting to load test, you have wordpress/drupal/moodle. Moodle seemed to me more interesting cuz it is a content heavy system where most data resides behind a login for the students and it needs usually higher resources, so load testing moodle installs is important with all the students logging at the same time to view courses and take quizzes
- I was doing load test for moodle install and the contributions under http://cvs.moodle.org/contrib/tools/jmeter/ has only 1 entry . It was bit tricky to find example and resources on the topic ! so i am publishing this to hopefully help the lost souls working with moodle/jmeter
- Because I am optimizing my blog for moodle / JMeter and i am so far happy with the reach of keywords that say JMeter, moodle, load testing :). Yes, that is how i digg jobs as freelancer :)
Enough with the blabbery blabbering , The fast quick solution is that you download THIS SAMPLE SCRIPT FOR MOODLE , and open it with JMeter – just browse around the items, and change the values of text boxes till it works ( this is how i personally like to mess around instead of reading long boring tutorials – I hope the big font made it easier for you to spot :D )
If you wanna do it a-la-more manual way to get a grasp of it , here is how :
You should obviously install JMeter from here .
Browse to your newly downloaded folder, go to bin and if you are still under windows double click jmeter.bat
If you are on some linux distro or osX you have a jmeter.sh file . Open it in your favorite editor – there is one line that says :
java $JVM_ARGS -Dapple.laf.useScreenMenuBar=true -jar `dirname $0`/Applications/jakarta-jmeter-2.3.4/bin/ApacheJMeter.jar “$@”
All you need to do is make sure to point the dirname to your correct download location
After that you launch it in your terminal and JMeter java GUI will come to show.
Right click on Test Plan , click add –> Thread group
Thread group elements are the beginning points of any test plan. All controllers and samplers must be under a thread group.
Now you will move to second screen – where you get to specify the following elements :
- Thread name : descriptive field
- Comments : descriptive field
- Action taken after sampler error
- Stop thread
- Stop test
- Stop test now
- Number of threads users u are emulating ( how many users visiting ur site u want )
- Ramp up period ( the time JMeter takes to generate all the threads – if you have 10 threads and ramp up period of 100 secs – JMeter will start a thread each 100/10 = 10 secs. after 100 secs, all your threads will be booted )
- Loop Count : How many times you want to repeat your test – you have the forever option or a number u can enter
Right click on your thread group and click add –> listener –> HTTP Request Defaults. You can define your port number ( 80 ) – timeout durations and such ( for our moodle test , you can leave the settings as default )
Now after configuring your ConfigElement you need to specify a sampler , right click on load test –> Add –> Sample –> HTTP Request
You will get the following screen :
As you can see it is important to specify the following :
- Path : the url of the page
- Uncheck redirect automatically and check follow redirects ( trick alert )
- Send your parameters with the request like username and password
You might have guessed it , the next step is testing if login worked or failed and then access some content – to do so , you need to use a “Response Assertion” . Right click on login and do the following :
You will get the screen where you put the criteria that tells JMeter if your login was successful or not :
As you noticed, the pattern to test used here is “contains” + “Not” + “You are not logged in” – this is different from one website to another – but you can use it on moodle.
Now , you can add a similar http request that exists after the login – this is highly dependent on the content you have .
Things are somehow ready, now time to add those juicy graphics that JMeter can generate – Simply , right click on the item u want to view its graph ( a special request or the full thread ) and add the following
For the ones who made it to the bottom of this post , i hope this was helpful and good luck with your load tests :)
I guess next post should be about how to fake those results :D