Assume that there is a Django project where everything is designed to accommodate WSGI. So, response times are as fast as they can get so that worker threads are not kept busy. To simplify things, you can even assume that only static HTML pages are served. (I know ASGI should help a lot when there is I/O stuff but I’m more interested in how requests are handled)
Now, let’s assume in this case I want to switch ASGI.
I know that unlike WSGI threads, ASGI threads can work on multiple requests. Thanks to this, you have access to some functionality such as efficient streaming with StreamingHttpResponse
(without blocking the entire thread). This also means that overall, you’ll have better throughput since more threads will be available to process requests.
All of these are good and all for async views, but what happens when you have only sync views? Can ASGI still handle multiple requests in one thread? And how does it know which request is blocking?
In my mind -might be wrong here-, switching to ASGI in a sync project should come with near zero-overhead if not making the throughput any better. I know there is a context-switch penalty due to sync views but that should be very minimal right?
I made some naive tests using hey where I sent requests to a static page (using gunicorn with uvicorn and sync workers). And for some reason, sync workers were better at handling requests (i.e., the request times were faster and throughput was better). Did I do something wrong?
So…
Should I switch to ASGI? Is it feasible for sync applications to use ASGI? How do I properly test which one is better for my application?