Suppose you have a task on your webapp that demands maximum performance. The task is highly parallelizable: you can subdivide it on, say, 500 independent subtasks. What is the best solution?
If (B) is the way to go, how can you determine (empirically if needed) the best value for t? Is there any library to solve this particular problem?
You can spawn as many workers as you wish. You can also pass data to the script being executed in the worker threads and also return value to the main thread upon completion.
Web Workers are primarily used for CPU-intensive tasks to be run in the background without any network connectivity required to work on the tasks.
Web Workers run in an isolated thread. As a result, the code that they execute needs to be contained in a separate file.
Web Workers are a simple means for web content to run scripts in background threads. The worker thread can perform tasks without interfering with the user interface.
Use navigator.hardwareConcurrency for optimal number of web workers.
Browser support - http://caniuse.com/#search=hardwareConcurrency
Polyfill for non-supported browser versions - https://oswg.oftn.org/projects/core-estimator/demo/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With