I have an MVC Web aPI and I have trouble in comparing the response time of this API. I added some code to calculate the response time:
In the AuthorizationFilterAttribute OnAuthorization, I have the below code:
actionContext.Request.Headers.Add("RequestStartTime", DateTime.Now.ToString());
I have an ActionFilterAttribute, and an OnActionExecuted in which I have the below code:
string strRequestStartTime = actionExecutedContext.Request.Headers.GetValues("RequestStartTime").First();
DateTime dtstartTime = DateTime.Parse(strRequestStartTime);
TimeSpan tsTimeTaken = DateTime.Now.Subtract(dtstartTime);
actionExecutedContext.Response.Headers.Add("RequestProcessingTime", tsTimeTaken.TotalMilliseconds + "ms");
The response has the header "RequestProcessingTime" in milli seconds. The issue is whenever I try the same request using Postman/JMeter, I see that the response time is lesser than what I see in my Response. Why is this happening?
I think this is due to the fact the header does not consider time for request to reach the server and response to travel back, my expectation is that it shows only the time, required to process the request on the server side. So JMeter reports time as delta from the time when request has been sent and the time when the last byte has been received, which is more correct in terms of real user experience.
See definitions of "Elapsed Time", "Connect Time" and "Latency" in the JMeter Glossary. You may also be interested in How to Analyze the Results of a Load Test article which demonstrates the impact of network capacity on the overall performance
Related
I am doing load testing on generating report and the requirement is like the report should get generated within 10mins.
It includes one HTTP post request for report generation, and then there is a status check call, which keeps on checking the status of the first request. Once the status of first request changes to complete then the report generation is successful.
Basically I want to start the timer at the begining of the first request and stop the timer once the status is complete and need to add assertion if the time is less than 10 mins then test is pass else fail.
I tried multiple approaches like using Transaction controller, and adding all request under it. But this doesn't give sum but the average response time of all the request under it.
Also, I tried beanshell listener, extracting the response time for every request and adding them all...
var responseTime;
props.put("responseTime", sampleResult.getTime());
log.info(" responseTime :::" + props.get("responseTime"));
log.info("time: "+ sampleResult.getTime());
props.put("responseTime", (sampleResult.getTime()+props.get("responseTime")));
log.info("new responseTime :::" + props.get("responseTime"));
However, I am not interested in adding the response time of these requests, instead I need to just know what is the time elapsed from when the report is triggered and till it gives status as complete.
All the jmeter timers are adding delays, I dnt wish to add delay instead I need it as a timer.
Any help is highly appreciated.
Thank you
Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting mainly due to performance reasons so I'll provide one of possible solutions in Grovy
Add JSR223 PostProcessor as a child of the HTTP Request which kicks off the report generation and put the following code there:
vars.putObject('start', System.currentTimeMillis())
Add JSR223 Sampler after checking the status and put the following code there:
def now = System.currentTimeMillis()
def start = vars.getObject('start')
def elapsed = now - start
if (elapsed >= 600000) {
SampleResult.setSuccessful(false)
SampleResult.setResponseMessage('Report generation took: ' + (elapsed / 1000 / 60) + ' minutes instead of 10')
}
Example setup:
I am using Jmeter for performance testing of my application. I am testing the websocket component and for that I am using plugins (Peter Doornbosch and Maceij Zaleski)
I am getting proper response back from websocket but I am stuck in finding out the response time of websocket component. I am using the listener 'View result tree' and it gives me back 'Load Time' but the value of this field varies with response timeout.
For ex : If I give response timeout as 1000 ms , the result comes like (1000 + few ms )
If I give response timeout as 500 ms , the result comes like (500 + few ms)
Please let me know if there is any way to find out the accurate response time.
enter image description here
enter image description here
enter image description here
From what I see from the screenshots:
You're using the plugin from Maceij Zaleski
It reads from the stream for the specified amount of time
If you're interested in getting the timings for reading a single message - I would suggest switching to WebSocket Single Read Sampler from Peter Doornbosch
More information:
Single read sample.jmx example test plan
JMeter WebSocket Samplers - A Practical Guide
Can you recommend plugin or report for Jmeter 4.0 which count number of requests with responses lower than < define time (eg, 200ms, 500ms, etc.)
I would like get answer on below question:
How many requests per sec can be sent that response time of 90% responses is lower than 200ms
How many responses is below 200ms from Total
% of responses to the response below 200 ms from Total
I'm not aware of any existing plugin which implements your requirement, however you can achieve this using JSR223 Listener
Add JSR223 Listener to your Test Plan
Put the following Groovy code into "Script" area:
if (prev.getTime() < 200) {
prev.setSampleLabel(prev.getSampleLabel() + " < 200")
}
That's it, if your Sampler response time will be below 200 the JSR223 Listener will amend its label and add < 200 postfix to it.
You can view total number of samplers with response time below 200 ms and 90% percentile using "normal" Aggregate Report listener
You can use "Duration Assertion". It will fail all the requests which take more than the expected time and with the "View Result Tree" or "Simple Data writer" listener you can get all the required data and count from the csv/jtl file generated by them.
Hope this help.
Unless you will need absolute numbers, I would recommend the Response Times Percentiles listener (https://jmeter-plugins.org/wiki/RespTimePercentiles/)
This listener will paint a graph of response times and this will clearly show in percentiles below any response time within the range
I am running a load testing with Jmeter and python Requests package, but get different result when I try to access the same website.
target website: http://www.somewebsite.com/
request times: 100
avg response time for Jmeter: 1965ms
avg response time for python Requests: 4076ms
I have checked response html content of jmeter and python Requests are the same. So it means they all got the correct response from website. but not sure why it has 2 times difference with each other. Is there anyone know is there any deep reason for that?
the python Requests sample code:
repeat_time = 100
url = 'http://www.somewebsite.com/'
base_time = datetime.datetime.now()
time_cost = base_time
for i in range(repeat_time):
start_time = datetime.datetime.now()
r = requests.get(url, headers=headers)
end_time = datetime.datetime.now()
print str(r.status_code) + ';time cost: %s' % (end_time - start_time)
time_cost += (end_time - start_time)
print 'total time: %s' % (time_cost - base_time)
print 'average time: %s' % ((time_cost - base_time).total_seconds() / repeat_time)
Without your JMeter code, I can't tell you what the difference is, but let me give you an idea of what's happening in that one call to requests:
We create a Session object, plus the urllib3 connection pools we use
We do a DNS look-up for 'www.somewebsite.com' which shouldn't be too negatively affecting this request
We open a socket for 'www.somewebsite.com:80'
We send the request
We receive the first byte of the response
We determine if the user wanted to stream the body of the response, if not we read all of it and cache it locally.
Keep in mind that the three most intensive parts (usually) are:
DNS lookup (for various reasons, but as I already said, it shouldn't be a problem here)
Socket creation (this is always an expensive operation)
Reading the entirety of the body and caching it locally.
That said, each response object should have an attribute, elapsed which will give you the time to the first byte of the response body. In other words, it will measure the time between when the request is actually sent and when the end of the headers is found.
That might give you far more accurate information than what you're measuring now, which is the time to the last byte of the message.
That said, keep in mind that what you're doing in that for-loop is also invoking the garbage collector a lot:
Create Session, it's adapters, the adapters connection pools, etc.
Create socket
Discard socket
Discard Session
Goto 1
If you create a session once, your script will perform better in general.
No Of Requests - 2113 ;
Average Response time (s) - 123.5 ;
Response time/Sec (90% of Requests) - 142.9
Minimum Response time (s) - 2.4
Maximum response time (s) - 14.9
Error% -0.0
My Questions - For 2113 requests average response time is 123.5 secs I need to know what will be the response time of average one single request in 2113 requests
The average response time of a single request (1 out of 2,113) will be the value itself, but I'm sure this isn't your question.
Are you simply trying to locate the response time of each request after a given test plan has fully executed, that is, to see each of the 2,113 response times? If so, just add a Summary Report to your thread group. By doing this you'll need to specify an output file (which will get generated if it doesn't already exist) and will show you in detail each of the requests sent to the server, along with the HTTP response code, response time and other goodies.
UPDATE
Per the question posed in the comments via Ripon Al Wasim, the default extension of the results file is CSV, however this is configurable in /bin/jmeter.properties:
# legitimate values: xml, csv, db. Only xml and csv are currently supported.
#jmeter.save.saveservice.output_format=csv
As we can see, JMeter only appears to support XML and CSV.