Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum number of http requests using web workers

Tags:

I know there is a limit on the number of concurrent http connections that can happen at a time in a browser...

Is this a total, overall browser limit? Are web-workers subject to this limit as well, or are they treated differently because they are different threads?

like image 992
mpickell Avatar asked Aug 25 '14 15:08

mpickell


People also ask

How many web workers can I use?

You can spawn as many workers as you wish. You can also pass data to the script being executed in the worker threads and also return value to the main thread upon completion.

How many web workers and web workers can run concurrently?

A web worker is a JavaScript program running on a different thread, in parallel with main thread. The browser creates one thread per tab. The main thread can spawn an unlimited number of web workers, until the user's system resources are fully consumed.


Video Answer


1 Answers

TLDR: Workers (in Chrome and Firefox at least) appear to adhere to a global max number of connections per host name.

I used this code to create a number of workers...

/* jshint esversion: 6 */

(function() {

    'use strict';

    const iWorkerCount = 20;

    for(let i = 0; i < iWorkerCount; i++) {
        const oWorker = new Worker('/js/worker.js');
    }

}());

... and then each worker made a remote request to an image service...

/* jshint esversion: 6 */

(function() {

    'use strict';

    const sUrl = 'https://loremflickr.com/320/240';

    fetch(sUrl).then(sResponse => {
        console.log(sResponse);
    });

}());

There's an initial batch of requests that complete at the same time and then the remaining requests trickle in shortly once the number max requests dips

like image 138
michael Avatar answered Oct 19 '22 05:10

michael