Dynamic Request per minute in Jmeter - jmeter

When we have a constant request per minute we can use timer to control throughput, but let's assume we have a CSV containing a number of requests every minute (dynamic throughput per minute) like:
| timestamp | Num. Of. Request|
| ..01:01:00| 9 |
| ..01:02:00| 3 |
| ..01:03:00| 23|
| ..01:04:00| 5 |
I tried to use constant throughput timer with beanshell but with handy input value not from csv.
Is there any good way to simulate this in Jmeter?

First of all are you aware of Throughput Shaping Timer in general and load_profile special property in particular?
If you want to continue with your "CSV" approach here is how it could be implemented: you can read the file in Groovy in separate Thread Group and overwrite the property value
"Handy" shorthands:
new File('path-to-your-file.csv').readLines().get('x') - read line number x from the test.csv file
vars.get('TESTSTART.MS') as long - get Unix timestamp of the time when the test was started
props.put('throughput', some-value-from-CSV-here) - write the value from CSV into throughput JMeter property
Then you can use ${__P(throghput,)} function in the Constant Throughput Timer
More information:
__P() function
Pre-Defined Properties
Top 8 JMeter Java Classes You Should Be Using with Groovy

Related

how to increment the number in jmeter body whenever we run jmeter run

i want to increment the batch number in my jmeter body whenever i run the jmeter run
say for example im running 1 request it should be like bleow
'batch_number_1_2022-09-27_1'
also if i run 2 request it would be , batch number remains the same for that run only counter changes fo as many request we trigger
'batch_number_1_2022-09-27_1'
'batch_number_1_2022-09-27_2'
now when i run the jmeter 2nd time again it should be like below(batch number should be incremented)
'batch_number_2_2022-09-27_1'
and so on like below for everytime when i trigger jmeter run
'batch_number_3_2022-09-27_1'
|
|
|
|
'batch_number_n_2022-09-27_1'
Take a look at Counter configuration element or __counter() function, the first one generates an incremented number on each iteration, the latter one each time it's being called.
So if you amend your payload to look something like:
batch_number_1_2022-09-27_${__counter(,)}
you will get the incremented postfix
More information: How to Use a Counter in a JMeter Test

Jmeter request and report validation

My Requirement is to execute 10 request per second for 5 minutes. The configuration I have used is
Thread Group Properties:
number of threads : 600
ramp up period : 60
Loop count : 5,
Add Sampler -> Flow Control Action
Select Logical Action on thread as Pause
Duration(milliseconds) :60000
I used the below command to run jmx from command line to generate xls and generate html report.
/jmeter.sh -n -t demo.jmx -l demo.xls -e -o ./report
Need to know if the configuration I have mapped is correct or not?
I have also looked at constant throughput timer and Runtime controller to stop the execution after 5 mins?
I am not able to validate the end result?
You can see what actual throughput your test generated using Transactions Per Second listener or the relevant chart in the HTML Reporting Dashboard
With regards to configuring JMeter for sending 10 requests per second for 5 minutes I would rather recommend going for Concurrency Thread Group and Throughput Shaping Timer combination.
Configurations:

JMeter - execute requests according to given millisecond offset

For a JMeter load test, I'd like to replay what we call a 'playbook', which has a form similar to this:
offset ms | request
--------------------------
0 | http://localhost/request1
7 | http://localhost/request2
12 | http://localhost/request3
25 | http://localhost/request4
... | ...
Where '0' is the start time of the test, and each request should be fired exactly x milliseconds after that, as given in the first column, irrespective of how long the single requests take.
What I want to avoid is the regular way JMeter works, where each thread basically fires one request after the other.
Background: We already have a tool which creates this sort of playbook, and it is a very realistic way of simulating user behavior. We are now evaluating if we can use JMeter to execute them.
In JMeter this is similar to Think time,
You can add after each request similar to Think time a Test Action after each request and under it a Timer as a Uniform Random Timer with Random = 0 and in your case:
After first request 7000 Constant Delay Offset
After second request 5000 Constant Delay Offset
After third request 13000 Constant Delay Offset

Jmeter property get/put issue

I have the following flow,
Thread Group 1
-JSR223 Sampler - props.put("x",10);
Thread Group 2
Number of threads(users) = ${__P("x")}
I am setting a property value which is not defined in any property file as 10. I am trying to use that value in the next thread group. But instead of ten threads, I get only 1 thread to start.
Documentation says ${__P()} would give 1 if the property is undefined. How can I set the THread Group 2's thread count to x value?
You need to pass that value from command line, when you run the test appended by -Jx.
So when you run your test, Pass value of X from command line
-JPropertyName=ProperyValue
This will pick up value as 10.
Setting property should be
props.put("x","10");
i.e. it wants value in String format, and function should be put, not set.
Thread Groups are being initialised during JMeter startup so you won't be able to set the number of threads in the Thread Group this way. You have 2 options:
Set the property value in user.properties file (lives in the "bin" folder of your JMeter installation) like
x=10
Pass the property value -J or -D command-line arguments like
jmeter -Jx=10 -n -t ....
jmeter -Dx=10 -n -t ...
The default value returned by the __P() function will never be 1 due to a bug in JMeter (you can report it via JMeter Issue Tracker if you want), its default value will be an empty string. If you want the __P() function to return 1 as default value you should be using it like ${__P(x,1)}
See Apache JMeter Properties Customization Guide guide for more information on working with JMeter Properties, ways of setting and overriding them, etc.
Although you cannot change the number of threads on the fly, you can control how often the samplers are executed via Constant Throughput Timer. This way you can use __P() function to set the desired throughput rate (in requests per minute) and you can change the associated property value on the fly even outside of the JMeter script.

Execute httpSample conditionally JMeter

I need to test a REST method for saving an object. In order to have the ability to save it I need to request an authToken that is updating each 100 seconds.
Right now I have a thread containing both requests , and the login request is executed each time the saving does. How can I make the login execute once at the start of the thread and then each 100 seconds ?
P.S. I've tried separating it in 3 threads , one for the initial login , the other with a loop and a 100 seconds timer and finally the one with the actual test. It does work ,but it seems like a bad solution.
How about:
|-Login
|-Loop n times
|-Save
n being number of times that will be just about less than 100ms?
or
|-If login valid?
| |-NO: Login
|
|-Save
option 3:
ThreadGoup1
|- Login
|- Beanshell update shared token
|- Constant throughput timer
ThreadGroup2
|- Beanshell fetch shared token
|- Save
A constant throughput timer allows you to run at a set throughput. Once every 100 seconds is 0.6 samples per minute, I'm not certain you can do fractions, but even 1 sample a minute should work for you.

Resources