如何配置ZeroRPC及超时设置
我正在尝试用一个ZeroRPC的Python服务器和Node.js客户端进行简单的负载测试。我发现如果请求的处理时间超过10秒,我就收不到任何数据。我在Python代码中尝试配置不发送心跳:
s = zerorpc.Server(Test(), heartbeat=None)
还尝试配置Node.js客户端:
new zerorpc.Client({ timeout: 60, heartbeatInterval: 60000 }),
但结果还是一样。
我该如何让处理时间超过10秒的请求也能返回结果呢?
2 个回答
0
对于最新的 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
0
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;
};
不过,最新的主版本已经实现了hearbeatInterval这个选项,你可以在客户端构造函数里指定它。
所以你的代码可以通过下面的命令来安装最新的主版本,这样就能正常工作了:
npm install git+https://github.com/dotcloud/zerorpc-node.git
或者你也可以等一个新版本的发布……