title: Async for Long operation with HttpResponseMessage
body: <p>I am figuring out performance of my C# web api. I wrote a very simple <code>HelloWorld</code> response:</p>
  
  <pre><code>public class HelloWorldController : ApiController
  {
      public HttpResponseMessage Get()
      {
  
          return new HttpResponseMessage()
          {
              Content = new StringContent("HelloWorld")
          };
      }
  }
  </code></pre>
  
  <p>I tested by using <a href="http://jmeter.apache.org/" rel="nofollow noreferrer">JMeter</a> I set 1000 Users request and it worked perfectly (CPU usage up to 100%). But the problem is that when the operation of the api take bit longer, the response become worse, got only 3 responses each (CPU usage &lt;7%). It took minuets for 1000 users request.</p>
  
  <pre><code>public HttpResponseMessage Get()
      {
          Thread.Sleep(1000);
          return new HttpResponseMessage()
          {
              Content = new StringContent("HelloWorld")
          };
      }
  </code></pre>
  
  <p>After google I come up with idea of using async but still I got same problem. I don't know what the problem is or my code implementation. Below is my sample implementation. </p>
  
  <pre><code>public async Task&lt;HttpResponseMessage&gt; Get()
      {
          return new HttpResponseMessage()
          {
              Content = new StringContent(await LongOperationAsync())
          };
      }
      private string LongOperation()
      {
          //long operation here
          Thread.Sleep(1000);
          return "HelloWorld";
      }
  
      private Task&lt;string&gt; LongOperationAsync()
      {
          return Task.Factory.StartNew(() =&gt; LongOperation());
      }
  </code></pre>
  
  <p>Anyone know what is the problem or any idea regarding to this problem?</p>