Disadvantage of increasing ServicePointManager.DefaultConnectionLimit

走远了吗. 提交于 2020-02-27 07:40:45

问题


I am calling a webservice in multi threaded environment. Lot of my calls fail due to operation time out or bad request but none of the calls fail if I do it in linear fashion which means there is problem with invoking webservice with multiple threads. After lot of analysis, I found out that there is limit of concurrent connection which is causing these exception so I fixed it by adding below code.

 ServicePointManager.DefaultConnectionLimit = 2 * _ThreadCount;

What I dont know is the possible disadvantage of increasing this limit. By default, Connection limit is 2. If anyone knows any disadvantages, please do let me know.


回答1:


The MSDN says:

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.

and

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.




回答2:


No, there should not be any disadvantages other than that your AppDomain will consume more resources. But in your case it's trivial.

In fact, it can actually help you use less resources (memory) since pending requests are queued up internally in the ServicePoint. Read here for more information: Big size of ServicePoint object after several hours sending HTTP request in parallel

let me give you the picture....I have around 46K tasks,these task are ran in batch of 100 (each task will call webservice) so I have 100 threads calling webserivce simultaneously. is it still trivial? or will it have some impact in my case?

It will of course have an impact. But the impact depends on many factors. A service point is per host.

If your tasks are mostly against the same host, increase DefaultConnectionLimit to a larger value (expected number of tasks in the current execution batch).

If you are mostly doing requests against different hosts, the limit in your question works fine.

Regarding the usage of resources, it's probably fine as long as your server is not very busy by other applications.



来源:https://stackoverflow.com/questions/34922699/disadvantage-of-increasing-servicepointmanager-defaultconnectionlimit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!