2017-05-26 41 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包,如果你想這很快就改變了覆蓋它。