我在 RabbitMQ 之上运行 Django 和 Celery 作为队列来处理一些数据处理任务。当用户首次注册时,我会启动 celery 任务,并定期更新他们的数据。但是,我当然想优先处理当前在线用户运行的任务。我注意到celery中的任务有一个优先级设置,但rabbitmq似乎不支持这个。此帖子http: //groups.google.com/group/celery-users/browse_thread/thread/ac3b6123d63421e5/b7740def1389e87e?lnk=gst&q=priority#b7740def1389e87e 建议有两个不同的队列,一个高优先级队列和一个低优先级队列,或为较低优先级任务设置速率限制。
有人有一个好的解决方法来实现优先级吗?提前致谢!
I am running Django with Celery on top of RabbitMQ as a queue to handle some data processing tasks. I am kicking off celery tasks when a user first signs up, as well as periodically to update their data. However, I'd like to of course give priority to the tasks running users who are currently online. I noticed there was a priority setting for tasks in celery, but it seems that rabbitmq does not support this. This thread http://groups.google.com/group/celery-users/browse_thread/thread/ac3b6123d63421e5/b7740def1389e87e?lnk=gst&q=priority#b7740def1389e87e suggests have two different queues, a high priority one and a low priority one, or setting a rate limit for lower priority tasks.
Does anyone have a good workaround to implement priority? Thanks in advance!
发布评论
评论(2)
据我了解,我还没有这样做,Ask 在这里介绍了这一点:
http://docs.celeryproject.org/en/master/faq.html#does-celery-support-task-priorities [稳定]
http://docs.celeryproject.org/en /latest/faq.html#does-celery-support-task-priorities [最新]
As I understand it, and I've not yet done this, Ask covers this here:
http://docs.celeryproject.org/en/master/faq.html#does-celery-support-task-priorities [stable]
http://docs.celeryproject.org/en/latest/faq.html#does-celery-support-task-priorities [latest]
除此之外,您还可以将紧急任务推送到某个队列(例如紧急队列)并设置消费者优先级,即让所有消费者从紧急队列中获取高优先级的任务。
https://github.com/celery/celery/issues/3098
在消费者端,您可以在队列中定义 x-priority 参数来消费。在下面的示例中,消费者从优先级为 0 的 celery 队列和优先级为 10 的 hipri 中获取任务。
示例:
Apart from this, you can push urgent tasks to some queue (let's say urgent-queue) and set consumer priorities, i.e, let all consumers pick up task from urgent-queue with high priority.
https://github.com/celery/celery/issues/3098
At consumer end, you can define x-priority argument in queues to consume from. In the below example, consumer picks up tasks from celery queue with priority 0 and from hipri with priority 10.
Example: