Task queue metrics helper methods#108
Task queue metrics helper methods#108alanhamlett wants to merge 6 commits intocloseio:masterfrom alanhamlett:task_count_from_queue
Conversation
|
@thomasst ready for code review. |
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.
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.
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.
I meant that passing limit=0 should make it just return the count and an empty list.
There was a problem hiding this comment.
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) |
| 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.
This should use a pipeline to avoid round trips.
| """ | ||
|
|
||
| key = tiger._key(state, queue) | ||
| count = tiger.connection.zcount(key, '-inf', '+inf') |
| 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.
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_queueTask.queue_metricsAlso fixed these pep8 linter rules:
Related to #107.