ZeroMQ 缓冲区大小 v/s 高水位线

ZeroMQ buffer size v/s High Water Mark

zeromq socket options 中,我们有高水位线和缓冲区大小的标志。

对于发送,它是ZMQ_SNDHWMZMQ_SNDBUF

谁能解释一下这两者的区别?

每个人都控制着一些其他的东西:

ZMQ_SNDBUF: Set kernel transmit buffer size

The ZMQ_SNDBUF option shall set the underlying kernel transmit buffer size for the socket to the specified size in bytes. A ( default ) value of -1 means leave the OS default unchanged.

where man 7 socket says: ( credits go to @Matthew Slatery )

[...]

SO_SNDBUF
          Sets or gets the maximum socket send buffer in bytes.  The  ker-
          nel doubles this value (to allow space for bookkeeping overhead)
          when it is set using setsockopt(), and  this  doubled  value  is
          returned  by  getsockopt().   The  default  value  is set by the
          wmem_default sysctl and the maximum allowed value is set by  the
          wmem_max sysctl.  The minimum (doubled) value for this option is
          2048.
[...]

NOTES
   Linux assumes that half of the send/receive buffer is used for internal
   kernel structures; thus the sysctls are twice what can be  observed  on
   the wire.
[...]

ZMQ_SNDHWM: Set high water mark for outbound messages

The ZMQ_SNDHWM option shall set the high water mark for outbound messages on the specified socket. The high water mark is a hard limit on the maximum number of outstanding messages ØMQ shall queue in memory for any single peer that the specified socket is communicating with. A ( non-default ) value of zero means no limit.

If this limit has been reached the socket shall enter an exceptional state and depending on the socket type, ØMQ shall take appropriate action such as blocking or dropping sent messages. Refer to the individual socket descriptions in zmq_socket(3) for details on the exact action taken for each socket type.

ØMQ does not guarantee that the socket will accept as many as ZMQ_SNDHWM messages, and the actual limit may be as much as 60-70% lower depending on the flow of messages on the socket.


Verba 讲解员,Exempla trahunt:

具有基础设施设置,其中 zmq.PUB 方将所有设置保留为默认值,这样的发件人将有大约 20、200、2000 zmq.SUB abonents 监听发送者,很快就会耗尽默认的,未修改的 O/S 内核缓冲区 space,因为每个 .bind()/.connect() 关系(每个 abonent)将尝试 "stuff" 与数据的总和 ~ 1000 * aVarMessageSIZE [Bytes] 一样多,一旦被以 .send( ..., ZMQ_DONTWAIT ) 方式广播 & 如果 O/S 无法提供足够的缓冲区 space -- 我们开始了 --

"Houston, we have a problem..."

If the message cannot be queued on the socket, the zmq_send() function shall fail with errno set to EAGAIN.

Q.E.D.