2017-05-26 38 views
3

有没有办法改变流星处理丢失连接的超时时间?流星连接超时调整

使用案例: 我们有一台服务器,连接到几个客户端。一旦客户端连接断开,例如拔出以太网电缆,我们想要反映客户端已经离线。但是,由于连接超时时间似乎约为30秒,因此服务器注意断开连接并将客户端置于脱机状态需要很长时间。

我们尝试过的事情: - 更改客户端的心跳速率,这对客户端起作用,因为他们更快地断开连接。尽管如此,这不会影响服务器上的行为,因为服务器仍然等待大约30秒来调用连接删除。

  • 实施我们自己的心跳方法(间隔3秒)来检测连接丢失。然而,这导致了一些额外的代码,我期望可以配置。

我一直无法在文档中找到任何有关减少连接超时的信息。

回答

3

流星使用SockJS作为其websocket服务器。

由于性能问题(如果CPU太忙时用户断开连接),Meteor早期的断开延迟设置为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包,如果你想这很快就改变了覆盖它。