如何在nodejs中创建线程池

How to create a thread pool in nodejs?

本文关键字:创建 线程 nodejs      更新时间:2023-09-26

所以出于好奇,我想在nodejs中创建自己的线程池,从中可以并行运行多个线程?一直在寻找webworker线程和npool,但没有从中了解太多。

有可能在nodejs中创建线程池吗?此外,如何从并行创建的池中执行线程数/chid_processes?分布式系统是什么?

是的,git上有一个开源项目,名为Threads,是为节点编写的gogo。

TAGG:Threadsàgogo for Node.jsThreadsàgogo(*)是Node.js的一个原生模块,它提供了异步、事件和/或连续传递风格的API,用于将阻塞/长CPU绑定任务从Node的事件循环转移到后台并行运行的JavaScript线程,并自动使用所有可用的CPU内核;所有这些都来自单个Node进程。

Installing the module
With npm:
npm install threads_a_gogo
From source:
git clone http://github.com/xk/node-threads-a-gogo.git
cd node-threads-a-gogo
node-gyp rebuild
# It also works with node-waf, but this is outdated, so please use node-gyp nowdays.
To include the module in your project:
var threads_a_gogo= require('threads_a_gogo');

https://github.com/xk/node-threads-a-gogo