I've just inherited an MVC4 API application that acts as a basic request forwarder for some other services. The basic structure of the app is something like this:
[request] -> [rest api] -> [local processing] -> [synchronous call to external service] -> [local processing of response] -> [response]
The local processing is mostly about validating and saving stuff into a db. Nothing heavy at all. The external request could take anything from 1 - 200+ seconds in extreme cases. The API typically handles several thousand requests per hour.
The app is hosted on a single, small, azure cloud instance.
What I'm confused about is the threading. The entire process from the API handler method, through to the external call to the external service, is set up to be asynchronous:
public async Task<CustomResponseType> Post([FromBody] inputType) {
// some validation
...
// save some stuff to a db
...
var response = await httpClient.PostAsync(someRequest)
return await response.Content.ReadAsStringAsync();
}
So firstly, what is the advantage to making this process async? To my understanding, IIS should be managing its own thread pool for incoming requests, and since we're waiting for a synchronous response to a single external service call, it doesn't look like anything actually gets processed in parallel. At first glance, it looks like the async service requests would be competing for the same resources that IIS would use, and that it might actually be more efficient to just do it all synchronously.
I've read this: http://msdn.microsoft.com/en-us/library/ee728598%28v=vs.98%29.aspx?wa=wsignin1.0 and understand that there maybe something called 'thread starvation' on the IIS side. That article supports the idea that async might be helpful in this situation, but I'm struggling to understand why. Would it be easier to just increase the number of IIS threads? Would they not all be competing for the same resources? Is the issue that IIS threads are heavier to use?