Articles

How to Change JMeter´s Load During Runtime

by Nicole Wells Cut me I will bleed content
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 about Jmeter Training click the link.

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)}.

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.

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.

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

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:

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.

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.

About Nicole Wells Freshman   Cut me I will bleed content

16 connections, 0 recommendations, 46 honor points.
Joined APSense since, October 3rd, 2017, From plano, United States.

Created on Sep 18th 2018 06:52. Viewed 183 times.

Comments

No comment, be the first to comment.
Please sign in before you comment.