question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Migration from wsgi to asgi questions

See original GitHub issue

We have a django app running on gunicorn with eventlet workers. But we are not satisfied with eventlet cause it monkeypatches everything and works badly with tooling. So we decided to move to asgi.

  • I replaced gunicorn eventlet worker with UvicornWorker
  • I replaced threading.local usage with asgi.Local
  • For cachetools we need to use threading.RLock because cachetools is not threadsafe

And after that, we ran a load test. Seems like with the asgi server we lost about 30% of performance.

So, questions are:

  • Are there any guides/docs where I can find how to tune asgi server? Anything about performance?
  • Are there any docs that describe how asgi works with django? I’m not sure but looks like there is main asyncio loop and for each request, asgi runs separate thread (and it looks like I must make async_to_sync functions that do network requests)
  • Is it safe/needed to use threading.RLock inside sync code or should I replace it with something?
  • Should I use asgi.Local(thread_critical=True) or asgi.Local() and how thread_critical works with different code?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
AlwxSincommented, Aug 5, 2020

@carltongibson I will go to the forum with some questions, thanks. But question about performance is suitable here as I think, it’s important.

1reaction
AlwxSincommented, May 28, 2021

@allen-munsch No, we returned to eventlet ¯_(ツ)_/¯

Read more comments on GitHub >

github_iconTop Results From Across the Web

Does anyone have experience migrating a large project from ...
I have a WSGI deployment with gunicorn and looking to switch to ASGI. I played around with a small django-channels project but I...
Read more >
Unable to run async functions after migrating from WSGI to ...
While implementing channels feature in DRF I migrated from WSGI to ASGI . So currently I have REST API and channels in same...
Read more >
How to deploy with ASGI - Django documentation
ASGI servers usually take the path to the application callable as a string; for most Django projects, this will look like myproject.asgi:application ....
Read more >
A Guide to ASGI in Django 3.0 and its Performance - Arunrocks
A blog by Arun Ravindran, author and speaker, about Python, Django and other curious things.
Read more >
ASGI Documentation
1.1 What's wrong with WSGI? You may ask “why not just upgrade WSGI”? This has been asked many times over the years, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found