In Jmeter calculate time taken to get a specific response in jmeter - jmeter

I am using a while loop to run a API request until a specific response is recieved (eg. Job status). Now, I want to calculate time taken for a job to reach that status. I want to generate a report with jobID, status and the time taken. Is there a way to do that? Any help on this will be highly appreciated.
enter image description here
While condition that i am using: ${__jexl3(${__jm__While Controller__idx} < 300 && "${Status}"!="Ready",)}

Put everything under the Transaction Controller, it will return the cumulative time of all its children execution
More information: Using JMeter's Transaction Controller

Related

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

Save Actual Response time for a Process from Start to Complete in summary report(jtl) in jmeter

I have jmeter test plan in which I create a workflow which transitions statuses like Not Started to In Progress to Completed.
The problem I am having is how I can measure how long it took for workflow status from the time of creation to it get completed? Since we are logging the response time of api calls only.
Is there a way we can extract this info and also add it to the summary (jtl reports?) I was thinking if I could do it from beanshell post processor where I have the wait time calculated and also checking the status of workflow and I could write to the summary result (jtl). How can I do this?
I have the test plan set up something like this:
Thread Group
- Create Workflow API call
- WhileLoop(checking on a flag set by beanshell post processor)
- Wait for 5seconds
- Check for timeout using JSR223 sampler(java)(don't want test to run inevitably if something goes wrong so want to break the loop after a fixed amount of time)
- Get Workflow status API call
- Beanshell post processor to check the response from above call to see if status is Completed or wait time has exceeded. In either of these cases I set the while loop flag false if not repeat the loop wait for 5 seconds and so on.
For the test itself it works as expected.
Use transaction controller to measure the time taken. Please check the reference;-
The Transaction Controller generates an additional sample which
measures the overall time taken to perform the nested test elements.
Hope this helps.

Take difference in time stamps to initiate logout in JMeter

In my jmeter script, I want to apply a logic where I take the time stamp of the first request and the second last request with the last request being logout. The difference in the time stamps when exceeds 3600 sec should trigger the logout transaction. I can take the time stamps using the jmeter _time function but not able to subtract it successfully. If I can get this done then I can put logout in an if controller and give the condition. Can anyone help please?
Check out __longSum() function which you can use to subtract 2 Unix timestamps
Define start as: ${__time(,start)} where required
Define end as: ${__time(,end)} where required
You can get the difference between end and start as ${__longSum(${start},-${end},)}
Demo:
More information: How to Use JMeter Functions

Developing JMeter test plan with results from multiple REST end points

Is this possible in JMeter to develop a test plan that will have result of first test (an ID) will be input of next test and so on in next test upto 4 tests because each test generates a unique ID and each of these IDs are dependent on each other. Each one is related as follows: submission ID > execution ID > both will generate completion ID with result pass or fail. These are REST API calls. I need to run concurrency users load testing. Finally I need measure latency, throughput from each test.
Between sampler requests, parse the api response using JSON post processor, assign it to ${variable_name} and use it in other requests.
It should look something like this.
Thread group
Userdefined variables
Http Sampler
Regex to get id
Http Sampler
Regex to get id
If you want to measure the response time of all the sampler have a simple controller as parent of all samplers
thank you for quick tip. I was able to get one step working by passing ID into a regular expression, but the same regular expression did not work for 3rd step. Let me give more details here. Basically first post command gives submission ID > I used that ID into regular expression > run a get command in next step with an URL something like '/../2ndStep/submissionId' > this is passed > I'm using the same regular expression in next get command with an URL something like '/../3rdStep/submissionId/executions'> this is supposed to give another executionId and it is failing for me. I'm not sure what I'm missing.
thank you all for suggesting working solution. But I need to do this different way to achieve the following requirement.
When I run POST command test on my REST API HTTP request using JMeter, it returns an ID in response. This ID will be used by other steps for completing the job. I'm currently passing ID into regular expression and using that in between the samplers of each step as it was suggested above and then measuring latency, but the GET steps which are dependent on that ID could take sometime to complete. So I can not put those GET steps into one thread because two of the steps are failing as they could take some time to complete. Is there a way to separate POST command from the remaining and start polling GET commands on the remaining steps automatically to remedy this. Bottom line is I need to measure latency of each step and throughput too. Please let me know if there is a way to achieve this in JMeter?
Thanks again,
Santana

Jmeter- how to find the time taken for the report to generate

how to check the time taken for some report to generate using jmeter
In my application we need to submit report and check for the time taken for the report to be completed. it usually takes about 15-20 minutes. How to check that using jmeter.
I checked in Listener- View results in table , aggregate report - it doesn't have that info. Kindly help
In Jmeter you can use below logic to check for completion time of report generation activity.
and your report generation activity has columns similar to,
Which has start time and end time (from which you can get approx time for your report generation activity, this raises question if you see this through UI why are you saying, you cant find out execution time for report.)
If you want it in Jmeter load testing then probably you have a custom code(beanshell postprocessor) extracting both values from result and logging it into log file.
status check workflow would be somewhat like,
While controller ------- to loop continuously till our condition satisfied (my mistake, value should be status!=complete)
http request ---- Refresh reqeust
Constant time ---- delay of 2 seconds

Resources