我正在尝试替换一个小型的国产消息系统,并且正在使用 zmq 。
我需要检测缓慢的读取器,并启动/断开它们 - 缓慢的读取器几乎意味着队列大小高于特定阈值的特定消费者。
到目前为止,如果其中一个消费者有点慢(很公平),zmq 似乎会阻止每个消费者 - 但是
我找不到任何方法来检测潜在的慢速消费者。任何人有任何经验
zmq 是否以及如何实现这一点 - 或者是否有任何其他无代理消息传递系统值得推荐?
I'm trying to replace a small homegrown messaging system, and are playing around a bit with zmq .
I'll be needing to detect slow readers, and boot/disconnect them - slow readers pretty much meaning a particular consumer whos queue size is above a certain threshold.
So far it seems zmq blocks every consumer if one of them is a bit slow (fair enough) - but
I can't find any way to detect a potential slow consumer. Anyone have any experience with
wether and how this is possible with zmq - or have any other broker-less messaging system to recccommend ?
发布评论
评论(2)
从 Zeromq-2.0.7 开始,您可以在
ZMQ_PUB
套接字上设置ZMQ_HWM
选项来控制订阅者可以排队的最大消息数。一旦达到高水位线,发往该订阅者的所有其他消息都将被丢弃,直到队列大小回落到高水位线以下。这限制了专用于所谓的慢速读取器的内存量。但是,由于 ZeroMQ 库公开套接字而不是客户端,因此您无法在不修改库本身的情况下识别并强制断开不需要的客户端。
As of zeromq-2.0.7, you can set the
ZMQ_HWM
option on aZMQ_PUB
socket to control the maximum number of messages that can be queued for a subscriber. Once the high-water mark has been reached, all further messages destined for that subscriber will be dropped until the queue size drops back below the high-water mark. This limits the amount of memory dedicated to what you call a slow reader.However, because the ZeroMQ library exposes sockets, not clients, there is no way for you to identify and forcibly disconnect unwanted clients without modifying the library itself.
ZeroMq 指南中有一节与此相关,它建议实现一种名为“自杀蜗牛模式”。
基本上,它扭转了依赖性,并试图通过为缓慢的订阅者提供一种检测他们是否已成为缓慢阅读者的方法来说服他们断开连接/自杀。
There is a section in the ZeroMq Guide regarding this, it suggests implementing a pattern the call the "Suicidal Snail Pattern".
Basically, it reverses the dependency and tries to convince slow subscribers to disconnect/kill themselves by giving them a way to detect if they have become slow readers.