Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extremely long wait time when loading REST resource from angularjs

I'm building a front-end in angular that is accessing a flask/python RESTful API. I'm using AngularJS v1.2.16.

For some reason, it takes an insane amount of time before the REST resource is loaded, with most of the time just waiting. It's my understanding that 'waiting' is measuring the time to first byte - all my services run locally (the frontend, API and database).

Angular, the API and the Mongo DB are all running locally.

Given that the services all run locally, I am at a loss how to debug this. Does anybody have any tips on where to look? I checked all my methods and they run decently fast (under 100ms per REST call). When I use postman, the API returns near-instantly.

Any ideas how to fix the wait, it only seems to be the case when loading the RESTful resource via angular. The angular $http get request is fairly straight forward:

myAppControllers.controller('ManageCtrl', ['$scope', '$http',
    function($scope, $http) {
        $http({
            url: 'http://127.0.0.1:5000/v1/domains/',
            method: "GET",
            headers: { 'Content-Type': 'application/json' },
        }).
        success(function(data, status, headers, config) {
            console.log('login successful');
            console.log(status);
            console.log(data);
        }).
        error(function(data, status, headers, config) {
            console.log('login failed');
        });
    }]);

EDIT:

  • the issue only appears in Google Chrome, regular mode.
  • the GET requests are fast when using incognito mode.
like image 560
Samir Said Avatar asked May 13 '14 18:05

Samir Said


1 Answers

We had the same problem and after some research the problem is related with the way Chrome uses connections and the default configuration of flask as mono threaded.

Added threaded=true when flask app is started solved the problem:

app.run(threaded=True)
like image 93
dd. Avatar answered Sep 19 '22 15:09

dd.