Web API Service - How to make the requests at the server to be executed concurrently

AmirTNinja picture AmirTNinja · May 25, 2014 · Viewed 7.9k times · Source

I am using a WebApi rest service controller, hosted by IIS 7.5, as i understood from this post:

Are all the web requests executed in parallel and handled asynchronously?

A webApi service, by default, executes all its incoming requests in parallel, but only if the current multiple requests (at a certain time) came from different sessions. That is to say, if single client will send some simultaneously requests to server, all of them will be executed sequentially and won't be executed concurrently.

This behavior is a real problem for us, because in some cases, our client sends bunch of requests from different client's listeners, asynchronously (by browser), and all of them will actually be queued instead of being executed concurrently at the server. Therefore, in some cases, we experiencing a serious performance issues which are really noticeable at the client's web page.

How can we solve this problem? I understand we can maybe disable session state but that isn't a normal thing to do.

Answer

Stephen Cleary picture Stephen Cleary · Oct 3, 2014

Actually, disabling session state is the normal solution for web APIs. If you need it for some/all of your calls, you can call HttpContext.SetSessionStateBehavior (e.g., from Application_BeginRequest). Multiple read-only session state requests can run concurrently.