ZeroMQ 缓冲区大小与高水位线

标签 zeromq pyzmq

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.

<小时/>

语言讲解员,示例 trahunt:

拥有基础架构设置,其中 zmq.PUB 方将所有设置保留为默认值,这样的发件人将有大约 20、200、2000 zmq.SUB 如果不监听发送者,默认的、未修改的 O/S 内核缓冲区空间很快就会耗尽,就像每个 .bind()/.connect() 一样。 关系(每个 abonent )将尝试“填充”大约 ~ 1000 * aVarMessageSIZE [Bytes] 的总累积和。 的数据,曾经在 .send( ..., ZMQ_DONTWAIT ) 中广播过方式&如果操作系统无法提供足够的缓冲空间——我们就这样——

"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.

关于ZeroMQ 缓冲区大小与高水位线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43791198/

相关文章:

node.js - 从 zmq 套接字返回值

python - 通过 KeyboardInterrupt 停止 pyzmq 接收器

c++ - 如何使负载平衡代理更加完全异步?

sockets - 应用级心跳是否优于 TCP 保活?

swift - ZeroMQ:即使在 poller.poll( pollIn) 之后,使用 SwiftyZeroMQ .recv() 的 swift 代码仍然会阻止 GUI 文本更新

ZeroMQ REQ/REP服务器错误处理

python - 如何将zerorpc作为greenlet运行?

zeromq - 了解 ZeroMQ

python - Python zmq SUB 套接字未接收到 MQL5 Zmq PUB 套接字

python - pyzmq 上下文有时初始化很慢