Reputation: 341
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?
Upvotes: 21
Views: 5239
Reputation: 4483
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
Upvotes: 3