Web Workers可以使用100%的多核CPU吗?

时间:2021-11-03 19:36:58

I've been trying to find out just how capable web workers are of distributing processor load. I've yet to find any demos that seem to be able to get my quad core 2600k to even 50%, let alone 100%.

我一直试图找出网络工作人员分配处理器负载的能力。我还没有发现任何能够让我的四核2600k甚至达到50%的演示,更不用说100%了。

Here's a web worker demo I've tried to max my CPU on:

这是一个Web工作者演示,我试图最大化我的CPU:

http://nerget.com/rayjs-mt/rayjs.html

http://nerget.com/rayjs-mt/rayjs.html

(If you go into the page's HTML with firebug /chrome-inspect-element and make the canvas larger, you can make it raytrace a much larger image - I set mine to 1920 x 1080)

(如果你使用firebug / chrome-inspect-element进入页面的HTML并使画布变大,你可以使它成为一个更大的图像 - 我设置为1920 x 1080)

Even with 4, 8, 16 workers selected, I can't get my CPU utilization above around 25% per core.

即使选择了4,8,16名工作人员,我也无法将每个核心的CPU利用率提高到25%左右。

Does anyone know if you can utilize 100% of the CPU through web workers?

有谁知道你是否可以通过网络工作者使用100%的CPU?

(I'm using Google Chrome.)

(我正在使用谷歌浏览器。)

2 个解决方案

#1


20  

This uses 100% on my 2500K:

这在我的2500K上使用100%:

var code = "while(true){}";
var URL = window.webkitURL || window.URL;
var bb = new Blob([code], {type : 'text/javascript'});

code = URL.createObjectURL(bb);

new Worker(code);
new Worker(code);
new Worker(code);
new Worker(code);

http://jsfiddle.net/MTJ27/81/

http://jsfiddle.net/MTJ27/81/

#2


9  

I have re-written Esailija's answer using the new blob constructor. BlobBuilder is now outdated, so you must use Blob() instead, see here for the deets: http://updates.html5rocks.com/2012/06/Don-t-Build-Blobs-Construct-Them

我使用新的blob构造函数重写了Esailija的答案。 BlobBuilder现在已经过时,所以你必须使用Blob(),请参阅这里的deets:http://updates.html5rocks.com/2012/06/Don-t-Build-Blobs-Construct-Them

window.URL = window.URL || window.webkitURL;

var blob = new Blob(["while(true){}"], {type: 'text/javascript'});

code = window.URL.createObjectURL(blob);

new Worker(code);
new Worker(code);
new Worker(code);
new Worker(code);

http://jsfiddle.net/MTJ27/15/

http://jsfiddle.net/MTJ27/15/

#1


20  

This uses 100% on my 2500K:

这在我的2500K上使用100%:

var code = "while(true){}";
var URL = window.webkitURL || window.URL;
var bb = new Blob([code], {type : 'text/javascript'});

code = URL.createObjectURL(bb);

new Worker(code);
new Worker(code);
new Worker(code);
new Worker(code);

http://jsfiddle.net/MTJ27/81/

http://jsfiddle.net/MTJ27/81/

#2


9  

I have re-written Esailija's answer using the new blob constructor. BlobBuilder is now outdated, so you must use Blob() instead, see here for the deets: http://updates.html5rocks.com/2012/06/Don-t-Build-Blobs-Construct-Them

我使用新的blob构造函数重写了Esailija的答案。 BlobBuilder现在已经过时,所以你必须使用Blob(),请参阅这里的deets:http://updates.html5rocks.com/2012/06/Don-t-Build-Blobs-Construct-Them

window.URL = window.URL || window.webkitURL;

var blob = new Blob(["while(true){}"], {type: 'text/javascript'});

code = window.URL.createObjectURL(blob);

new Worker(code);
new Worker(code);
new Worker(code);
new Worker(code);

http://jsfiddle.net/MTJ27/15/

http://jsfiddle.net/MTJ27/15/