CR41G14
CR41G14

Reputation: 5594

multiple ajax requests very slow mvc

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 () {

        }

    });

Upvotes: 3

Views: 3129

Answers (1)

Johncl
Johncl

Reputation: 1231

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.

Upvotes: 3

Related Questions