NodeJS C ++本机模块:创建指定的线程池

时间:2016-04-18 18:31:37

标签: c++ node.js threadpool native libuv

对于我正在开发的应用程序,我需要并行启动共享库的实例。

由于我希望对并行实例的数量进行细粒度控制(-license of library限制并行数量到固定数量的线程),我想知道是否有一种简单的方法来创建和维护本机模块中的自己的线程池?

谢谢!

1 个答案:

答案 0 :(得分:0)

Basically we must set the UV_THREADPOOL_SIZE environment variable before the thread pool is created.

This can be done in three ways:

  1. Putting this line in your .bashrc file will affect all the opened node processes under that user

    export UV_THREADPOOL_SIZE=10
    
  2. Set it before the process is open

    UV_THREADPOOL_SIZE=10 node myscript.js
    
  3. Set it inside the javascript, in the first line:

    process.env.UV_THREADPOOL_SIZE = 10;