Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inefficiency in RedisStorage.get_next_message() #35

Open
mkrysiak opened this issue Jan 7, 2018 · 0 comments
Open

Inefficiency in RedisStorage.get_next_message() #35

mkrysiak opened this issue Jan 7, 2018 · 0 comments

Comments

@mkrysiak
Copy link

mkrysiak commented Jan 7, 2018

cyclops/cyclops/storage.py

Lines 95 to 103 in 9136a4f

def get_next_message(self):
projects = list(self.redis.smembers(self.projects_key))
if not projects:
return None
project_id = random.choice(projects)
msg = self.redis.rpop(self.get_queue_key(project_id))
if not msg:
return None

get_next_message() uses redis.smembers() to get a list of all project_id's, and project_ids are added to the set in put(), but project_id's are never removed from the set if there are no request in the project_id's queue. So get_next_message() may be calling redis.rpop() on a key that no longer exists.

Another option may be to use redis.scan() for keys that match "cyclops:queue:*", and randomly select from that list for the next message. This would guarantee that redis.rpop() is called on a queue that contains at least one message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant