1

a quick overview of our set up :- MVC web application for front end, this sends REST requests to an MVC Web API.

This is all working great, however, we have now introduced AngularJS to allow us to use 2 way data binding with javascript.

This is a really good framework, and we have started to utilise the ajax $http requests.

so, within angular, we are using $http to call the MVC controller which calls the REST WEB API, data is returned, serialised as JSON within the controller and sent to the angularJS request for 2 way data binding.

This issue that we are having, is that we are now making multiple HTTP Requests in one go, however, each request seems to wait for the previous to have been completed and we are struggling to work out why? we where expecting all the requests to be independent of each other, so that there would be no lag or wait time...

If anyone can offer any advise, it would be greatly appreciated

ps - I hope that all made sense

angular code below:-

    $scope.LoadResults();
    $scope.GetHistory();
    $scope.GetUserDetails();

 $scope.GetHistory = function () {
  $http.post('/user/GetHistory/', $scope.data).success(function (data, status, headers, config) {
});
}

 $scope.GetUserDetails= function () {
 $http.post('/user/GetUserDetails/1234', $scope.data).success(function (data, status, headers, config) {
});
}


$scope.LoadResults = function () {
    $scope.data = {
        frequency: $scope.frequency,
        direction: $scope.direction,
        view: $scope.view
    };
    var userid = $('#id').val();
    var url = '/user/' + userid + '/GetUserResults/';

    $http.post(url, $scope.data).success(function (data, status, headers, config) {
        if (data.msg != '') {
                        $scope.resultssummarydata = data.aaData;

        }
        else {
            $scope.errors.push(data.error);
        }
    });
}
Simon
  • 1,412
  • 4
  • 20
  • 48
  • 1
    Is the web server under heavy load? If the thread pool is running out of threads you might see that things are starting to queue up and not run in parallel immediately. In that case, consider using `async` / `await` to allow I/O heavy actions to free the thread while doing the I/O. Related answer: http://stackoverflow.com/a/15190138/700926 – Lasse Christiansen Apr 03 '14 at 19:44
  • hi, everything is running locally at the moment, and async / await is being used. I've been googling most of the day. do we need to set the MVC controller as an async controller? – Simon Apr 03 '14 at 19:48
  • You seem to be concerned about the MVC controller being async, but that should have nothing to do with it if you are making ajax calls to it via angular (or any js library for that matter). The controller does not have to be async, and you don't have to use await on the server side. Show some angular code. – Phil Sandler Apr 03 '14 at 20:06
  • @PhilSandler We didn't think it should have any impact if its not an async controller, but from googling, thats the only answer we could find. I've added some sample code of how we are calling the controllers from the angular. As a test, we placed break points at the end of each controller, and the other controllers would not run, until the previous one had been completed. – Simon Apr 03 '14 at 20:50
  • 2
    Just a guess, but what if you disable session state on IIS? One other thing on using the REST word..actually you have more of a RPC web api than RESTful one. – Patko Apr 03 '14 at 21:03
  • Hi, we are using visual studio, and so using the built in webserver still at the moment, would anything need to be changed within that?. On a side note tho.. You mention RPC? What makes it more RPC than REST? Thanks again – Simon Apr 03 '14 at 21:16
  • No idea about builtin web server, sorry. You can try running it under iis and see how it behaves. As I understand asp.net serializes concurrent requests from the same client because of session state,that is why I suggested turning it off (if you are not using it ofc). As for why rpc.. What you are doing is calling a method (eg. GetUserDetails) instead of indicating with a http verb (like get) what you want to do with a resource (like /users/47). Then there is hateoas. Look at Richardson maturity model. – Patko Apr 03 '14 at 21:35
  • 1
    I think Patko may be on to something, since your angular code looks ok. Try changing (or adding) this to your web.config: . Just a note--disabling session will mean you can no longer use TempData. – Phil Sandler Apr 03 '14 at 22:52
  • Couple of questions. (1) How did you verify that the quests are indeed being processed synchronously from the browser? Can you post a screenshot of your browser's network tab in developer tools when loading that page, so we can indeed confirm that the synchronous effect is from the browser and not from the server? (2) If I understand your description, Angular is calling MVC controller, which in turn calls Web Api. Is there a specific reason to have MVC in the middle there, why not just call Web Api directly from Angular? – Beyers Apr 04 '14 at 01:32
  • @PhilSandler adding that to the webconfig has done the trick. Why would session cause a problem with this.. Did you want to set an answer and i'll mark it as correct. – Simon Apr 04 '14 at 14:22

1 Answers1

3

Note that if Patko wants to add this as an answer, he should get credit, since he is the one who really figured it out (I just supplied the means to turn sessions off).

Try changing (or adding) this to your web.config to turn sessions off:

<sessionState mode="Off" />.

The session implementation in ASP.Net is very strange. If multiple http requests come in from the same browser/user session, it serialized them and handles them one at a time. In addition to this, the session implementation is very inefficient--the whole session gets loaded into memory for each request.

There has been pretty wide criticism of the ASP.Net Session implementation over the years--a little googling will allow you to read up on it.

Phil Sandler
  • 27,544
  • 21
  • 86
  • 147