Problem with a growing number of connections in HttpWebRequest

  • Thread starter Thread starter Basel
  • Start date Start date
B

Basel

Hi All!

I'm having a problem with a growing number of connections. my app
generates http requests and reads responses. the app creates large
number of threads (100 or more) that generates the requests, this is
the code:

ServicePointManager.DefaultConnectionLimit = 10;

ThreadFunction()
{
for(int i=0;i<1000000;i++)
{
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("http://localhost:8080/page.html");
request.KeepAlive = true;
System.IO.StreamReader reader = new
System.IO.StreamReader(request.GetResponse().GetResponseStream());
reader.ReadToEnd();
request.GetResponse().Close();
}
}

I'm using TCPView to monitor connections, after a couple of minutes
connections number starts to increase gradually , and some connections
closes.
decreasing ServicePointManager.MaxServicePointIdleTime will result in
creating more connection in less time

Is this problem is an issue of freeing resources? garbage collection?
My goal is to let each thread open one connection and stay active along
the way.

And what is the best way to achieve maximal throughput?

Basel
 
Basel,

You know that there is a commitment that says that there should not be used
more than 4 HTTP connections at a time in an applications and as this set in
PC Operatingsystems as default?

Cor
 
I know that single-user should not maintain more than 2 persistent
connections with any server or proxy.

Anyway, I dont think this should affect my application, I set the web
server not to limit connections. the server is in my lan.
Also, if I open only 2 connection, the number of the connections will
grow after some time.
So the problem is not with the number of connections I open.
 
Back
Top