-
Notifications
You must be signed in to change notification settings - Fork 80
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
Task queue metrics helper methods #108
base: master
Are you sure you want to change the base?
Conversation
@thomasst ready for code review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! See comment.
README.rst
Outdated
keyword argument, which accepts an integer indicating how many executions | ||
should be loaded. | ||
To get a count of the number of tasks for a given queue and state, use | ||
``Task.count_tasks_from_queue``. To get a list of all tasks for a given queue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually called task_count_from_queue
in the code.
Also, another approach would be to let you pass 0 into tasks_from_queue
(currently it's undefined). That way we wouldn't need to add a new function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tasks_from_queue
uses mget
and then loops over all the returned tasks. It's much faster to use zcount
to only get the count of tasks from redis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the readme with 843e016.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant that passing limit=0
should make it just return the count and an empty list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, got it. I prefer methods to not change behavior. Would you be ok with leaving them separate methods?
Should we leave the methods separate? |
Ready for re-review 😄 |
Anything else needed for this PR? |
Bringing this PR to attention again. It should be ready to merge pending the comment above. |
Thanks! It's on my list to review. |
Let me know if I can do anything to help with your review! 😄 |
Happy Friday! The best day for merging PRs 😉 |
prefix = tiger.config['REDIS_PREFIX'] + ':' | ||
|
||
for state in metrics.keys(): | ||
queues = tiger.connection.smembers(prefix + state) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use tiger._key(state)
.
queues = tiger.connection.smembers(prefix + state) | ||
for queue in queues: | ||
metrics[state][queue] = { | ||
'total': self.task_count_from_queue(tiger, queue, state), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use a pipeline to avoid round trips.
""" | ||
|
||
key = tiger._key(state, queue) | ||
count = tiger.connection.zcount(key, '-inf', '+inf') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zcard()
does the same.
def task_count_from_queue(self, tiger, queue, state): | ||
""" | ||
Returns the number of tasks in a given queue and task state. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation details aside, I'm still unsure on whether this could be solved by just using tasks_from_queue(limit=0)[0]
. I'm aware that currently passing a 0 limit to tasks_from_queue
returns all the tasks but this behavior is not documented, and a more Pythonic way would be to say limit=None
if we actually wanted all the tasks. We should at least define how tasks_from_queue
should behave before we decide to add a new function here. @jkemp101 curious if you have any thoughts on this?
Are these stats different compared to what get_queue_stats returns? I didn't compare the output of both functions. Our Prometheus exporter uses those stats with the following code for our metrics. It just summarizes some subqueues.
|
@jkemp101 I wasn't aware of the |
One thing I wish |
I can't think of an easy way to do this in Redis without some Lua scripting. And I kind of feel that computing stats should take second priority over the regular task processing so it makes sense to me to just offload this to Python code instead of putting any extra burden on Redis. |
Adds new helper classmethods:
Task.task_count_from_queue
Task.queue_metrics
Also fixed these pep8 linter rules:
Related to #107.