hello, i’m seeing duration times from Response.timings.duration that are REALLY confusing. In the following script:
var date = new Date();
var startRequest = date.getMilliseconds();
const response = http.get(url, params);
var date = new Date();
var endRequest = date.getMilliseconds();
var totalTime = startRequest - endRequest;
console.info("Response times: calculated response time=" + totalTime + ", k6 response time=" + response.timings.duration)
Why is my totalTime so much lower than response.timings.duration? Maybe I’m not understanding response.timings.duration??? Can someone please help me? It’s very confusing!!!
getMilliseconds returns the milliseconds since the late second - what you will see if you print the date in some format and you print the milliseconds as well, not the milliseconds since 1970 which is probably what you wanted.
Additionally timings.duration will always be smaller then what you measure and especially for a single first request it will be even smaller as it doesn’t include the connection and dns lookup times as explained here
thanks, @mstoykov ! that was very helpful. but i’m still a little confused by http_req_duration. in the attached results summary, the number of http_reqs is 2.553453/s so that’s about 392 ms. but http_req_duration reports the following metrics, which are no where near 392.
When you execute the request in your bash script, presumably you are just calling the endpoint once, whereas in the k6 test, you’re calling it with multiple VUs (threads) concurrently (2.5/sec on average). Doing so could obviously increase the response time, particularly if the server is single-threaded.
If you want to see the equivalent to what your bash script is doing, you should just run the k6 script with a single VU.
thanks, @Tom. in my bash script, i’m executing 5 concurrent curls. so for a duration of 30s, i execute 5 concurrent requests with a 500ms sleep. i get the following:
total requests=85
requests per second=2.8333
Average response time in milli: 251.0470
in my k6 script, i have 5 VUs with a duration of 30s. 154 requests were submitted for 4.682934/s. 1000ms divided 4.68 is an average of 214ms. but the following response times are reported. why is the average more than double 214ms.
The iteration duration will include the .5 seconds spent sleeping (sleep(.5)), so that’s why iteration_duration averaged 1001.7ms yet the average response time was 499.90ms.
Not sure that particular division makes any sense anyway. The 4.68/s is the request rate. Why curl’s requests/sec is lower despite the lower average response time is odd. I’d need to see the curl command you’re running to try and figure that out.
The k6 output suggests that there is a rather lengthy delay for Time-To-First-Byte (TTFB), which is what http_req_waiting represents. With the options you’ve got, k6 will start all 5 VUs at the same time. Could your curl command be staggering when the requests are made? That might explain why we are reporting higher response times.
What do you see if you run just a single VU with k6, and likewise just a single thread with curl? I would expect the output to be very similar.
thanks, @Tom. I think I figured out the issue. the authentication request in the setup is included in http_req_duration. when i commented out the setup function and hardcoded the JWT in the headers, http_req_duration was closer to what i get in my bash script.