Testing an async endpoint with Yada
- Other endpoints remain responsive no matter how many request to async endpoints are being processed.
- Clone this repository
- In a terminal sesssion:
cd yada-async-test/edge
boot dev
and wait for a webserver to be started at port3010
- Visit The Swagger UI in a browser. There you'll see two endpoints,
async
andhello
. - In another terminal session:
cd yada-async-test/external
. lein repl
(dev)
(go)
and wait for a webserver to be started at port3000
. This service has one endpoint calledexample
which will wait 5 seconds before it returns a response.
Now for the test:
-
In another browser tab, visit
http://localhost:3010/api/hello
while having a Network tab open in devtools so you can see the response time. On my machine this was about6ms
. Click preserve log, so you can compare requests when you hit refresh. -
In the The Swagger UI fire 20 request. Meanwhile, refresh the tab with the call to
api/hello
a couple of times and notice how it becomes less responsive. On my machine it sometimes takes a couple of seconds before a request comes back. This is different from my expectation:
ab -n 20 -c 20 -v 10 -H 'Accept: application/json' 'http://localhost:3010/api/async'
ab -n 20 -c 20 -v 999 -H 'Accept: text/plain' 'http://localhost:3010/api/hello'
The problem was that there is a maximum number of concurrent requests to the same domain in browsers. Use a different tool like Apache Bench. Thanks to thegeez for pointing me to the solution.