1

Here is the very simple scenario I would like to show:

internal class Program
{
    private static void Main(string[] args)
    {
        var uri = new Uri("http://myserver.com");
        ServicePointManager.FindServicePoint(uri).ConnectionLimit = 1000;
        for (int i = 0; i < 1000; i++)
        {
            WebRequest.Create(uri).BeginGetResponse(a => { }, null);
        }
        Console.WriteLine("done");
        Console.ReadLine();
    }
}

And corresponding App.config:

<system.net>
  <connectionManagement>
    <clear/>
    <add address="*" maxconnection="1000" />
  </connectionManagement>
  <defaultProxy>
    <proxy proxyaddress="http://127.0.0.1:8888" />
  </defaultProxy>
</system.net>

Let say myserver.com responds 10 seconds (I emulated this in Fiddler via AutoResponder).

In the proxy server (Fiddler) I see that only 14 http requests are sent at application start. Then number of active connections is growing but very slow, about +1 request in 1-2 sec. So after 1 minute of work the number of active http requests is about 50, but not 1000.

Is there any configuration that I can change to force .NET to open if not 1000 real http request but at least 200-300?

Pashec
  • 23,199
  • 3
  • 26
  • 26
  • You should complete your WebRequests by reading the response stream and correctly disposing of your IDisposables. Can you also be sure that limits aren't being imposed by Fiddler? This may also be of interest: http://stackoverflow.com/a/1361932/14357 – spender Jun 20 '13 at 16:22
  • I tried to change System.Net.ServicePointManager.DefaultConnectionLimit. It didn't help. By the way, it was already 1000. Disposing of WebResponse didn't help as well. – Pashec Jun 20 '13 at 16:26
  • I am with Peuczyński. Right now all you requests are on a single thread. – paparazzo Jun 20 '13 at 17:05
  • If you run the application, you can see that BeginGetResponse is invoked incredibly fast that 1000 times. So "done" message is displayed right after app start. I mean single thread is not the cause. Anyway I tried this approach - no difference. – Pashec Jun 21 '13 at 06:44
  • How can you have a BeginGetResponse and no request to the proxy server? – paparazzo Jun 21 '13 at 13:10
  • I believe there is some internal queue in .NET. Just try yourself to ensure. – Pashec Jun 21 '13 at 14:30

1 Answers1

1

I think that the best solution is to open each of the connections in new Thread.

The thread limit is 1023 in .NET 4 32-bit systems 32768 in .NET 4 64-bit systems

If it doesn't work at least you will be sure that there is nothing wrong in your code.

Peuczynski
  • 4,591
  • 1
  • 19
  • 33