Django + Gunicorn with gevent workers, with asyncio in the views

Viewed 734

I have a django project, served by Gunicorn with gevent workers.

In some views, I have to make two long running external calls. These are IO-bound

class FooView(View):
    def post(self, request):
        slow_call_one()
        slow_call_two()
        do_some_work
        return HttpResponse(...)

There is no reason for which these two slow calls cannot run concurrently. Would there be any issue with running these as asyncio co-routines? I'm asking mainly regarding the interplay between asyncio and the gevent gunicorn workers.

My naïve understanding, based on the research that I've done is:

  • Making these calls into asyncio coroutines would allow single requests to finish more quickly, by not sitting and waiting for IO bound tasks
  • gunicorn + gevent workers allow multiple requests to run 'concurrently' (I am aware that it's not true concurrency).

My concerns are that gevent might already be transparently swapping to process a different request during the IO bound calls made by the original request, and that this might, at worst, screw up the process, or at best, not actually result in a performance improvement.

0 Answers
Related