470,833 Members | 1,447 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

Problem with a growing number of connections in HttpWebRequest

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
2 2313
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
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.

Similar topics

2 posts views Thread by msnews.microsoft.com | last post: by
5 posts views Thread by japslam japslam via DotNetMonster.com | last post: by
2 posts views Thread by Dan D. | last post: by
8 posts views Thread by Chizl | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.