Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disadvantage of increasing ServicePointManager.DefaultConnectionLimit

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.

like image 408
Viru Avatar asked Jan 21 '16 11:01

Viru


2 Answers

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.

like image 145
Rahul Tripathi Avatar answered Oct 20 '22 22:10

Rahul Tripathi


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.

like image 28
jgauffin Avatar answered Oct 20 '22 22:10

jgauffin