简体   繁体   English

Web Worker的最佳数量

[英]Optimal number of Web Workers

Suppose you have a task on your webapp that demands maximum performance. 假设您的webapp上有一项要求最高性能的任务。 The task is highly parallelizable : you can subdivide it on, say, 500 independent subtasks. 该任务具有高度可并行性 :您可以将其细分为500个独立子任务。 What is the best solution? 什么是最好的解决方案?

  • (A) Merely spawn 500 Web Workers. (A)仅产生500名Web Worker。
  • (B) Spawn a small amount t of Web Workers and make them consume those 500 tasks. (B)产卵的Web工人少量 ,并使它们消耗这些500个任务。

If (B) is the way to go, how can you determine (empirically if needed) the best value for t ? 如果(B)是要走的路,你如何确定(根据经验,如果需要) t的最佳值? Is there any library to solve this particular problem? 有没有图书馆可以解决这个特殊问题?

Use navigator.hardwareConcurrency for optimal number of web workers. 使用navigator.hardwareConcurrency获得最佳Web工作者数量。

Browser support - http://caniuse.com/#search=hardwareConcurrency 浏览器支持 - http://caniuse.com/#search=hardwareConcurrency

Polyfill for non-supported browser versions - https://oswg.oftn.org/projects/core-estimator/demo/ Polyfill适用于不受支持的浏览器版本 - https://oswg.oftn.org/projects/core-estimator/demo/

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

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