-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New thread_sensitive=True default effectively makes Channels single-threaded #218
Comments
This is an unfortunate side-effect of the change, but it is deliberate - we were seeing a lot of subtle bugs caused by the multi-threaded nature of things that didn't have Channels is particularly hard-hit because of the way it works, but what's needed there is a Channels setting to decide how to run Django code; it's not something we can really fix on the |
Thanks for the response. Just to check my understanding - considering only a normal Django app with no explicit use of async functionality, would serving under channels with My instinct would be that without any async views or use of the async decorators, the risk is the same - when run in asgiref's threadpool the entire request/response cycle will happen on the same thread, so anything that worked in e.g. uWSGI should work there too. But I haven't dug too deep here. Could changing Channels to decorate |
I think Channels would mostly be safe as there's nothing synchronous on the main thread to lock to, but I'd have to go back into the codebase to be sure, and it's been a loooong time since I actively developed in there. |
Hi all,
We're running Django 1.11 but this applies at least up to 2.2.
We didn't have asgiref pinned, and so at some point it was updated to 3.3. We found that a bunch of requests were timing out and we tracked it down to the changed default of thread_sensitive to True in SyncToAsync.
Since Django views are run inside this decorator, all Django code is treated as thread sensitive, which means none of it is run on the asgiref threadpool. ASGI_THREADS has no effect. In addition to reducing concurrency to zero, this introduces a lot of latency if you have any long-running requests. The uvicorn worker accepts connections as fast as it receives them, so one slow request in a worker will cause a backlog of unhandled async tasks inside that worker, even if other worker processes are doing nothing.
I'm not sure what the answer is here, just wanted to raise the issue. From what I can see it looks as though the change was made to accommodate things in Django 3. We've fixed the issue by pinning the older version of asgiref. Perhaps there could be a new point release of Channels 2.4 that requires asgiref<3.3?
The text was updated successfully, but these errors were encountered: