Reputation: 1
When using the Apache Benchmark tool I noticed that the first request is not getting executed concurrently.
For example, when running: ab -n 4 -c 4 http://localhost:8080/block/10
I get the following results:
2024-01-17T13:40:28.398-05:00 INFO 61127 --- [sample-client] [nio-8080-exec-1] a.s.s.client.controller.HomeController : 200 OK on Thread[#56,http-nio-8080-exec-1,5,main]
2024-01-17T13:40:38.414-05:00 INFO 61127 --- [sample-client] [nio-8080-exec-3] a.s.s.client.controller.HomeController : 200 OK on Thread[#58,http-nio-8080-exec-3,5,main]
2024-01-17T13:40:38.414-05:00 INFO 61127 --- [sample-client] [nio-8080-exec-2] a.s.s.client.controller.HomeController : 200 OK on Thread[#57,http-nio-8080-exec-2,5,main]
2024-01-17T13:40:38.414-05:00 INFO 61127 --- [sample-client] [nio-8080-exec-4] a.s.s.client.controller.HomeController : 200 OK on Thread[#59,http-nio-8080-exec-4,5,main]
The first request is executed at 13:40:28 and runs by itself. After it returns the remaining 3 requests are in parallel. All 4 requests run on different threads, but not at the same time.
I don't think it is a problem with my laptop not being able to handle 4 threads concurrently. If I change the parameters to -n 3 -c 3
I get the same results. The first request is executed and then when it finishes the 2 remaining request are done in parallel.
The code I'm using is a Spring Boot application that makes a call to another Spring Boot application. I'm following along with a video by Spring Developer Advocate Dan Vega. Dan experiences the problem too, first seen around 16:15 in the video. He is expecting a time of 15 seconds but the result is 18 seconds. This off by 1 factor continues throughout all of his tests. Likely the cause in the video is the same I'm experiencing.
Any thoughts as to what is causing this or how to get around it? This is causing the benchmarks to be off.
Upvotes: 0
Views: 217
Reputation: 363
I stumbled across this myself today, but from a different context: I tested an endpoint that generated lists of random numbers with a random amount of random numbers, and wondered why so many of my requests were failing, for example:
Complete requests: 4
Failed requests: 3
(Connect: 0, Receive: 0, Length: 3, Exceptions: 0)
As you can see: The reason for the failed requests is Length: The endpoint returned content with different lengths -- which makes sense given the nature of my endpoint.
This is easily fixed by using the -l
parameter:
-l Accept variable document length (use this for dynamic pages)
Why do I mention this?
ApacheBench seems to make the first request separately, probably partially to determine the content length. There seems to be nothing in the docs that I can cite, except for this:
Output: Document Length: This is the size in bytes of the first successfully returned document. If the document length changes during testing, the response is considered an error.
(source: https://httpd.apache.org/docs/2.4/programs/ab.html)
I hope this is still helpful, despite me being unable to find proper citations for this. I couldn't find anything on the mailing lists either. But knowing this would have saved me an hour of debugging today.
One additional positive effect this has for me in my tests: The first request effectively serves as a warm-up request (my ML-models are loaded into memory). So while I was annoyed at the first request behaving differently at first: Now I kind of like it.
Upvotes: 1