-2

When running a C# program which generates multiple network requests in a multi-threaded environment, I find that Request.GetRequestStream is quite slow, sometimes taking several seconds, and generally twice as long as the subsequent GetResponse. This is even though Proxy has been set to null, a "standard" fix.

What is the cause of this?

Hot Licks
  • 47,103
  • 17
  • 93
  • 151

1 Answers1

4

It turns out that .NET, by default, has a default limit of 2 for simultaneous connections. This of course will seriously throttle any app which does significant multithreading, and the delay will appear on the GetRequestStream call.

The "fix" is to alter the default limit to something more reasonable with:

ServicePointManager.DefaultConnectionLimit = newConnectionLimit;

My rickety Mac running Windows on VMWare seems to handle a value of 20 OK, but some care should be taken with the number as a large one will allow more resources to be tied up with no added performance.

Hot Licks
  • 47,103
  • 17
  • 93
  • 151