Nitin Gurram is a performance testing expert with almost a decade of experience in performance testing and engineering. He has helped his clients transform their web applications by making them much faster and more reliable.

Learn JMeter in 5 Hours

Start Learning
Slack

Run massively scalable performance tests on web, mobile, and APIs

Mar 13 2018

Ramping-up Thread Groups in JMeter with the JavaScript Function

If you have been using Apache JMeter™ for a while, it is very likely that you have created a test plan with multiple thread groups. You may have noticed that it becomes increasingly challenging to set up all the thread groups to work together as you add more. In this post, I will go through some tips and tricks to make this process automatic and error-free.

 

Creating your Test Scenario

 

To illustrate the process, I will be using JMeter 4.0, but you should be able to complete these steps with almost any JMeter version. I will be using three different thread groups.

 

Let’s say I’m testing an e-commerce website that has a release that needs to be load tested. In the scenario, a load test will run for an hour with 30 users who are using computers, 60 users using mobiles and 10 users using tablets. Ramp up is 1 user per second, totalling 100 second ramp-up for all users.

 

In our tested website, the load pattern constantly changes as it grows. Hence, our goal is to create a test plan with three different thread groups (Web, Mobile and Tablet) and make it easy to change users without affecting the test duration ( total time - (Ramp up)).

 

Our test plan is going to have three different thread groups as shown in the diagram below. We will ramp up one thread group at a time (Web, Mobile and Tablet in that order) and run a test for an hour.

 

ramping up thread groups

 

Calculating Ramp ups

 

As stated in the scenario, we need to create thread group with the following settings:

  • Web_threads     = 30
  • Mobile_threads  = 60
  • Tablet_threads   = 10
  • Stable duration  = 3600 seconds
  • Ramp up time per thread = 1 second

 

Let us now make calculations for our three different thread groups.

 

Web Thread Group

 

  • Number of threads = 30
  • Ramp-up period= Number of threads *  Ramp up time per thread = 30 * 1 = 30
  • Total test duration = Ramp up + stable duration = 100 + 3600 = 3700
  • Delay = 0

Delay is zero as the Web thread group is the first thread group to start.

 

This is what the Web thread group configuration looks like:

 

configuring thread group ramp up in jmeter

 

I will be making a similar calculation for the two other thread groups.

 

Mobile Thread Group

 

  • Number of threads = 60
  • Ramp-up period= Number of threads *  Ramp up time per thread = 60 * 1 = 60 seconds
  • Total test duration = Ramp up + stable duration = 100 + 3600 = 3700 seconds
  • Delay = time to ramp up previous thread groups = ramp-up period for web = 30 seconds

 

guide for jmeter rampup

 

Tablet Thread Group

 

  • Number of threads = 10
  • Ramp-up period= Number of threads *  Ramp up time per thread = 10 * 1 = 10
  • Total test duration = Ramp up + stable duration = 100 + 3600 = 3700
  • Delay = time to ramp up previous thread groups = ramp-up period for web +ramp-up period for mobile = 30 + 60 seconds = 90 seconds.

 

how to ramp up thread groups in jmeter

 

Parameterization

 

Since the load pattern on the website is changing, you constantly have to recalculate and update your thread group properties, or alternatively you can save time by parameterizing these test configurations.

 

In this example, I will be using User Defined variables but you can also use CSV Data Set Config or JMeter properties. As you can see I set the variable values for the number of threads for each type of thread group, for the duration of the complete test and for the ramp up duration.

 

jmeter ramp up settings

 

According to our test scenario, I set:

  • Web_threads = 30
  • Mobile_threads = 60
  • Tablet_threads = 10
  • Stable_duration = 3600
  • Rampup_duration = 1

 

Now you can reuse these variables and create a mathematical formula using the ${__javaScript(,)} function.

 

Now let’s set up the thread groups with the relevant formulas:

  • Ramp up period = (No of threads) *(Ramp Up duration per thread)
  • Duration = (Stable duration) + ( Total ramp up duration)
  • Delay = (Time take to ramp up previous thread groups)

 

After making these changes and applying the formulas I used in earlier calculations, the thread groups look like this:

 

setting up automatic ramp up in jmeter

 

  • Number of Threads: ${Web_threads}
  • Ramp-Up Period: {__javascript(${Web_threads}*{Rampup_duration},)}
  • Duration: ${__javaScript(${Stable_duration}+${Web_threads}*${Rampup_duration}+${Mobile_threads}*${Rampup_duration}+${Tablet_threads}*${Rampup_duration},)}
  • Startup delay: 0

 

thread group ramp up in jmeter

 

  • Number of Threads: ${Mobile_threads}
  • Ramp-Up Period: {__javascript(${Mobile_threads}*{Rampup_duration},)}
  • Duration: ${__javaScript(${Stable_duration}+${Web_threads}*${Rampup_duration}+${Mobile_threads}*${Rampup_duration}+${Tablet_threads}*${Rampup_duration},)}
  • Startup delay: {__javascript(${Web_threads}*{Rampup_duration},)}

ramping up load test scenario

 

  • Number of Threads: ${Tablet_threads}
  • Ramp-Up Period: {__javascript(${Tablet_threads}*{Rampup_duration},)}
  • Duration: ${__javaScript(${Stable_duration}+${Web_threads}*${Rampup_duration}+${Mobile_threads}*${Rampup_duration}+${Tablet_threads}*${Rampup_duration},)}
  • Startup delay: {__javascript(${Web_threads}*{Rampup_duration}+${Mobile_threads}*{Rampup_duration},)}

 

Now that the test plan is all set up, all you have to do next time you want to change the number of threads, is update the number of threads in the user-defined variables.

 

That’s it! Now that you know how to automate the process with three different thread groups you can apply a similar principle to a different number of thread groups or with a different type of thread group. Learn more JMeter use cases in our free JMeter academy.

 

JMeter is compatible with BlazeMeter, which enables running your JMeter test in the cloud through multiple geo-locations, fast scaling, collaboration and advanced analysis. Request a demo to learn more, or put your URL in the box below and your test will start in minutes.

You might also find these useful:

Interested in writing for our Blog?Send us a pitch!

Your email is required to complete the test. If you proceed, your test will be aborted.