Alejandro Berardinelli is a Systems Engineer, with more than 3 years of experience in Performance Testing at Abstracta. He has solid experience in all roles involved in the performance testing cycle, from scripting to automating, executing and gathering results, to analyzing and obtaining conclusions and improvement recommendations. Alejandro also worked for 10 years at IBM as a Storage specialist, coauthoring several IBM Redbooks.

Learn JMeter in 5 Hours

Start Learning
Slack

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

Sep 03 2018

How to Change JMeter´s Load During Runtime

On certain occasions it is useful or necessary to be able to change the load generated by the performance test, without stopping the test. This can be done by using Apache JMeter™´s Constant Throughput Timer and the Beanshell server. In this post we will cover how to accomplish this, while providing examples. 

 

During performance tests scenarios, load is primarily defined by the number of Virtual Users that access the application being tested. In JMeter, virtual users are implemented as threads. Other parameters or variables that can also define the testing load are test duration, thinktimes and ramp-up period. In this post, the load parameter we will be changing is throughput, through the Constant Throughput Timer. 

 

By using the Constant Throughput Timer element, JMeter allows defining the number of requests per minute being sent, by introducing pauses between the requests, while the number of threads remains unchanged. Please refer to Constant Throughput Timer component reference for more information.

 

1. The first step for this configuration will be adding the mentioned element to JMeter. The Constant Throughput Timer will control how many requests per minute are performed on the test, by the setting of the “Target throughput” value. Since we will be updating this value through the command line, it must be defined as a parameter (“hits” in the example). The default value will be set to 100 by writing ${__P(hits,100)}.

 

This configuration is shown in the following screenshot:

 

changing jmeter load runtime

 

It makes sense to place this element at a Thread Group level so all the threads in it will be controlled generating the desired objective load on this group. Also, the throughput will be adjusted on a per thread basis as the value “Calculate Throughput based on” reflects.

 

It is important to remark that the load is adjusted to match a requests per minute value, so give your test some time to notice the throughput change.

 

2. The next step will be to use JMeter Beanshell as a server so you can issue Beanshell commands. For the purpose of this example, we will update the “hits” parameter defined previously by invoking a beanshell function. Beanshell is a Java source interpreter that is built into JMeter, allowing you to execute Java code and extend it with scripting capabilities. More information can be found on BeanShell’s home page.

 

The necessary steps to do this will be described in the following lines:

 

3. Enable the Beanshell server when JMeter starts:

 

  • First configure the TCP port where the server will be listening. We used 9000 on this example.
  • Secondly, specify the .bsh server file that will start it. This file is already shipped with JMeter and there is no need to edit it.

 

For this purpose, the following lines should be uncommented on jmeter.properties:

 

beanshell.server.port=9000
beanshell.server.file=../extras/startup.bsh

 

4. Right after JMeter starts, we can validate the Beanshell server is up and running by checking its TCP port status. On windows this can be accomplished on a DOS command window by the following command:

 

netstat -an | find 9000

 

how to change throughput during runtime jmeter

 

5. Create a .bsh file in order to modify/update the “hits” parameter. We created the folder bsh\ under the JMeter home directory to keep directories ordered and added a .bsh file called update_parameter.bsh with the following content:

 

setprop("hits", args[0]);

 

jmeter runtime change


Basically, this file calls the setprop function to update “hits” with the value in the first argument provided (args[0]).

 

6. We are now able to invoke the created .bsh to update “hits” while our test is running. Through the following command (the current path is JMeter home´s directory), we will update the parameter to “10” requests per minute:

 

sjava -jar .\lib\bshclient.jar localhost 9000 .\bsh\update_parameter.bsh 10

 

The command first invokes the beanshell client through bshclient.jar that will connect to localhost on 9000 TCP port, which is the address where our beanshell server is listening. Next, the command calls the update_parameter.bsh with “10” as its first argument. This will invoke the setprop function setting “hits” to 10, thus slowing our test load.

 

Next, a sample invocation DOS window is shown:

 

changing load in jmeter with beanshell

 

7. This command can be invoked at any time while your test is running, so the JMeter requests per minute can be updated. This can be performed when either running JMeter through the command line or the GUI.

 

Putting this all together in action, we will show how the load varies on the JMeter GUI. We created a simple Test that performs requests to our openCart Test page. Inside its thread group we also placed the Constant Throughput Timer, to control the generated throughput.

 

By default, the “hits” parameter is set to 100 requests per minute and the test will be run by 5 threads.

 

The test plan structure is shown below:

 

changing jmeter test throughput with constant throughput timer

 

Also, a Graph Results element was added (right click on the Test plan -> Add -> Listener -> Graph Results) to graphically show the test results.

 

After letting the test run for several minutes, in order to generate enough samples on the graph, we updated “hits” to 1:

 

test run, throughput update

 

The dotted green line in the graph generated shows the throughput decrease after a period of time where requests per minute remained stable. 

 

altering throughput during jneter test

 

JMeter is a really good tool that allows you to create and execute performance tests. In this post we presented how the generated load can be updated during a test without the need to stop it. We hope you find this post useful to develop your scripts and tests.

 

Changing Your Throughput in BlazeMeter

 

To change your throughput in BlazeMeter, first, configure the parameter in the Constant Throughput Timer in JMeter. Then, click the Remote Control button at the top of your BlazeMeter reporting screen during your test. Finally, enter new value(s) and click Send to update the property on all engines. Learn more from here.

 

throughput update in blazemeter

 

To try out BlazeMeter, put your URL in the box below and your test will start in minutes. Or, request a live demo from one of our performance engineers.

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.