Saturday, April 15, 2023

Async views means dropping gunicorn gevent for uvicorn, affecting sync view performance

Hello

Production django app, currently 100% sync views, running under gunicorn with gevent worker class.

@andrewgodwin suggests here it is possible to migrate slowly, just run hybrid sync-async and add or convert views as desired
https://www.youtube.com/watch?v=19Uh_PA_8Rc&t=1728s

But to get a single async view one has to switch to uvicorn workers or similar, right? Now one is no longer getting the gevent patching for sync views, which could be a major impact on performance/scaling, and could trigger re-evaluation of the production deployment & tuning!

Questions:

1. How to approach this? It has me wondering if monkey.patch_all() should be ported to asyncio and tested under uvicorn. This would smooth the transition since the sync views should perform and scale roughly the same as before.

2. Also an important technical question on how sync views under ASGI work. By default they will run all in the same thread (per worker) which could be really bad for performance with tons of sync views, correct? If I enable DJANGO_ALLOW_ASYNC_UNSAFE, then the sync views will be run in more threads, right? How many threads?Should I expect to have to tune this?

In general, regardless of the approach, one could presumably A/B test in a live environment - run some workers / nodes under uvicorn, partition the traffic accordingly, and see how it compares. Tune, stress test, and then rolling transition.

-C

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8cc88d44-df9f-4232-8f57-89a1b07fb769n%40googlegroups.com.

No comments:

Post a Comment