本文介绍了如何在Node.js中创建线程池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此出于好奇,我想在nodejs中创建自己的线程池,从中我可以并行运行多个线程?一直在寻找 webworker-threads npool ,但对此了解不多.

So out of curiosity, I was thinking of creating my own thread pool in nodejs from which I can run number of threads in parallelly? Been looking to webworker-threads and npool but not being to understand much from it..

是否可以在nodejs中创建线程池?另外,如何从并行线程/chid_processes中创建的池中执行线程数?像是分布式系统?

Is it possible to create a thread pool in nodejs?Also how to execute number of threads from the pool created in parallel number of threads/chid_processes? Like is distributed system?

推荐答案

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

Yes there is an open source project on git called Threads a gogo written for node.

TAGG:Node.js的线程àgogo线程àgogo(*)是Node.js的本机模块,它提供异步,事件和/或连续传递样式API,用于将阻塞/冗长的CPU绑定任务从Node的事件循环中移出到JavaScript线程中,该线程在后台并且自动使用所有可用的CPU内核;所有这些都来自单个Node进程.

TAGG: Threads à gogo for Node.jsThreads à gogo (*) is a native module for Node.js that provides an asynchronous, evented and/or continuation passing style API for moving blocking/longish CPU-bound tasks out of Node's event loop to JavaScript threads that run in parallel in the background and that use all the available CPU cores automatically; all from within a single Node process.

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

这篇关于如何在Node.js中创建线程池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-16 02:19