Q:

GetRequestStream is very slow

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?

A:

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.

