How to saturate network connections/sec with threads
<p>I have created a simple Azure web service (that just echos back string passed to it) and I wanted to saturate the service with as much network connections as possible using a desktop .Net app. The desktop app is something like this:</p>

<pre><code>        System.Net.ServicePointManager.DefaultConnectionLimit = 1000;
        while (running)
        {
            if (m_working.Count &lt; max_threads &amp;&amp; m_queue.Count &gt; 0)
            {
                Queue q = m_queue[0];
                q.timestamp = DateTime.Now;
                q.thread = new Thread(new ParameterizedThreadStart(ThreadWorker));

                m_working.Add(q);
                m_queue.Remove(q);

                q.thread.Start(q);
                while (!q.thread.IsAlive) ;
            }
            ...
            Thread.Sleep(5);
        }
</code></pre>

<p>Inside ThreadWorker() is the code that contains WebClient object using the DownloadString() function.</p>

<p>For the web app, I have set:</p>

<pre><code>&lt;system.net&gt;
    &lt;connectionManagement&gt;
      &lt;add address="*" maxconnection="500"/&gt;
    &lt;/connectionManagement&gt;
  &lt;/system.net&gt;
&lt;system.web&gt;
</code></pre>

<p>When I run the app, I only manage to get maximum of about ~65 connections/s. Setting the Thread sleep time to lower value does not improve the performance. However if I run another instance of the app, the 2nd app would still show ~65 connections/s and the 1st instance is not affected.</p>

<p>Did I did something wrong with my code? How can I write the code so that the connections could be saturated, maybe perhaps 1000 or 10,000 connections/s?</p>

<p>Or is this some kind of fundamental limit on the C#/.Net library thing? Please help thanks.</p>