By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,146 Members | 1,631 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,146 IT Pros & Developers. It's quick & easy.

Problem with a growing number of connections in HttpWebRequest

P: n/a
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().GetRe sponseStream());
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

May 21 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"Basel" <ba****@gmail.com> schreef in bericht
news:11**********************@y43g2000cwc.googlegr oups.com...
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().GetRe sponseStream());
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

May 22 '06 #2

P: n/a
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.

May 22 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.