beta9 icon indicating copy to clipboard operation
beta9 copied to clipboard

Feat: Allow concurrent requests to ASGI apps

Open dleviminzi opened this issue 1 year ago • 0 comments

Resolve BE-1919

Previously running the following two curls in order would result in the second request taking 10 seconds because it waits until the first request is handled. With this change, a user can now specify concurrent_requests for their asgi application. In the example below, setting this to 2 allows the app to receive and process the second request while the first is still sleeping

# first
curl -X POST 'http://localhost:1994/asgi/asgi-test-app/latest/sleep-with-body' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <token>' \
-d '{"seconds": 10, "nums": [1, 2, 3]}'
# second
curl -X POST 'http://localhost:1994/asgi/asgi-test-app/latest/sleep-with-body' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <token>' \
-d '{"seconds": 0, "nums": [1, 2, 3]}'

Endpoint being called above

    @myapp.post("/sleep-with-body")
    async def sleep_with_body(body: dict = Body(...)):
        await asyncio.sleep(body["seconds"])
        return {"message": f"Slept for {body['seconds']} seconds", "nums": body["nums"]}

dleviminzi avatar Oct 11 '24 18:10 dleviminzi