mirror of
https://github.com/django/daphne.git
synced 2025-06-07 06:33:18 +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):
|
def receive_many(self, channels):
|
||||||
if not channels:
|
if not channels:
|
||||||
raise ValueError("Cannot receive on empty channel list!")
|
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
|
# Get a message from one of our channels
|
||||||
while True:
|
while True:
|
||||||
result = self.connection.blpop([self.prefix + channel for channel in channels], timeout=1)
|
result = self.connection.blpop([self.prefix + channel for channel in channels], timeout=1)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user