繁体   English   中英

如何配置 ZeroRPC 和超时

[英]How to configure ZeroRPC and timeouts

我正在尝试使用 ZeroRPC python 服务器和 node.js 客户端进行一些简单的负载测试。 我注意到的是,如果请求花费的时间超过 10 秒,我将不会收到任何数据。 我尝试在 python 代码中不配置心跳:

s = zerorpc.Server(Test(), heartbeat=None)

以及尝试配置 node.js 客户端:

new zerorpc.Client({ timeout: 60, heartbeatInterval: 60000 }),

但仍然看到相同的行为。

如何获得需要超过 10 秒才能返回结果的请求?

zerorpc-node (0.9.3) 的最后一个可用版本使用硬编码的 HEARBEAT 超时。

正如您在https://github.com/dotcloud/zerorpc-node/blob/0.9.3/lib/channel.js 中看到的:

//Heartbeat rate in milliseconds
var HEARTBEAT = 5000;
...
//Resets the heartbeat expiration time
Channel.prototype._resetHeartbeat = function() {
    this._heartbeatExpirationTime = util.curTime() + HEARTBEAT * 2;
};

但是,当您尝试在客户端构造函数中指定时,最新的主版本实现了 heartbeatInterval 选项。

然后您的代码可以使用命令安装最新的主服务器

npm install git+https://github.com/dotcloud/zerorpc-node.git

或者等待新版本....

对于最新的js zerorpc版本v0.9.8

# npm list zerorpc
xxx/electron-python-example
└── zerorpc@0.9.8 

和最新的python zerorpc版本v0.6.3

# pip show zerorpc             
Name: zerorpc
Version: 0.6.3
Summary: zerorpc is a flexible RPC based on zeromq.
Home-page: https://github.com/0rpc/zerorpc-python
Author: François-Xavier Bourlet <bombela+zerorpc@gmail.com>.
Author-email: UNKNOWN
License: MIT
Location: xxx/venv/lib/python3.8/site-packages
Requires: msgpack, future, pyzmq, gevent
Required-by: 

这提供了你已经说过的heartbeatInterval

所以我在这里使用代码electron-python-example/renderer.js

const constLargeEnoughHeartbeat = 60 * 60 * 24 * 30 * 12 // 1 Year
clientOptions = {
  "heartbeatInterval": constLargeEnoughHeartbeat,
}
let client = new zerorpc.Client(clientOptions)

可以实现您的预​​期:足够大到 1 年的心跳 -> 超过 10 秒,js 和 python 仍在运行,没有更多错误

  • js: invoke startSaver: error=Error: Lost remote after 10000ms
  • python: zerorpc.exceptions.LostRemote: Lost remote after 10s heartbeat

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM