gpt4 book ai didi

c# - 增加 ServicePointManager.DefaultConnectionLimit 的缺点

转载 作者:太空狗 更新时间:2023-10-30 01:33:05 24 4
gpt4 key购买 nike

我在多线程环境中调用网络服务。由于操作超时或请求错误,我的很多调用都失败了,但是如果我以线性方式进行调用,则没有一个调用失败,这意味着使用多线程调用 web 服务存在问题。经过大量分析,我发现存在并发连接限制导致了这些异常,因此我通过添加以下代码修复了它。

 ServicePointManager.DefaultConnectionLimit = 2 * _ThreadCount;

我不知道增加此限制可能带来的不利影响。默认情况下,连接限制为 2。如果有人知道任何缺点,请告诉我。

最佳答案

MSDN说:

Changing the DefaultConnectionLimit property has no effect on existing ServicePoint objects; it affects only ServicePoint objects that are initialized after the change. If the value of this property has not been set either directly or through configuration, the value defaults to the constant DefaultPersistentConnectionLimit.

Note

Any changes to the DefaultConnectionLimit property affect both HTTP 1.0 and HTTP 1.1 connections. It is not possible to separately alter the connection limit for HTTP 1.0 and HTTP 1.1 protocols. When used in the server environment (ASP.NET) DefaultConnectionLimit defaults to higher number of connections, which is 10.

关于c# - 增加 ServicePointManager.DefaultConnectionLimit 的缺点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34922699/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com