【问题标题】:Meteor connection timeout adjustment流星连接超时调整
【发布时间】:2017-05-26 09:57:39
【问题描述】:
有没有办法更改超时 Meteor 句柄以断开连接?
用例:
我们有一个服务器,连接到几个客户端。一旦客户端上的连接断开,例如通过拔出以太网电缆,我们希望反映客户端已离线。但是,由于连接超时似乎是大约 30 秒,因此服务器大约需要这么长时间才能注意到断开连接并将客户端置于脱机状态。
我们尝试过的事情:
- 更改客户端上的心跳速率,这对客户端有效,因为它们会更快地断开连接。但这不会影响服务器上的行为,因为服务器仍会等待大约 30 秒来调用连接断开。
- 实现我们自己的心跳方法,它有 3 秒的间隔,以检测连接断开。然而,这会导致大量额外的代码用于我期望可配置的东西。
我在文档中找不到任何关于减少连接超时的内容。
【问题讨论】:
标签:
javascript
meteor
connection
connection-timeout
【解决方案1】:
Meteor 使用 SockJS 作为其 websocket 服务器。
在 Meteor 早期,由于性能问题(如果 cpu 太忙,用户会断开连接),断开延迟设置为 60 秒,并且无法配置。
// The default disconnect_delay is 5 seconds, but if the server ends up CPU
// bound for that much time, SockJS might not notice that the user has
// reconnected because the timer (of disconnect_delay ms) can fire before
// SockJS processes the new connection. Eventually we'll fix this by not
// combining CPU-heavy processing with SockJS termination (eg a proxy which
// converts to Unix sockets) but for now, raise the delay.
disconnect_delay: 60 * 1000,
来源:Meteor ddp-server package
如果您希望快速更改,您很可能需要分叉 ddp-server 包并覆盖它。