title: Async vs Sync Benchmarks on MVC Controller with Questions
body: <p>I have set-up the examples from this MSDN article <a href="http://www.asp.net/mvc/tutorials/mvc-4/using-asynchronous-methods-in-aspnet-mvc-4" rel="noreferrer">Using Asynchronous Methods in ASP.NET MVC 4</a> and have done some benchmarking to see what I come up with.</p>
  <h3>Server Configuration:</h3>
  <ul>
  <li>Windows 7 Professional (x64)</li>
  <li>IIS 7.5</li>
  <li>Intel Core i7-2600S @ 2.80HGz</li>
  <li>8GB Memory</li>
  <li>AppPool &gt; Maximum Worker Processes: 10</li>
  </ul>
  <p>I set-up 2 controllers <code>Sync</code> and <code>Async</code> and did some testing using a loader tool for benchmarking.  The loader tool just sends 50-60 constant requests for one minute. Each controller is calling the same webservice 3 times. The code for each is below:</p>
  <hr />
  <h2>SYNC:</h2>
  <pre><code>public ActionResult Sync()
  {
      var g1 = GetGizmos(&quot;url1&quot;);
      var g2 = GetGizmos(&quot;url2&quot;);
      var g3 = GetGizmos(&quot;url3&quot;);
      return Content(&quot;&quot;);
  }
      
  public object GetGizmos(string uri)
  {
      using (WebClient webClient = new WebClient())
      {
          return JsonConvert.DeserializeObject(
           webClient.DownloadString(uri)
          );
      }
  }
  </code></pre>
  <p><img src="https://i.stack.imgur.com/A7Z1N.gif" alt="sync" /></p>
  <h2>ASYNC:</h2>
  <pre><code>public async Task&lt;ActionResult&gt; Async()
  {
      var g1 = GetGizmosAsync(&quot;url1&quot;);
      var g2 = GetGizmosAsync(&quot;url2&quot;);
      var g3 = GetGizmosAsync(&quot;url3&quot;);
      var a1 = await g1;
      var a2 = await g2;
      var a3 = await g3;  
      return Content(&quot;&quot;);
  }
  
  
  public async Task&lt;object&gt; GetGizmosAsync(string uri)
  {            
      using (HttpClient httpClient = new HttpClient())
      {
          var response = await httpClient.GetAsync(uri);
          return (await response.Content.ReadAsAsync&lt;object&gt;());
      }
  }
      
  </code></pre>
  <p><img src="https://i.stack.imgur.com/rGlZb.gif" alt="async" /></p>
  <p>First question, does anyone know why Async is taking longer, running less and causing timeouts, whereas sync version isn't?  I would think using Async for this would be faster, no timeouts, etc.  Just doesn't seem right, am I doing something wrong here? What can be done to improve/fix it?</p>
  <p>Second question, Using WebRequests in general, is there a way to speed that up? I have set the following in my <code>global.asax</code> but still unsure if the usage is correct:</p>
  <pre><code>System.Net.ServicePointManager.DefaultConnectionLimit = 1000;
  </code></pre>
  <p>Also, any other suggestions to help speed up an application performing these types of tasts will be very helpful.</p>