3

I have an ASP MVC4 application which loads a dashboard of widgets. Each widget executes an async ajax call back to the server and a partial is returned.

For some reason these widgets are taking aprox 50 seconds to replace the content with the partial. The ajax request is instant and executing the database query is also instant on the database side. Most of the time this works fine but I think it may be related to high usage of the site.

Can anyone recommend anything I can do to debug this issue or identify what the bottleneck could be?

$.ajax({
            cache: true,
            type: 'post',
            async: true,
            url: '/Overview/GetBillingWidget/',
            success: function (result3) {

                if (result3 == '') {
                    $('.widget-billing-container').replaceWith('');
                } else {
                    $('.widget-billing').html(result3);
                }

            },
            error: function () {

            }

        });
$.ajax({
        cache: true,
        type: 'post',
        async: true,
        url: '/Overview/GetQueryWidget/',
        success: function (result3) {

            if (result3 == '') {
                $('.widget-myquery-container').replaceWith('');
            } else {
                $('.widget-myquery').html(result3);
            }

        },
        error: function () {

        }

    });
CR41G14
  • 5,464
  • 5
  • 43
  • 64
  • If you use session, investigate blocking. Session access is serialized, and the blocking can cause poor performance when multiple requests access it at roughly the same time. – Tim M. Mar 17 '15 at 22:26
  • Yes we widely use a session for this. What do you mean blocking? – CR41G14 Mar 17 '15 at 22:29
  • ASP.Net places a lock on session at the beginning of a request. If another request begins before the lock is released, it must wait for the other to finish, and I believe a 500ms delay is added. (see http://stackoverflow.com/questions/3629709/i-just-discovered-why-all-asp-net-websites-are-slow-and-i-am-trying-to-work-out) – Tim M. Mar 17 '15 at 22:33

1 Answers1

3

I had the same problem in a similar dashboard like application, and it is as the comments suggest a problem of Session locking. By default when a controller action is called the session is locked until it exists so any call coming in while this is happening will have to wait until it is released.

However, with some smart coding you can avoid session variables altogether, preferably by storing and reading data in a database. If your controllers are only reading session variables (or not using them at all), you can add this attribute on the top of your controller class:

[SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)]

This should solve a lot of locking issues you might experience with parallel ajax calls to your controllers.

Johncl
  • 1,211
  • 1
  • 12
  • 13