0

Bah!

I have recently installed the MiniProfiler from http://code.google.com/p/mvc-mini-profiler/ attempting to find all the slow calls on my site. (There are quite a few. But I've fixed a lot of it as a result of the profiler)

There were two common calls that I noticed were being reported by the profiler to take over a second to return in some cases. This didn't make any sense. The profiler showed the call (in mvc itself) to take around 2-4ms but the overall call took over 1 second. I spent quite a bit of time trying to narrow down the problem.

I noticed that the subsequent ajax calls are always instant but those were on delayed loads and the initial call times seemed to always grow from the initial page load so I decided to check in firebug and IE's firebug equivalent and the reported times are the same. I decided then to delay the calls made by the page by about 10ms using a setTimeout(). Suddenly the calls are exactly what they should be in terms of how long they take to complete. (Note the actual calls are instant but the reported times aren't)

I can not figure out why this is happening. I've tried to reproduce it using a new project and attempting to duplicate the behavior but alas, all is well in the new project. My initial thoughts were that the initial ajax calls were using the same connection due to the keep alive header, however, all the responses returned with "Closed" on the keep alive so I'm not sure that is the case.

Here are the results from the different services

Mini Profiler

Mini profiler results

Firebug

firebug results

IE's firebug

ie results

Note that I'm fairly certain the difference between the page results and the first call are a result of the images being loaded for the page.

Javascript Helper function

<script type='text/javascript'>
    function LoadJson(url, callback, error) {
        $.ajax({
            url: url,
            type: "POST",
            dataType: "json",
            success: function (ret) {
                callback(ret);
            },
            error: function (ret) {
                //alert(url);
            }
        });
    }
</script>

Actual call

$(function () {
    LoadJson('/ajax/activeform', function (ret) {
        //Do something
    });
);

Any help in understanding this would be appreciated. Thanks :)

Buildstarted
  • 26,529
  • 10
  • 84
  • 95
  • I don't know if this is related to my issue, but it seems like it. Disabling session state worked, as did using locking to prevent two requests from happening at once. http://stackoverflow.com/questions/6172350/mysterious-asp-net-mvc-action-high-latency-issue – Jason Goemaat Jun 10 '11 at 23:21
  • @Jason Goemaat, I'll have to give that a try. Trouble is that I need the session state on the ajax calls but willing to see if that's the issue and then look for a way around that :) – Buildstarted Jun 13 '11 at 21:17
  • I was unable to remove the session state without breaking the application. Thanks though. :) – Buildstarted Jun 28 '11 at 16:04

2 Answers2

1

You may be seeing the result of max browser connection to the same domain. Browsers have a certain limit of concurrent connections that they can make to a domain. The reason your delay works is that this allows other requests to finish freeing up a connection allowing your ajax request to action immediately rather than being queued up.

redsquare
  • 78,161
  • 20
  • 151
  • 159
0

Load times of 1-2 seconds of the first call can be attributed to an assembly loading. It can be hard to verify when running a live site. The easiest way is to just run it in the debugger and watch the output window.

If it is the case you can use a warm up call in your Global.asax or other common block of code to call a method or initialise a class in the assembly. This will force the assembly to be loaded and linked on application startup.

Bernie White
  • 4,780
  • 4
  • 23
  • 21