Huge delays for some requests in an ASP.NET MVC project

482 Views Asked by At

I have a problem with an ASP.NET MVC project hosted on IIS. I'm flooding the same request hundreds of times:

function Test(count){
    for(var i=0; i<count; i++){
        $.ajax({
          url: "http://example.com?someparam=sth&test="+i,
          context: document.body
        }).done(function() {
          console.log("done");
        });
    }
}
Test(500)

Here is the taken time of each request in milliseconds (here are just a part of the sent requests):

221
215
225
429
217
228
227
209
236
355
213
224
257
249
223
211
227
1227
168
181 
257 
3241 
201
244
130
198
283
1714
146
136
177
3304
294
868
772
2750
138
1283
221
775
136
235
792
278
641
1707
880
1711

As you can see there are peaks for some of the requests and the taken time could be more than 10 times of the average of the other requests.

  1. I though it could be a Garbage Collector issue, but I think it's not. I called GB on each request. I had the same result, the delays were still there in the log.
  2. This happens not only for my MVC project but either for an empty MVC project.
  3. I created a new MVC project and sent lots of requests to Home/About. The result was same.
  4. I tried with an action that returns EmprtActionResult... same result.

If anybody knows why this happens and has a solution for the problem or just has a suggestion ... please share the information, I will be really grateful

Also I'm using .NET Memory Profiler, but I can't find out how to track each request and catch exactly the requests with delays. Can I do it with .NET Memory Profiler? If I don't please suggest another profiler that will be working for me.

Thank you!

EDIT: I also tried with an empty WebForms project. There were delays just for the firs 5 requests ... but this is because of IIS warming up for sure. And no delays for the next 1495 requests.

1

There are 1 best solutions below

0
B2K On

Your testing methodology has no way to identify where your bottleneck might be occurring, only that something is causing your delay.

Also, there is no mention whether this is an isolated server. If you are hitting a production website, you'll be affected when pages are requested by visitors accessing the web site.

At the very least, you'll need to add a control to this. I would start by loading a plain text file from the same web server. Another point to note is that most web browsers will limit the number of concurrent requests to the same web site. Usually, that is two simultaneous requests. Your delay could be a backlog of ajax requests in your client.