- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
例如,我注意到 zeromq PUB 套接字在连接时会缓冲所有传出数据
import zmq
import time
context = zmq.Context()
# create a PUB socket
pub = context.socket (zmq.PUB)
pub.connect("tcp://127.0.0.1:5566")
# push some message before connected
# they should be dropped
for i in range(5):
pub.send('a message should not be dropped')
time.sleep(1)
# create a SUB socket
sub = context.socket (zmq.SUB)
sub.bind("tcp://127.0.0.1:5566")
sub.setsockopt(zmq.SUBSCRIBE, "")
time.sleep(1)
# this is the only message we should see in SUB
pub.send('hi')
while True:
print sub.recv()
sub 在这些消息之后绑定(bind),它们应该被丢弃,因为如果没有人连接到它,PUB 应该丢弃消息。但它不会丢弃消息,而是缓冲所有消息。
a message should not be dropped
a message should not be dropped
a message should not be dropped
a message should not be dropped
a message should not be dropped
hi
如您所见,那些“不应丢弃的消息”由套接字缓冲,一旦连接,它就会将它们刷新到 SUB 套接字。如果我在 PUB 套接字处绑定(bind),并在 SUB 套接字处连接,那么它可以正常工作。
import zmq
import time
context = zmq.Context()
# create a PUB socket
pub = context.socket (zmq.PUB)
pub.bind("tcp://127.0.0.1:5566")
# push some message before connected
# they should be dropped
for i in range(5):
pub.send('a message should not be dropped')
time.sleep(1)
# create a SUB socket
sub = context.socket (zmq.SUB)
sub.connect("tcp://127.0.0.1:5566")
sub.setsockopt(zmq.SUBSCRIBE, "")
time.sleep(1)
# this is the only message we should see in SUB
pub.send('hi')
while True:
print repr(sub.recv())
而且你只能看到输出
'hi'
这种奇怪的行为会导致问题,它会在一个连接套接字上缓冲所有数据,我有两个服务器,服务器 A 将数据发布到服务器 B
Server A -- publish --> Server B
如果服务器 B 上线,它工作正常。但是,如果我启动了服务器 A 而没有启动服务器 B 呢?
结果,服务器A上连接的PUB套接字保留了所有这些数据,内存使用率越来越高。
问题来了,这种行为是错误还是特性?如果是功能,我在哪里可以找到提到此行为的文档?以及如何停止连接 PUB 套接字缓冲所有数据?
谢谢。
最佳答案
套接字是阻塞还是丢弃消息取决于套接字类型,如 ZMQ::Socket documentation 中所述(下面的重点是我的):
ZMQ::HWM: Retrieve high water mark
The ZMQ::HWM option shall retrieve the high water mark for the specified socket. The high water mark is a hard limit on the maximum number of outstanding messages 0MQ shall queue in memory for any single peer that the specified socket is communicating with.
If this limit has been reached the socket shall enter an exceptional state and depending on the socket type, 0MQ shall take appropriate action such as blocking or dropping sent messages. Refer to the individual socket descriptions in ZMQ::Socket for details on the exact action taken for each socket type.
The default ZMQ::HWM value of zero means “no limit”.
您可以通过查看 ZMQ::HWM option action
的套接字类型的文档来查看它是否会阻塞或丢弃,这将是 Block
或 放下
。
ZMQ::PUB
的操作是Drop
,所以如果它没有被丢弃,你应该检查 HWM(高水位线)值并注意警告 < strong>默认的 ZMQ::HWM 值为零意味着“无限制”,意味着它不会进入异常状态,直到系统内存耗尽(此时我不知道它的行为如何) .
关于python - ZeroMQ PUB 套接字在连接时缓冲我所有的外出数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8952091/
Rust 支持 pub和 pub(super) . pub使父模块可以访问项目...和pub(super)似乎也做同样的事情。我试过玩下面的例子,并交换 pub和 pub(super)似乎没有效果:
我正在尝试运行 this拖放 API。当我尝试运行 dart 文件(使用 dart 编辑器)时,出现以下错误: could not start pub serve or connect to pub
根据pub get docs pub get 和 pub Upgrade 之间的主要区别是: If a lockfile already exists, pub get uses the versio
我see函数的可见性可以在模块内声明为 pub(self)。这与没有 pub 属性的私有(private)函数有何不同?如果它们没有区别,为什么会存在这种语法? 最佳答案 pub(restricted
我正在运行 pub install 以便我可以使用作为 dart sdk 一部分的 intl 包(我需要使用 DateFormat 类)。我已经在我的项目中安装了其他包,例如 XML 解析器和演示文稿
假设我在 Rust 包中有这个文件层次结构: src/... src/m1/mod.rs src/m1/path/m2.rs 拥有以下行的实际区别是什么: pub mod path::m2; 在我的文
其中一个比另一个更安全吗? 最佳答案 id_rsa.pub 和 id_dsa.pub 是 id_rsa 和 id_dsa 的公钥。 如果您询问与 SSH 相关的问题,id_rsa 是 RSA key
pub 是 Dart 的包管理器。 Flutter 是一个使用 Dart 的移动应用 SDK。如何创建依赖于或以 Flutter 为目标的包? 最佳答案 要从 pub 包中声明对 Flutter 的依
id_rsa.pub 文件基本上是 Linux 主文件夹下 .ssh 文件夹中的一些加密文本,用于公钥加密。它使用 .pub 文件格式。但为什么这种文件格式也恰好是 Microsoft Publish
使用当前版本的angular.dart.tutorial , 使用 Chapter_04 对于“pub serve”,main.dart.js 是一个 42337 行的文件,示例运行良好。 对于“pu
假设我正在运行我自己的 pub-dartlang 实例对于私有(private)酒吧供稿;如何在 pubspec.yaml 中注明哪些软件包来自私有(private)提要与 pub.dartlang.
我们通过运行脚本来实现DART自动化,该脚本导航到项目文件夹(.yaml文件所在的位置)并运行“pub get”和“pub build”。它工作了一段时间,但现在(两种情况下)我们都得到了: Unha
我刚刚安装了 Dart Editor 并创建了一个简单的 Web 应用程序,当我单击运行时它显示此错误并且没有任何 react 。 “无法启动 pub 服务或连接到 pub” dart editor
当我尝试在 android studio 中打开大部分已下载的 flutter 应用程序时,它一直告诉我“Pub get”尚未运行,当我按下“获取依赖项”或升级依赖项时,它会向我显示该错误。我已经把a
在哪里可以找到用于搜索和列出已安装的打包版本和可用升级版本的命令行工具? 我想不出任何其他的软件包管理工具,它们不包含列出已安装版本或查找可用升级的命令,而无需实际升级。 例如,如果我的pubspec
前两天升级到 Flutter 2.0 开始面对 Execution failed for task ':app:compileFlutterBuildDebug'由于一些包裹。 然后我降级了,但错误仍
下面提供了相关的程序代码。我经常在开源项目中看到这样的代码,可以在Linux和Windows上运行。有人告诉我,这是为了避免编译警告。真的是这样吗? class Base { public:
我有一个带有简单测试代码的函数,例如: exports.helloPubSub = (event, context) => { const message = event.data
无法解析 URL“https://pub.dartlang.org”。错误 (69):无法“发布升级”flutter 工具。五秒后重试...(还剩 9 次尝试) 这是我创建或升级flutter时flu
我正在尝试制作一个脚本来控制农场中的 Android 设备,adb connect 通过 OpenSTF 建立连接。 .设备接受来自客户端的连接的要求之一是在 OpenSTF 中提供 adbkey.p
我是一名优秀的程序员,十分优秀!