简体   繁体   English

使用共享优先级队列进行负载均衡

[英]Load balancing with shared priority queues

I am trying to implement a load balancer at the moment and have hit a bit of a speed bump. 我正在尝试实现负载平衡器,并且已经达到了一点速度。 The situation is as follows (simplified), 情况如下(简化),

  • I have a queue of requests queue_a which are processed by worker_a 我有一个请求queue_a队列,由worker_a处理
  • There is a second queue of requests queue_b which are processed by worker_b 请求queue_b的第二个队列由worker_b处理
  • And I have a third queue of requests queue_c that can go to either of the workers 我有queue_c的请求的3队列可到该工人

The reason for this kind of setup is that each worker has unique requests that only it can process, but there are also general requests that anyone can process. 这种设置的原因是每个工作者都有唯一的请求,只有它可以处理,但也有任何人可以处理的一般请求。

I was going to implement this basically using 3 instances of the C5 IntervalHeap. 我基本上使用C5 IntervalHeap的3个实例来实现它。 Each worker would have access to its local queue + the shared queues that it is a part of (eg, worker_a could see queue_a & queue_c). 每个工作者都可以访问其本地队列+它所属的共享队列(例如,worker_a可以看到queue_a和queue_c)。

The problem with this idea is that if there is a request in the local queue and a request in the shared queue(s) with the same priority, it's impossible to know which one should be processed first (the IntervalHeap is normally first-come-first-serve when this happens). 这个想法的问题是,如果本地队列中有请求,并且共享队列中的请求具有相同的优先级,则不可能知道应该首先处理哪一个(IntervalHeap通常是先来的 - 发生这种情况时的首发服务)。

EDIT: I have discovered IntervalHeap appears to not be first-come-first-server with same priority requests! 编辑:我发现IntervalHeap似乎不是具有相同优先级请求的先来先服务器!

I would like to minimise locking across the queues as it will be relatively high throughput and time sensitive, but the only way I can think of at the moment would involve a lot more complexity where the third queue is removed and shared requests are placed into both queue_a and queue_b. 我希望最小化队列中的锁定,因为它将具有相对较高的吞吐量和时间敏感性,但是我现在能够想到的唯一方法将涉及更多的复杂性,其中第三个队列被移除并且共享请求被置于两者中queue_a和queue_b。 When the request is sucked up it would know it is a shared request and have to remove it from the other queues. 当请求被提升时,它会知道它是一个共享请求,并且必须将其从其他队列中删除。

Hope that explains it clearly enough! 希望能够清楚地解释清楚!

It seems that you'll simply end up pushing the bubble around - no matter how you arrange it, in the worst case you'll have three things of equal priority to execute by only two workers. 看起来你只是最终推动泡沫 - 无论你如何安排它,在最坏的情况下,你将有三个同样优先的事情,只有两个工人执行。 What sort of tie breaking criteria could you apply beyond priority in order to choose which queue to pull the next task from? 您可以优先应用哪种打破平局标准,以便选择从哪个队列中提取下一个任务?

Here are two ideas: 这有两个想法:

  1. Pick the queue at random. 随机选择队列。 All priorities are equal so it shouldn't matter which one is chosen. 所有优先事项都是平等的,因此选择哪一个并不重要。 On average in the worst case, all queues will be serviced at roughly the same rate. 在最坏的情况下,平均而言,所有队列将以大致相同的速率进行服务。

  2. Minimize queue length by taking from the queue that has the largest number of elements. 通过从具有最大元素数量的队列中获取最小化队列长度。 This might cause some starvation of other queues if one queue's fill rate is consistently higher than others. 如果一个队列的填充率始终高于其他队列,这可能会导致其他队列的一些饥饿。

HTH HTH

Synchronizing your workers can share the same pool of resources as well as their private queue. 同步您的工作人员可以共享相同的资源池以及其专用队列。 Of there is 1 item available in the queue for worker 1 and 1 item available in the shared queue, it would be a shame if worker 1 picks up the item of the shared queue first since this will limit parallel runs. 在工作组1的队列中有1个可用项,在共享队列中有1项可用,如果工作者1首先获取共享队列的项,那将是一种耻辱,因为这将限制并行运行。 Rather you want worker 1 to pick up the private item first, this however leads to new caveats, one being where worker 1 and worker 2 are both busy handling private items and therefore older shared items will not be picked up. 相反,您希望工作人员1首先获取私人物品,但这会产生新的警告,其中一个是工人1和工人2都忙于处理私人物品,因此旧的共享物品将不会被拾取。

Finding a solution that addresses these problems will be very difficult when also trying to keep the complexity down. 在尝试降低复杂性时,找到解决这些问题的解决方案将非常困难。 A simple implementation is only to handle shared items when the private queue is empty. 一个简单的实现只是在私有队列为空时处理共享项。 This does not tackle the part where priorities are not handled correctly on high load scenario's. 这并不能解决在高负载情况下未正确处理优先级的部分。 (eg where the shared queue wont be handled since the private queues are always full). (例如,由于私有队列总是满的,因此不会处理共享队列)。 To balance this, you might want to handle the private queue first, only if the other workers private queue is empty. 为了平衡这一点,您可能希望首先处理专用队列,仅当其他工作者专用队列为空时。 This is still not a perfect solution since this will still prefer private queue items over shared items. 这仍然不是一个完美的解决方案,因为这仍然会优先于共享项目的私有队列项目。 Addressing this problem again can be achieved by setting up multiple strategies but here comes even more complexity. 再次解决这个问题可以通过设置多个策略来实现,但这里的复杂性更高。

It all depends on your requirements. 这一切都取决于您的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM