I have an asp.net MVC 4 controller thats methods are called via ajax.
The problem is that the ajax requests are handled sequentially by the controller. This causes performance issues as the time to load the page is the sum of all ajax requests and not the longest ajax request.
To demonstrate this, I put a break point in the first ("ReadOverview8Week") method. Each of these methods take ~600ms to execute individuality.
How can I make the controller respond to all three requests in parallel? I am using iis 8.
This is the ajax request (from kendo ui dataSource)
.DataSource(dataSource => dataSource.Ajax()
.Read(read => read.Action("ReadAllSitesOverview", "AbuseCase").Type(HttpVerbs.Get))
Thanks.
The issue you are facing is caused by the way ASP.NET is managing session. Here is the most important part from ASP.NET Session State Overview (Concurrent Requests and Session State section):
Access to ASP.NET session state is exclusive per session, which means that if two different users make concurrent requests, access to each separate session is granted concurrently. However, if two concurrent requests are made for the same session (by using the same SessionID value), the first request gets exclusive access to the session information. The second request executes only after the first request is finished.
You can resolve your issue if your actions doesn't require access to session. If that is the case, you can decorate the controller with SessionStateAttribute attribute:
[SessionState(SessionStateBehavior.Disabled)]
This way the controller will not have to wait for session.
If your actions require only read access to session, you can try using the SessionStateBehavior.ReadOnly
value. This will not result in an exclusive lock but the request will still have to wait for a lock set by a read-write request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With