3

If I understand it right Web Workers run in a single isolated thread, therefore I don't get the point of creating multiple 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.

I have tried to use 5 and 15 Workers. Don't see any significant difference in rendering speed.

Is there any point to create a lot of Web Workers? If yes, what would be the right number?

Any help will be appreciated!

2
  • For me the results of that demo are not consistent unless the same test is run about 5 times in a row. Commented Nov 19, 2015 at 16:28
  • @DavidSherret - for me the same, sometimes 2 workers render the cube faster than 5.. And that is the question if there is a point to use many of them.. Commented Nov 19, 2015 at 16:54

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.