SignalR与负载均衡器组合在一起,缺少消息 [英] SignalR combined with load balancer missing messages

查看:132
本文介绍了SignalR与负载均衡器组合在一起,缺少消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在硬件防火墙后面有2台Web服务器(IIS 8.5),我们的应用程序使用SignalR进行一些实时更新.我们正在使用SQL Server作为背板,以帮助我们在这种负载平衡的环境中工作.此外,我们在负载均衡器上使用粘性会话,以帮助我们在会话期间将用户保持在同一Web服务器上.当我们在这种硬件配置下运行时,我们将丢失至少1/3的消息.有时我们会收到所有预期的消息,但更多的是我们经常丢失很多消息.

I have 2 web servers (IIS 8.5) behind a hardware firewall and our application uses SignalR for some real-time updates. We are using SQL Server as the backplane to help us work in this load balanced environment. Additionally we are using sticky sessions on the load balancer to help us keep the users on the same web server during their session. When we are running in this hardware configuration we lose at least 1/3 of our messages. Sometimes we get all the expected messages but more often than not we are missing plenty.

当我们在单个Web服务器上运行时,会收到所有消息.有人对解决此问题有任何建议吗?我们已经打开了日志(包括客户端和服务器),看起来好像没有丢失或损坏.我们真的很沮丧.

When we are running on a single web server all messages are received. Does anyone have any suggestions for troubleshooting this problem? We've turned on logs (both client & server) and nothing looks like it's missing or broken. We're really stumped.

编辑---

我希望一些其他细节可以说明这一情况.

Some additional details that I hope will shed light on the situation.

  • 服务器到客户端的消息丢失了.我们几乎所有的通信都是服务器到客户端.
  • 我们正在使用基于IP的粘性会话,限制为5分钟,但在5分钟内我们丢失了消息.
  • 这是一些旧的SignalR代码,自SignalR 1(甚至更旧)以来才被最小程度地使用. 我们会在内存中保留用户及其连接的列表,并使用该列表将通知发送回客户端.最有可能的原因是麻烦,但对于粘性会话,用户应该至少在5分钟内停留在同一台服务器上?
  • 此用户列表将用户名映射到连接ID.当我们的后端服务(在另一台计算机上)使用用户名而不是连接ID发送消息时,此功能很有用.
  • Server to Client messages are getting lost. Pretty much all our communication is Server to Client.
  • We are using sticky session just based on IP and limited to 5 minutes but we're losing messages within that 5 minutes.
  • This is some old SignalR code that has been only minimally touched since SignalR 1 (or even older). We are keeping an in memory list of users along with their connections and we use that list to send notices back to the client. It seems most likely that this is the cause of the troubles but with Sticky sessions the user should be stuck to the same server for at least the 5 minutes right?
  • This list of users maps Username to connection id. This is useful when our backend services (on another machine) sends a message back with the username not the connection id.

推荐答案

最终解决了这个问题.确实有2个问题.首先是我们使用了上面的编辑中提到的用户的内存列表.一旦我们意识到无法在所有机器上正常工作,便将其删除.这也导致我们遇到第二个问题,即SignalR 2如何使用IUserIdProvider,而我们的通话应该是

Finally resolved this. There were 2 issues really. The first is that we were using an in memory list of users as mentioned in the edit above. Once we realized that wasn't going to work across machines we removed it. It also led us to the second issue which was how SignalR 2 uses the IUserIdProvider and our call should have been

Clients.User(userId).send(message)

代替

context.Clients.Client(connection)

此代码自从我们多年前首次使用SignalR以来就存在,并且在升级SignalR版本时从未得到正确的更新

This code had existed since we first started using SignalR many years ago and never got properly updated as we upgraded SignalR versions

这篇关于SignalR与负载均衡器组合在一起,缺少消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆