-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Hi there! I started using this for a new project I'm working on and it perfectly suits my needs.
One thing I'm concerned about over time is that all events are broadcast over the same channel (subscriptions?). For the purposes of my app, which implements a chat-like interface over a single Message model, this would—to my understanding—require every message to be received and filtered by every instance of the application. That is, if there are 1000 users sending 10 messages per minute across 5 servers, each server would need to receive and process 10,000 events per minute (166 per second). Ideally, if each user is connected to one server via a websocket, and the recipient is connected to another server via a websocket, each server is only processing 4000 events per minute (1000 users spread over 5 servers == 200 users/server, with each user sending/receiving 20 messages == 4,000 per minute or ~66/second). Adding servers in this case would significantly decrease the number of events per server per minute.
I guess my first question is, have you considered anything to work around this? My initial thought is to create factories that return the equivalent of post_save_subscription or post_delete_subscription. So instead of
post_save.connect(post_save_subscription, sender=Message, dispatch_uid="message_post_save")
post_delete.connect(post_delete_subscription, sender=Message, dispatch_uid="message_post_delete")you might write
def channel_map(event):
return f'chat_room::{event.instance.room.id}'
post_save_subscription, post_delete_subscription = \
get_signal_handlers(mapper=channel_map)
post_save.connect(post_save_subscription, sender=Message, dispatch_uid="message_post_save")
post_delete.connect(post_delete_subscription, sender=Message, dispatch_uid="message_post_delete")However, it's unclear how one might group_add in the consumer when a client subscribes. I don't know much about the internals of the underlying graphql library (yet), so it's tough for me to imagine how it would be possible to, for instance, call root.join_channel(f'chat_room::{room_id}').filter(...).
Long story short, I'd be interested in contributing towards this if there was an obvious way to expose some notion of channels in the existing interface. I'd love to hear your thoughts on how this could be accomplished and whether you'd accept PRs for an implementation.