Thursday, March 16, 2017

Simultaneous AJAX calls appear to be executed serially - here's a possible explanation

Scenario:

You issue multiple AJAX requests to your ASP.NET (or any other similar Web Server). In Inspector Console, your requests are fired at the same time. However, it appears that one is starting to execute only after one request is finished.

Probable explanation:

Locking at the server side is the probable reason for this behavior. For example, if all your server side scripts access Session object, they need to wait in a queue for Session to become available. Session becomes available only when one of the simultaneous requests is finished. This is why it appears as a serial execution.


One easy workaround:
If you can , declare your ASP.NET MVC controller / page as readonly when it comes to accessing the Session object.


From the Stack Overflow thread:

Session is blocking access to other ones.

This is because session is single threaded per session. Requests to ASP scripts for the same session can only be processed sequentially so only one request will be handled at a time. To stop this you will need to stop using session on the page and turn it off: http://support.microsoft.com/kb/244465/en-us. If you need session you may need to instead use a database.


Details here in this useful forum thread

This same story applies to all shared resources on the server side. One great way to minimize these events, is to  replace Session object with Database.

No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...