Search code examples
restasynchronousasp.net-web-apiasync-awaitthreadpool

Does Async Actions in Asp.Net Web Api help the user in some way?


If I have a Web Api service (no GUI), and the Get request of the user demands me to get data, which is going to take 15 seconds to retrieve it,

and lets say this is my Action:

  [HttpGet]   
  public async Task<HttpResponseMessage> GetSomeAsync([FromUri]NiceRequestObject request)
  {
     var response = await _niceService.F1Async(request); //15 seconds duration.
     return Request.CreateResponse(response);
  }

then what is the benefit for the user? The fact I released the thread back to the thread pool...How will the user "feel" it some way? The user needs to wait these 15 seconds no matter what.


Solution

  • tl;dr

    This isn't a UI experience optimisation. It can improve UI experience but this is really a side effect. This helps you optimise your thread utilisation. Meaning you can process more requests with less threads. Meaning you can have a cheaper server and/or can process more requests on existing infrastructure.


    How will the user "feel" it some way?

    The user will feel it when 10,000 people all request your page at the same time and your server has a better chance of processing all of those request (including this imaginary "user") without running out of threads. Ultimately though, this is a server optimisation.

    The user needs to wait these 15 seconds no matter what.

    Unless all the threads on your server are used up, then the user will get an error when they request this resource (depending on other technology) and will have to resubmit. Meaning they will have to wait longer than 15 seconds.