2015-04-02 76 views
-1

所以出於好奇,我想在nodejs中創建自己的線程池,從中可以並行運行多個線程?一直期待webworker-threadsnpool但不是很瞭解它..如何在nodejs中創建線程池?

是否有可能在nodejs中創建一個線程池? 也如何執行線程數/線程/ chid_processes創建池中的線程數?像是分佈式系統?

回答

2

是的,git上有一個開源項目叫做Threads gogo,它是爲節點編寫的。線程àgogo(*)是Node.js的本地模塊,它爲移動阻塞/冗長的CPU綁定任務提供異步,均勻和/或延續傳遞樣式API從節點的事件循環中移出到在後臺並行運行並且自動使用所有可用CPU核心的JavaScript線程;全部來自單個節點進程。

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

相關問題