【问题标题】:How to configure ZeroRPC and timeouts如何配置 ZeroRPC 和超时
【发布时间】:2020-01-01 17:44:14
【问题描述】:

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

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

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

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

但仍然看到相同的行为。

如何让请求花费超过 10 秒的时间返回结果?

【问题讨论】:

  • 您是否曾经设法找到解决方案?我现在也有同样的问题。

标签: python node.js zeromq zerorpc


【解决方案1】:

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 选项。

然后您的代码可以使用命令安装最新的 master

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

或者等待新版本....

【讨论】:

    【解决方案2】:

    最新版js zerorpcv0.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年心跳->超过10s,js和python还在运行,不再报错

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

    【讨论】:

      猜你喜欢
      • 2014-12-30
      • 2013-06-22
      • 1970-01-01
      • 2014-04-14
      • 2021-09-17
      • 2021-09-08
      • 2014-10-26
      • 1970-01-01
      • 2021-03-19
      相关资源
      最近更新 更多