Note: this blog post is part of the Moodle Oktobertest series
- Apache JMeter book by Emily H. Halili
- Apache JMeter documentation and best practices
Before you start this tutorial, you need to download the following:
It is possible that you’ll get an error if you’re trying to run this in Moodle 2.2+. All you need to do is open the ‘index.php’ file (for the ‘loadtesting’ report) and search-replace all instances of the entire word ‘mod’ (no quotes) and replace it with ‘module’. This should solve your problem.
Step 1: Generate your JMeter script
- Settings > Site Administration > Reports > JMeter loadtesting
- Use the drop-down box to select the correct category
- Click ‘Select category’
__Note:__you must be logged in as an administrator to do this
- This can be a bit confusing. You should see each activity type as a different test. For example, if 10 is entered in this box, then a total of 40 virtual users would be running simultaneously (10 for chat, 10 for forum, 10 for glossary and 10 for quiz)
- I always tick this, to put as much strain on the disk as possible, and to mimic real world usage as closely as possible 3 & 4. I like to pick and choose activities. The main reason being that students cannot post to the News forums, and also to ensure that the activities I picked are not restricted by time, or by condition (conditional activities), or even available only to particular groupings.
- I usually tick this option, again to mimic real work usage as closely as possible
- I like to set this to 10, for no particular good reason, I tend to like even numbers
- Once you click the button, your Moodle server will generate a zip file, so make sure you have a zipping program installed. It will look like nothing is happening, simply go and check your download folder to see if jmeter.zip is there.
Step 2: Start JMeter
- To open JMeter, you have to visit the JMeter folder you downloaded
- JMeter > bin > ApacheJMeter.jar
- Double-click on the ApacheJMeter.jar file
Step 3: Open the newly generated script
- Select the correct file
- Click ‘Open’
Step 4: You can now run your script
- Click the play button
- Look for the numbers at the top right of the window reach the maximum set, and then go back to zero
- Once your script has looped through the amount defined in your settings, the load test is over
Note: Check out this blog post to find out what tools you could use to monitor your server while load testing
Step 5: Check the results
- There are several types of reports you can take a look at (see rectangle in picture above).
- Not all reports are super user-friendly and might not make a great deal of sense. Further reading on the matter:
- JMeter report plugin (very useful to visualize data)
- JMeter user manual (reports are called ‘listeners’ in JMeter)
- JMeter log analysis See below for more report examples
Tip 1: Create a ‘Load testing’ category with courses dedicated to load-testing
- If you are planning on enrolling lots of test users to your Moodle courses, you should know that it could have an impact on the performance of the courses involved.
- If you create a specific category with dedicated courses, you do not run this risk as the courses are only used once in a while.
- You should also reset your courses once in a while
Tip 2: Generate your script with lots of users
The first time you generate a script chances are you’ll have no idea how many users your installation can cope with.
Part of load testing is to find out the limits of your server. Consider this scenario:
- Generate a script for 50 users
- Get the script to generate users and enroll them in the course(s)
- Run the test
- If that test runs smoothly, you’ll have to create a new script with a new value every time you want to increase the number of users.
Consider this (better) scenario
- Generate a script for 1,000 users (or large number of users)
- Get the script to generate users and enroll them in the course(s)
- Run the test with 50 users (edit the ‘Number of threads’ value)
- If the test runs smoothly, all you need to do is edit the ‘Number of threads’ value and run the test again (the users are already enrolled)
Tip 3: Generate your script with lots of activities, and all activity types
- It is possible for you to easily disable activities right in the script after it has been generated.
- You might want to test the same course under different loads e.g. once with just a forum, once with a forum & a quiz, once with a forum, a quiz and a chat, etc.
- By creating a test with multiple activities, you can easily re-use the same test by simply disabling/enabling the activities you want to test/not test
- To disable an activity, you need to right-click on the activity name and then select ‘disable’.
- All disabled activities show up in grey
Tip 4: Edit the ramp-up period
- By default, the script generator sets the same value for the ‘Ramp up period’ as the number of users you selected when creating the script.
- The ramp-up period determines how long it takes for all virtual users (threads) to start.
- For example. if set to 0, all users would start at the same time. If set to 10 (as above), it takes 10 seconds to start all users (1 per second)
- You can play with different values and monitor how your server reacts to the changes
Tip 5: Disable some of the reports
If you are running tests with a lot of virtual users and multiple activities, you might get ‘out of memory’ errors on the computer you are running JMeter. To avoid this:
- Right-click on a specific report
- Select ‘Disable’
- This will not delete the report and you can decide to enable it again later