Microsoft Azure、中继绑定和最大并发性

Microsoft Azure, relay bindings and max concurrency

我已经使用 Microsoft Azure 设置了 ServiceBus 中继。我正在使用一个 HTTP 后端连接到此,该后端处理传入的 GET 和 POST 请求到达中继。

现在,这工作得很好。不过,我的问题是我可以获得的最大并发性是 2 个同时请求,即我的后端只会同时收到 2 个请求,如果有更多请求,它们将被暂停,直到处理并完成之前的请求。我已经尝试通过服务行为增加并发性,但这似乎被忽略了,但是将并发性降低到 1 似乎与设置有关。所以我猜这是实际中继强加的某种限制!?但真的可以吗?只有 2 个?在我的场景中,这使得中继无法使用,因为请求必须进行耗时的处理(2 秒),不能延迟并且需要立即响应。因此,我不能简单地存储请求并像队列一样处理它们。

我该如何扩展它?添加更多中继并连接到所有中继?

您需要将 ServicePointManager.DefaultConnectionLimit 设置为适当的值以允许更多并发连接。尽早在您的应用程序代码中尝试这样做:

ServicePointManager.DefaultConnectionLimit = int.MaxValue;

这将允许您的应用程序打开无限数量(实际上)的并发 HTTP 连接。


默认限制取决于 HTTP 协议的最初设计方式。

以下引自section 8.1.4 of the HTTP/1.1 RFC:

A single-user client SHOULD NOT maintain more than 2 connections with any server or proxy [...] These guidelines are intended to improve HTTP response times and avoid congestion.

因此,兼容的客户端通常必须确保它与单个服务器的打开连接永远不会超过两个。

但是,这已经改变,您可以覆盖此行为。以下引用来自 section 6.4 of RFC 7230,它是 HTTP/1.1 协议的更新:

Previous revisions of HTTP gave a specific number of connections as a ceiling, but this was found to be impractical for many applications. As a result, this specification does not mandate a particular maximum number of connections but, instead, encourages clients to be conservative when opening multiple connections.