0

我试图理解 Resque 的排序逻辑。我相信每个队列都是在 FIFO 基础上处理的(标准队列行为),但是说我有几个队列 - 都有待处理的作业 - 以及两个处理“*”的工作人员(即所有队列)。

什么算法决定接下来要处理哪个作业?如果它是一个通用 FIFO,它将是任何队列中最古老的作业,但在我看来,它就像是在进行某种队列轮换。

4

2 回答 2

2

https://github.com/resque/resque/blob/master/lib/resque/multi_queue.rb

如果它在阻塞模式下工作(默认情况下),那么它使用 Redis 的BLPOP方法,该方法接受队列列表,并将弹出并从第一个队列返回一个值以获取数据。

Redis 的 BLPOP 以先到先得的方式将客户端排入队列。当给定多个队列键时,它只是遍历它们并为每个键设置阻塞。见https://github.com/antirez/redis/blob/unstable/src/t_list.c#L781-815

Resque 将通过获取类似的内容来构建要测试的队列列表SMEMBERS queues,这意味着队列将按照 SMEMBERS 命令返回它们的顺序进行优先级排序。这是一个集合操作,这意味着它的顺序是未定义的;您主要受 Redis 的摆布。

于 2013-07-09T17:46:11.920 回答
1

也许你应该知道一点redis,因为resque内部用户[blpop][1]检查here

现在如何blpop工作,假设您有 2 个列表或队列king,并且queen

考虑以下场景

1) when one or more message exist in `king` and `queen` has no message i.e empty

  blop would pop a single message from `king` 

2) when `queen` has one or more message but `king` doesnt 

  blop would pop a message from `queen`

3) when but `king` or `queen` both has message in them. 

now the order of queues decide from which the message would be popped 

Let say `king` has 3 message and `queen` has 2 message 

and let say the order is 

redis.blpop "king","queen",0

blop would pop message from `king` 3 times(until it has no longer message in them) and then would pop the message from queue name "queen"

您可以参考list 和 blop 上的redis文档以获取更多信息

希望这是有道理的

于 2013-07-09T17:47:11.127 回答