#37156: Properly implement async Redis methods
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Core (Cache system) | Version: 6.0
Severity: Normal | Resolution:
Keywords: redis, asyncio, | Triage Stage:
async | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mykhailo Havelia):
Hey. Happy to help get rid of the `async_to_sync` stuff in Django 😁 I'll
leave a few thoughts below, hope they help.
To get a real async implementation, we basically just need to implement
`AsyncRedisClient`. Django already depends on redis, which ships an async
client. But there's a catch. 😁
The async redis client relies on event-loop-bound connections, which means
the code won't work under WSGI. Django supports running async code under
WSGI, and core devs won't want to drop that. So the options are:
- Open and close a connection for each command. Works everywhere, but
kills performance.
- Implement a separate `AsyncRedisCache` so people on ASGI can opt into
it. Avoids breaking changes, but core devs don't like adding a new class
for this.
- Use a third-party library like https://github.com/Andrew-Chen-Wang
/django-async-redis, without official Django support.
> As discussed before, the extra threading comes with a significant
overhead
I looked into the async_to_sync performance degradation, and it looks like
creating threads doesn't cause significant degradation on its own. what
matters more is how frequently you hit it during the request cycle. If
you're seeing something like that, could you share your setup (RPS,
sync_to_async calls per request, avg CPU per pod)? That'd be helpful.
--
Ticket URL: <https://code.djangoproject.com/ticket/37156#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019eb25abe01-3c7c6012-5137-4c8e-be82-7fc3354d1eca-000000%40eu-central-1.amazonses.com.