JMeter et Latency of the last Request - jmeter

Is there any way to get the latency (i.e. duration) of the last request? I need this, because I want to wait e.g. 10 seconds - duration-of-last-request seconds. But for this I need the time taken by the last sampler/http request. How do I get this?

Take a look at JSR223 PostProcessor, the relevant code would be something like:
sleep 10000L - prev.getTime()
where prev stands for the previous SampleResult, see the JavaDoc for comprehensive information on all methods/fields and Top 8 JMeter Java Classes You Should Be Using with Groovy for other useful JMeter API shorthands available for the JSR223 Test Elements

Related

Display Response Body on the report JMeter

I try to show a script result on the report
Hello all,
I have written a test where I am trying to determine the total duration of a thread.
I calculate the time with JSR223 script:
[]
This is my result:
[]
The results are calculated correctly, but on the HTML report I have only the time from the request.
[]
[]
Does anyone know how I pass the calculated time from the ResponseBody?
Thank you very much.
If you want to set your JSR223 Sampler execution time to the value of your JSR223 Sampler result text you need to use JSR223 PostProcessor and the following code:
prev.elapsedTime = prev.getResponseDataAsString() as long
where prev stands for the previous SampleResult, see JavaDoc for all functions available with descriptions and Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information on this and other JMeter API shorthands available for the JSR223 Test Elements.
also remove this /1000 bit from your JSR223 Sampler code as JMeter elapsed time is in milliseconds, if you want it to be in seconds - round it up so it won't have any decimal points.

How to measure the start to endtime of a thread in JMeter

I have been trying to figure out how to measure the amount of time it takes a thread (virtual user) in JMeter to fully complete. I'm not necessarily concerned with response times at the moment. The API that I'm attempting to load test works in an async fashion. I make a request to start a job, I'm given a job id then I use that job id to check the status of said job until it's complete. I'm interested in knowing how long it takes for each job to complete i.e. when the job starts (thread is created) and when the job is completed (thread is done working).
I've seen several people suggest using the Transaction Controller in similar situations but that, unless I'm misunderstanding, gives me the total response time for all the requests in the "transaction" which doesn't help me.
This is what I have setup so far in JMeter:
Which actually works great, I make the initial request to submit the job and extract the job id. In a while loop I check the status of the job using the extracted id every 10 seconds (Constant Timer) until the job is complete.
This is what the aggregate report looks like for 5 concurrent users, I can also make the labels be the same so that it's compacted further but none of this information tells me how long a thread took. From the number of samples I can surmise that half the threads took roughly 10 seconds to complete and the others I can multiply by 10 seconds (sleep timer) and get a rough estimate how long it took to complete but that would be difficult to do (or at least time intensive) for a couple hundred threads. I was really hoping JMeter had something out of the box that would give me this information in a nice report format.
I've also seen suggestions that the only way to get this type of information is to parse logs, was just wondering if anyone has solved a similar problem.
Your question contains the answer, just measure it
Add JSR223 Sampler to the beginning of your Thread Group and put the following code into "Script" area:
SampleResult.setIgnore()
vars.putObject('startTime', System.currentTimeMillis())
the first line tells JMeter to not to store the JSR223 sampler result (as I believe you don't need this) and the second line saves current timestamp into ${startTime} JMeter Variable
Add another JSR223 Sampler to the end of your Thread Group and use the following code there:
SampleResult.setIgnore()
def end = System.currentTimeMillis()
def start = vars.getObject('startTime')
log.info('Thread ' + (ctx.getThreadNum() + 1) + ' elapsed time: ' + (end - start))
here we get the current timestamp after the job ended and subtract it from the previous timestamp store in the first JSR223 Sampler. The delta is printed to jmeter.log file however you might rather want to store it into another JMeter Variable and expose it to the results via Sample Variables property so it would be added to .jtl results file
Demo:
See Top 8 JMeter Java Classes You Should Be Using with Groovy to learn more about what these SampleResult, vars, and ctx shorthands mean

How to execute a BeanShell PostProcessor after all samples end on Jmeter?

My goal is make a beautiful report about my test plan. I'm using about 50 threads and infinite loop so I want get the responses content and make the report. The problem is that the PostProcessor execute every sample request end so I can't put it all together on the same context to use all data and if I use the data every sample ends the results becomes a big mess. I don't found the solution on the web and I'm newbie with Jmeter. So, there are a way to wait all threads ends and get all responses data on 1x time ?
First of all don't use Beanshell, since JMeter 3.1 you should switch to JSR223 Test Elements and Groovy language
If you need to collect response data the best option is writing it into a file using i.e. Flexible File Writer and if any post-processing is needed you can perform this using JSR223 Sampler in the tearDown Thread Group

There are 5 Parallel request executing in under 1 TR controller of Jmeter

Let,c These below are the 5 request in one Transaction controller
https//detailslist/Json/1
https//detailslist/Json/2
https//detailslist/Json/3
https//detailslist/Json/4
https//detailslist/Json/5
Note : Above request are executing parallel in browser and the response time of the browser is one of the highest response time of the request (request 4 is having high response time i;e 6 sec and this is the total response time of this page)
In Jmeter what is happening, It is giving response time sum of all 5 request i;e 12 sec.Which is higher than browser.
How we can do this in Jmeter. is there any solution or option are available in jmeter to execute request parallel in jmeter.
Thanks in advance to people who will answer.
JMeter executes sequentially samplers under Transaction Sampler.
There is an enhancement request for that but I am not sure it will be implemented one day:
https://bz.apache.org/bugzilla/show_bug.cgi?id=53159
To do this , you would have to code a JSR223 Sampler using groovy as a language for example.
Currently JMeter cannot kick off any extra threads to simulate the behaviour so the options are in:
Write your custom sampler which will kick off several parallel threads from JMeter Thread
Use scripting-enabled sampler like Beanshell Sampler or JSR223 Sampler
See How to Load Test AJAX/XHR Enabled Sites With JMeter guide for more detailed explanation and some reference code for points 1 and 2

How can I test the limit of the number of threads with Jmeter

Is it possible to automate the load tests in Jmeter and increase the number of threads until the first error is observed?
For example I start with testing 16 threads for every seconds and increase the number until i receive an error. But instead of doing this manually can I let this run automatically?
Looking into Pre-defined Properties section of JMeter's User Manual on Functions there is a JMeterThread.last_sample_ok variable holding result of the last sampler execution.
So if you build your test plan as follows:
Sampler which does test action
If Controller checking whether previous sampler was successful
If not - relevant actions (stop test, send email, stop ramping up virtual users, etc.)
The value you need to put in "Condition" input of If Controller should look like
"${JMeterThread.last_sample_ok}"=="false"
See How to use JMeter's 'IF' Controller and get Pie for more information on JMeter's If Controller.
Regarding threads in jmeter You may find those 2 links interesting:
What is the highest number of threads that is reasonable to simultaneously run in Jmeter?
JMeter max. thread limit
Regarding your methodology, why not use slow rampup and see the limit using what Dmitri T has provided ?

Resources