Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POST requests "stall" on Chrome

I started noticing that post requests sent to our application server are getting stalled for around 7 seconds on the browser side for no discernible reason.

Environment :

  • Angular 1.4
  • Play Framework
  • Chrome 64.*
  • Server sent events (SSE)
  • POST request

The number of TCP connections, as seen from the Chrome console, are around 3-4 at the time of stalling as seen in Network -> Connection Id

If the user rapidly does around 4 UI operations that create a SSE subscription, followed by the POST, stalling is observed consistently.

I'm not really a UI dev so any help debugging is helpful.

like image 321
212 Avatar asked Oct 28 '25 05:10

212


1 Answers

I have seen this too, using Angular 1.4 with Chrome (not sure which version). In our case it seemed to be caused by too many parallel requests. We therefore bundled requests into batches. You can use this function if you like to give it a go and see if it helps in your case:

function _batchRequests(requests, batchSize) {
    function doBatch(batches, batchIndex, numBatches, deferred) {
        if (batchIndex === numBatches) {
            deferred.resolve();
            return null;
        }
        console.log('Doing batch ' + batchIndex);
        let p = [];
        let batch = batches[batchIndex];
        _.forEach(batch, (f) => {
            p.push(f());
        });
        return $q.all(p).then(() => {
            doBatch(batches, ++batchIndex, numBatches, deferred);
        }, (err) => {
            deferred.reject(err);
        });
    }
    let deferred = $q.defer();
    let b = batchSize || 3;
    let batches = _.chunk(requests, b);
    doBatch(batches, 0, batches.length, deferred);
    return deferred.promise;
}

Note that the above function depends on lodash for _.chunk and _.forEach.

like image 150
see sharper Avatar answered Oct 29 '25 22:10

see sharper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!