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

Queue length is wrong when using Redis and task priorities #272

Open
ArchFrosty opened this issue Oct 19, 2023 · 3 comments
Open

Queue length is wrong when using Redis and task priorities #272

ArchFrosty opened this issue Oct 19, 2023 · 3 comments

Comments

@ArchFrosty
Copy link

tldr; only the priority 0 queue is counted

This one is fairly simple:
when you get active queues here

queues = self.app.control.inspect().active_queues() or {}

Celery will indeed return you the active queues from its point of view - for example the default queue 'celery'. The problem is that when using Redis, priority is implemented by actually crating multiple queues in Redis.
By default it creates 3 additional queues: 'celery\x06\x163' 'celery\x06\x166' 'celery\x06\x169' - queues 3 6 and 9 with '\x06\x16' as separator between name and priority number. Priority numbers used when submitting tasks are then mapped to these queues (0 highest prio and 9 lowest), the highest priority queue (with priority value 0) is just called its name, in this case 'celery' without separator and number

So then when you eventually call

length = queue_length(transport, connection, queue)

and eventually call llen
def redis_queue_length(connection, queue: str) -> int:
return connection.default_channel.client.llen(queue)

on the name of this queue, you only get the tasks in the priority 0 queue.

Also the separator and then number of queues is configurable.
https://docs.celeryq.dev/en/stable/userguide/routing.html#redis-message-priorities

@danihodovic
Copy link
Owner

#204 (comment)

tl;dr I don't think I will add queue length for Redis.

@zdenekbauer
Copy link

Hi, we have the same problem. I saw that there was already prepared pull-request for that, can you please consider it again? It would be amazing to have this feature.

@danihodovic
Copy link
Owner

@zdenekbauer I will not be adding it for now. Feel free to fork the repo.

See #204 (comment)

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

3 participants