mirror of
https://github.com/django/daphne.git
synced 2025-04-21 17:22:03 +03:00
Shuffle fetch order for channels to prevent starvation
This commit is contained in:
parent
aaf2321db1
commit
b9f07475b7
|
@ -56,6 +56,8 @@ class RedisChannelBackend(BaseChannelBackend):
|
|||
def receive_many(self, channels):
|
||||
if not channels:
|
||||
raise ValueError("Cannot receive on empty channel list!")
|
||||
# Shuffle channels to avoid the first ones starving others of workers
|
||||
random.shuffle(channels)
|
||||
# Get a message from one of our channels
|
||||
while True:
|
||||
result = self.connection.blpop([self.prefix + channel for channel in channels], timeout=1)
|
||||
|
|
Loading…
Reference in New Issue
Block a user