Javascript 中的 Web worker,线程和 worker 的数量?

Web workers in Javascript, number of threads and workers?

如果我理解正确 Web Workers 运行 在 单个隔离线程 中,因此我不明白创建多个工人的点。

我找到了这个演示 https://nerget.com/rayjs-mt/rayjs.html , 这显示了使用 worker 在 canvas 上渲染多维数据集的性能优势。

我试过用5个和15个Worker。看不到渲染速度有任何显着差异。

创建大量Web Worker 有什么意义吗?如果是,正确的数字是多少?

任何帮助将不胜感激!

工人 可以 运行 在另一个线程上,也可以不。如果您创建了太多线程,它们实际上不会同时 运行:这种行为是被模拟的。由于向 worker 发送消息/从 worker 接收消息需要时间,因此创建过多 worker 实际上可能会损害您的性能。

可以找到更多信息 here

It is important to distinguish software threads from hardware threads. Software threads are the threads that programs create. Hardware threads are real physical resources. There may be one hardware thread per core on the chip, or more, as for example with Intel Hyper-Threading Technology.

When there are more software threads than hardware threads, the operating system typically resorts to round robin scheduling. Each software thread gets a short turn, called a time slice, to run on a hardware thread. When the time slice runs out, the scheduler suspends the thread and allows the next thread waiting its turn to run on the hardware thread.