在Web的场方案SignalR连接亲和力 [英] SignalR connection affinity in web-farm scenario

查看:178
本文介绍了在Web的场方案SignalR连接亲和力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下要求我的应用程序:一个连接的JavaScript(客户端)和服务器(ASP.NET)之间打开。这种连接必须能够将数据发送回&安培;来回的时间中量,并保持的状态(不像REST调用),直到它关闭。也就是说,对于连接的持续时间,则客户端基本上具有与服务器亲和力(在Web-场方案)。

I have the following requirement for my application: a connection opens between JavaScript (client) and the server (ASP.NET). This connection must be able to send data back & forth for a medium amount of time and remain stateful (unlike REST calls) until it's closed. That is to say, for the duration of the connection, the client basically has affinity (in a web-farm scenario) with the server.

我已经读了很多关于SignalR和WebSockets的一般,但我想不通,如果这是它是如何运作与否。

I have read a lot about SignalR and WebSockets in general, but I can't figure out if this is how it operates or not.

我不关心服务器 - >网络 - 场中的服务器之间的服务器之间的通信,因为这已经解决了code。我只需要JS的客户端和服务器它最初接触留在了连接的持续时间接触。

I do not care about server->server communication between servers in the web-farm, as this has already been solved with code. I only need the JS client and the server it initially contacts to stay in contact for the duration of the connection.

这是它是如何工作的,如果不是,这可能吗?此外,如果可能的话,我怎么能存储在内存中的信息在多个呼叫/广播?

Is this how it works, and if not, is this possible? In addition, if it is possible, how can I store information in memory for the duration of the connection across multiple calls/broadcasts?

推荐答案

请记住,虽然SignalR不透明很多事情对你来说,4个底层传输有很大的不同。

Keep in mind, that although SignalR does transparently lots of things for you, the 4 underlying transports are quite different.

只有的WebSockets和SSE是持久连接。 ForeverFrame和LongPolling是重复的HTTP请求,因此,如果你有多个服务器在一个循环的方式进行负载平衡,必须对每个呼叫转到无法控制的。

Only WebSockets and SSE are persistent connections. ForeverFrame and LongPolling are repetitive HTTP requests, and therefore if you have several servers load balanced in a round robin fashion, you have no control on where each call goes.

一个解决方案是使用负载平衡器具有粘性会话。这种负载平衡器将查找在设定的亲和力特定服务器的HTTP请求特定的Cookie。

A solution is to use a load balancer with sticky sessions. This kind of load balancers will look for specific cookies in the HTTP request to set an affinity for a particular server.

其他的解决办法是使用SignalR背板,所以你不介意在您的请求前往,背板可确保连接得到正确的信息:

Other solution is to use the SignalR backplane, so you do not mind where your requests go, the backplane ensures the connection gets the right messages:

http://www.asp.net/signalr/overview/signalr-20/performance-and-scaling/scaleout-in-signalr

每个服务器实例连接到通过总线背板。当一个
  发送消息时,它会到背板,与背板将其发送
  每一个服务器。当一个服务器从背板获得消息,它
  将邮件在本地缓存中。然后,服务器传递消息
  从本地缓存的客户。

Each server instance connects to the backplane through the bus. When a message is sent, it goes to the backplane, and the backplane sends it to every server. When a server gets a message from the backplane, it puts the message in its local cache. The server then delivers messages to clients from its local cache.

有关每个客户端连接,客户端的在读取进度
  消息流是使用光标跟踪。 (光标再presents一个
  消息流中的位置。)如果一个客户端断开连接,然后
  重新连接,它要求总线后,即到达任何消息
  客户端的游标值。当连接使用同样的事情发生
  长轮询。长轮询请求完成后,客户端打开
  新的连接并询问光标后到达的消息。

For each client connection, the client’s progress in reading the message stream is tracked using a cursor. (A cursor represents a position in the message stream.) If a client disconnects and then reconnects, it asks the bus for any messages that arrived after the client’s cursor value. The same thing happens when a connection uses long polling. After a long poll request completes, the client opens a new connection and asks for messages that arrived after the cursor.

这篇关于在Web的场方案SignalR连接亲和力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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