How to load test your Moodle server using JMeter

JMeter and Moodle logos

 

 

 

 

 

Note: this blog post is part of the Oktobertest series

This tutorial is aimed at Moodle administrators who have never used JMeter. It will help you get started but won’t teach you advanced techniques. Should you wish to dig further into this wonderful piece of open-source software, I invite you to read the following:

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

 

 

 

Most of the options above are self-explanatory, please note the following:

1. 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)
2. 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.
5. I usually tick this option, again to mimic real work usage as closely as possible
6. I like to set this to 10, for no particular good reason, I tend to like even numbers
7. 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

 

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

 

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

 

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:

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
 

11 comments

  1. Hi Frederic Nevers, first of all I’d like to thank you and appreciate you for sharing with us such useful site.

    I’m facing a problem. Whenever I’m selecting a category which contains quizzes: I’m getting following error message:

    Generate jMeter Script
    Table “quiz_question_instances” does not exist

    More information about this error
    Debug info:
    Error code: ddltablenotexist”

    However, for course categories with only forums, loadTesting script is working fine.

    What is going wrong? Can you pls help.

    Thanks.

    1. Hi,
      thank you for the kind words. I wonder if it’s something to do with a question type missing on your Moodle installation. I’m thinking maybe the Drag and Drop question type? A bit of a shot in the dark here
      Cheers,
      Fred

  2. Pls i have a problem Sir fred.
    I ran a test today with moodle 2.8.5 using a hp proliant 370 G6 server with 2GB of ram. I had about 220 clients and as they just logged in, d apache shut down and wrote out of memory. Just to login o. What happened pls and whats your advice?

  3. hola como estas me sale este error y ya cambie el mod por module

    Error al leer de la base de datos

    Más información sobre este error

    Debug info: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘mod
    ON module.id = cm.instance
    JOIN mdl_course course
    ‘ at line 8

    SELECT
    cm.id AS cmid,
    module.name AS name,
    module.id AS id,
    course.fullname AS course_name,
    course.id AS course_id
    FROM mdl_course_modules cm
    JOIN mdl_chat mod
    ON module.id = cm.instance
    JOIN mdl_course course
    ON course.id = cm.course
    JOIN mdl_modules modules
    ON cm.module = modules.id
    WHERE cm.visible = 1
    AND cm.course = ?
    AND modules.name = ?

    [array (
    0 => ’26’,
    1 => ‘chat’,
    )]
    Error code: dmlreadexception
    Stack trace:
    line 443 of \lib\dml\moodle_database.php: dml_read_exception thrown
    line 1080 of \lib\dml\mysqli_native_moodle_database.php: call to moodle_database->query_end()
    line 691 of \report\loadtesting\index.php: call to mysqli_native_moodle_database->get_records_sql()
    line 1071 of \report\loadtesting\index.php: call to test_setup->get_cms()

Leave a Reply

Your email address will not be published.