Wednesday, July 12, 2006

More about microsoft Webservices

There is a client-side limit to how many simultaneous calls you can make
from one AppDomain to one web service (see the
ServicePointManager.DefaultCon-nectionLimit property).


http://www.webserviceshelp.org/wsh/Discussions/dotnet/postings/Web+Service+To+No+Where+Lbadnc0Wm4I5m1HfRVniQspeakeasynet.htm


After having seen this same problem at more than one client, I thought it important to share this valuable piece of information with others. When discovering it I was amazed that with all the .NET Web Services articles floating around, there is not any more mention of this important piece of information.

Let me start by describing the problem. You are using web services to interact with an external system (either your own or an external source). Everything works great in functional testing, but in load testing or (better yet) a production environment, under heavy load, requests to take an unusually long time or seem as though they are single threaded.

Contacting the 'owner' of the service you are consuming (this may be looking in the mirror), they will claim that they are fulfilling requests in compliance with service level agreements, but logging from your client application proves that this cannot be true.

The answer and cause lie in an http 1.1 specification intended to keep a user from saturating a web server. To prevent this, part of RFC2616 states that clients should limit their connections to servers.

...
Clients that use persistent connections SHOULD limit the number of
simultaneous connections that they maintain to a given server. A
single-user client SHOULD NOT maintain more than 2 connections with
any server or proxy. A proxy SHOULD use up to 2*N connections to
another server or proxy, where N is the number of simultaneously
active users. These guidelines are intended to improve HTTP response
times and avoid congestion.
...

Unfortunately this becomes a problem when your intention is to make multiple requests. In the cases where I saw this problem, we had a wonderfully multi-threaded queue listener that concurrently processed long running requests and purposely throttled the number of concurrent connections to the host to comply with our agreement. We complied and then some.

To 'fix' this problem, you must change the default setting for the maximum number of connections to the Internet host. This can be done in the machine.config, web.config or application configuration files as shown:









See MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/gngrfconnectionmanagementelement.asp for more information

It can also be changed programmatically:

Uri con = new Uri ("http://www.parivedasolutions.com/");

// Use the FindServicePoint method to find an existing
// ServicePoint object or to create a new one.
ServicePoint servicePoint = ServicePointManager.FindServicePoint (con);
servicePoint.ConnectionLimit = 10;


In .net , there
are connection management configuration settings which control the
connections allowed to remote servers. The setting are under the



# Element
http://msdn.microsoft.com/library/e...nnectionmanagem
entelement.asp?frame=true

the default connection limitation for every remote server is 2. That's why
you'll found your 3rd request to a single server pending until one of the
former 2 complete. We can override the limitation for that certain server
in our client app's app.config, for example:





maxconnection = "4" />





the above app.config adjust the connection limit for "remoteserver" to 4.
Then, we can make at most 4 requests concurrently to that server.

In addition, the following kb article also include this info and some other
common issues we may meet when consuming asp.net webservice in .net client
app.

#PRB: Contention, poor performance, and deadlocks when you make Web service
requests from ASP.NET applications
http://support.microsoft.com/?id=821268

Hope also helps.

Regards,

Steven Cheng
Microsoft Online Support

See MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnetservicepointmanagerclassfindservicepointtopic.asp for more information

0 Comments:

Post a Comment

<< Home