如何防止ActiveMQ优先级队列上的低优先级消息饥饿?
我正在开发一个需要实现优先队列的系统。我们有不同优先级的消息,我们需要根据优先级处理消息。现在,出于多种原因,我们希望使用 ActiveMQ 作为我们的队列技术,其中之一是支持优先级队列。
对于 ActiveMQ 中的优先级队列,处理饥饿问题的最佳方法是什么?具体来说,我们需要确保即使较高优先级的消息继续充斥队列,低优先级的消息最终也能得到处理。 ActiveMQ 有内置的东西吗?或者我们是否需要构建自己的东西来随着消息的老化而提高优先级?
I am working on a system where we need to implement a prioritized queue. We have messages with different priorities and we need to process messages based on priority. Right now, we are looking to use ActiveMQ as our queuing technology for many reasons, one of which is that is supports priority queues.
With a priority queue in ActiveMQ, what is the best way of dealing with starvation? To be specific, we need to ensure that even a low priority message eventually gets processed even if higher priority messages continue to flood the queue. Does ActiveMQ have something built-in? Or do we need to build something of our own to increase the priority as the message ages?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
做到这一点的基本方法是当消息变旧时提高优先级,
这样,一小时前的低优先级消息的优先级高于
评论中指出的新的高优先级消息,但是来自低优先级消息的洪水几个小时前将暂时缺乏新的高优先级消息,并且将这些消息正确地隔开将需要更复杂的方法,
另一种方法是使用多个队列,每个优先级一个,并从低优先级队列中取出多个队列。优先级队列
最后一种方法仅适用于少量情况优先级,而我提供的第一个方法可以处理任意数量的优先级
a basic way to do this is to bump up the priority when the message gets older
this way a low priority message from say an hour ago is higher priority then a new high priority message
as noted in the comments however a flood from low prio messages from several hours ago will temporarily starve the new high prio messages and to space those properly out will require a more sophisticated method
another method is using multiple queues, one for each priority and taking several out of the higher priority queue for each taken out of the low priority queue
this last method is only really viable for a low amount of priorities while the first method I provided can handle an arbitrary amount of priorities