How to create a thread pool in nodejs? [duplicate]

强颜欢笑 提交于 2019-12-14 03:27:33

问题


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..

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?


回答1:


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

TAGG: Threads à gogo for Node.js Threads à 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



来源:https://stackoverflow.com/questions/29418424/how-to-create-a-thread-pool-in-nodejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!