Alex.Xing
Alex.Xing

Reputation: 1

How to set thread size of libuv in nodejs?

  1. I have write a demo in nodejs like this:

hello.js:

var http = require(‘http’);
while(true){
    console.log(process.env.UV_THREADPOOL_SIZE);
}
  1. I monitor the process and threads with 'pstree -p | grep node' after starting the program above.

  2. I have tried 3 ways to edit thread size but none of them works: 1) Set the paramters when starting: 'UV_THREADPOOL_SIZE=100 node hello.js' 2) add path in the etc/profile and reboot the system:export UV_THREADPOOL_SIZE=100 3) add 'process.env.UV_THREADPOOL_SIZE=100' in the code.

  3. the results of the monitor are the same:

enter image description here

There is only 5 threads work in the node process (4 are work threads and 1 is loop thread)

My nodejs is v6.9.x. Have anyone used this successfully?

Upvotes: 0

Views: 1298

Answers (1)

Mitesh
Mitesh

Reputation: 11

You can set the environment variable UV_THREADPOOL_SIZE , as of this writing the max limit is 128.

If you want you can also set this env variable within your node app rather than at the shell.

Upvotes: 1

Related Questions