Thread scoped variable counter - jmeter

Looking to create a jMeter script with thread-local counter. I have a pool of 50000 (1 to 50000) keys and would like to spread them evenly over the number of threads in a threadGroup. Seems like I could do a simple calculation up front and create a min and max variable (ie: if I had 100 threads and my ${__threadNum} was 2 ... I would be looking at a __counter range of 501 to 1000. Is there a way to do that calc up front and then just run an efficient thread-scoped variable or function to loop thru the keys within the range for that thread (obviously next run could be 50 threads or 200). Thanks,

Related

Scale thread count by scaling factor

How would I do multiply two constants or variables .
I have a number of Thread groups in a Jmeter test each with a variable number of threads. I would like to multiple each threads Thread group by a constant factor , so I could run tests with different percentage of threads .
I have tried defining a scale factor as ${__P{scale,1}} so that I could multiply a constant thread count with the scale as 100 * ${__P{scale,1}} , but Jmeter doesn't seem to recognize that.
Of course it doesn't, you need to wrap your expression into i.e. __groovy() function.
Example syntax:
${__groovy(100 * org.apache.jmeter.util.JMeterUtils.getPropDefault("scale"\, 1),)}
More information:
JMeterUtils JavaDoc
Apache Groovy - Why and How You Should Use It

How to calculate the number of threads and loop count in jMeter

I am not able to find out the specific answer of how to calculate the number of threads for running a load test in JMeter?
How to identify the loop count ?
Is there any formula?
What are the parameters to consider for the calculation?
Say if you want to fire 100 request to server with 2 tps. then your threas properties should be like below:
Number of threads(users) :2.
Ramp up period: 100
Loop count :50
Based on above example.Please find below explaination.
• Number of Threads (N): Sets the number of threads the JMeter will use to execute our test plan. We must know that each thread will execute the whole test plan, which effectively utilizes the number of users that could use the tested service at any given time simultaneously.
• Ramp-Up Period R: Specifies how much time (in seconds) it will take for JMeter to start all the threads (simultaneous user connections). If the number of users is 5 and the ramp-up time is 10 seconds, then each thread will be started in a 2 second delayed interval. We need to be careful when setting this value, because if the value is too high the first thread will already finish processing the whole test plan before the second thread will even begin. This is important because that would effectively reduce the number of concurrent users using the testing server application at any given time. But the ramp-up period also needs to be high enough to avoid starting all of the thread at a single time, which could overload the target application.
• Loop Count (L): How many times each thread group will loop through all configured elements belonging to that thread group.
Hope it helps!

Why does using a higher Loop Count improve site performance in JMeter?

I've noticed that when load testing with JMeter, if I do a single loop I get a fairly long average time for my test. If I have say a Loop Count of 10, my average time peaks early on and then drops way down. For example if I setup a test on a simple get request for a page with the following settings:
Number of Threads (users): 500
Ramp-up Period(in seconds): 5
Loop Count: 1
My average time is about 4 seconds. If I change it to 10 loops:
Number of Threads (users): 500
Ramp-up Period(in seconds): 5
Loop Count: 10
I get an average time of 1.4 seconds.
Apache's documentation states that the Loop Count is:
The number of times the subelements of this controller will be
iterated each time through a test run.
Is it possible that this means the first request will actually do something on the server and the subsequent 9 requests will be pulling from cache?
How exactly is the Loop Count being used that would cause the results I'm seeing?
Yes, Remaining 9 requests must be pulling from cache.
Loop controller is simple loop executor doing nothing magic inside.
Improved performance is because of use of cached results on server.
If you want one thing you can try, use the loop controller but use different substituted parameters so that every
time different requests will be sent to server (I know that loop controller is for repeating same values, but this is just to confirm the effect of caching).
then compare the results.
I hope this clears the doubt :)

How does JMeter looping work?

Are the simulation loops separate? With separate I mean that JMeter waits for all threads to be done to begin a new iteration of the loop. Or does JMeter just let every thread do a request X time, without stopping?
Additional question: Could one change the number of threads dynamically? Doing a simulation for a range of number of thread (e.g. 100-1500) would be nice.
Each thread is completely independent. So when you have loop set, if a thread is finished its first loop of execution, it goes for another round (as per the loop count) irrespective of the completion of other threads.
You can use a variable for the number of threads & set the number via property files etc. But when the test is running, you can not change the no of threads for the test.
Hope it is clear!
In addition to vIns answer:
You CAN change load dynamically during execution. Threads count is static, but their fire rate is something you can impact.
Look into combination of Beanshell Server and Constant Throughput Timer.

JMeter Loop Count

I want to run a JMeter test with a number of concurrent threads with each thread sending a request every 10 seconds.
These are my thread properties.
Number of Threads: 10
Ramp-Up Period: 10
Loop Count: 1
Result: 10 requests divided over 10 seconds, so every second a request and exactly what I want.
Now I want to run this test for 3 times(30 seconds). So I set the Loop Count to 3.
But the result is: 30 requests in 10 seconds. This is strange, because I would expect to run this for 30 seconds and get 1 request per second.
How can I achieve this with JMeter?
My final goal is to run this test for a long period and also increase the Number of Threads.
How to do this with JMeter?
I researched this today and came to this conclusion: The Loop Count setting is a complete misnomer. It doesn't actually loop in any sort of chronological sense, even if your Test Plan has Run Thread Groups consecutively checked. What it does do is multiply your thread group and run all multiples concurrently. Therefore, the Ramp-Up Period is only respected once, and NOT once per "loop" - there is no temporal loop!
An explanation with graphs can be found here: http://pro-programmers.blogspot.com/2009/07/jmeter-max-threads-with-rump-up-and.html
Seems that the most simplest ways to control throughput in your tests is using either standard "out-of-box" Constant Throughput Timer or custom Throughput Shaping Timer from jmeter-plugins collection.
In both the cases structure of the test will be like the following:
Thread Group
Number of Threads = N
Ramp-up Period = N
Loop Count = 1
Constant Throughput Timer
Target Throughput = 60
Calculate Throughput based on = "all active threads in current thread group"
. . .
Loop Controller
Loop Count = M
. . .
HTTP Request
. . .
Here Loop Controller defines number of iterations.
Looks like both the timers are not absolutely precise as well as both are a bit differently configurable:
Here is also a kind of practical example how to vary the throughput.
In my experience with Jmeter if you set
Number of Threads: 10
Ramp-Up Period: 10
Loop Count: 1
you create 10 threads into 10 seconds so you create 1 thread every second.
With loop count of 1 you repeat this once.
But if you increase loop count I think that you don't create new threads but repeat jmeter elements procedure in the Thread Group therefore the time beetween the request isn't 30 seconds but just over 10s.
If you want to create 30 threads within 30 seconds you have to set
Number of Threads: 30
Ramp-Up Period: 30
Loop Count: 1
If you want to repeat 10 threads for 3 times with ramp- up of 10 seconds you should insert a Timert->Constant Timer with thread delay of 10000 ms so you obtain 30 requests in 30 seconds (really you should consider the time of executions of the task)
refer link: http://www.testingjournals.com/5-must-know-features-thread-group-jmeter/
scenario 1 :
number of threads = 20
Ramp-up period =100
loop count=1
Every 5 seconds(100/20) 1 request/thread will hit the server,Execution will start with 1 request at a time
scenario 2 :
number of threads = 20
Ramp-up period =100
loop count=4
Every 5 seconds(100/20) 4 request/thread will hit the server, once the 1st request/thread completes , it will start 2nd loop by executing same HTTP request,Execution lasts until all 20 threads executes all HTTP requests 4 times
My understanding of Ramp-Up is that a value of 0 will fire all threads at the same time (concurrently).
You might be able to achieve what you want by setting the following:
Number of Threads: 10
Ramp-Up Period: 0
Loop Count: N
and then using a Controller to determine when to end each loop.
Yup, the Loop Count parameter is not intuitive. From what I figured out it is actually the number of times the thread/user performs a particular test
So if I understand correctly your intention that you want:
to run N number of concurrent threads/users
each of them sends a request every 10 seconds
you want to run this scenario for around 30 seconds
the configuration should be the following:
Number of Threads: N
Ramp-up Period: 0
Loop Count: 3
And in Constant Throughput Timer (within the Thread Group) you should set Target Throughput (samples per minute)=6, which means request every 10 seconds

Resources