简体   繁体   English

Java中的Web worker,线程数和worker?

[英]Web workers in Javascript, number of threads and workers?

If I understand it right Web Workers run in a single isolated thread , therefore I don't get the point of creating multiple Workers. 如果我理解正确,则Web Workers单个隔离的线程中运行,因此,我并不想创建多个Workers。

I have found this demo https://nerget.com/rayjs-mt/rayjs.html , that shows performance benefits of using workers for rendering a cube on a canvas. 我已经找到了这个演示https://nerget.com/rayjs-mt/rayjs.html ,该演示显示了使用工作程序在画布上渲染多维数据集的性能优势。

I have tried to use 5 and 15 Workers. 我尝试使用5和15个工人。 Don't see any significant difference in rendering speed. 渲染速度没有明显差异。

Is there any point to create a lot of Web Workers? 创建许多Web Workers有什么意义吗? If yes, what would be the right number? 如果是,正确的电话号码是什么?

Any help will be appreciated! 任何帮助将不胜感激!

A worker may run on another thread, or may not. 一个工作程序可以在另一个线程上运行,也可以不运行。 If you create too much threads, they don't actually run at the same time: this behaviour is emulated. 如果创建过多的线程,它们实际上不会同时运行:此行为是模拟的。 Because of the time required to send / receive messages to / from a worker, it might actually hurt your performances to create too much workers. 由于向工作人员发送消息/从工作人员接收消息需要时间,因此创建过多的工作人员实际上可能会损害您的表现。

More informations can be found 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. 当时间片用完时,调度程序将挂起线程,并允许等待该线程的下一个线程在硬件线程上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM