Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has anyone tried using the UV_THREADPOOL_SIZE environment variable?

Tags:

node.js

One of the changes made by Ben Noordhius in Node v0.10.0 was to "honor UV_THREADPOOL_SIZE environment variable" in Unix. The "threadpool.c" source file seems to do just that.

If I don't set this env variable, I can verify that I am limited to a threadpool of 4 threads, which is the default size of the threadpool.

But I set this environment variable on my Linux server to 64 and then restart Node, but I still seem to be limited, seemingly to a threadpool of size of 5?!

Does this make any sense to anyone? Thanks!

like image 624
user2330260 Avatar asked Jul 09 '13 17:07

user2330260


2 Answers

It seems that you must set it the var with node command or from inside the node program. Execute it like:

UV_THREADPOOL_SIZE=64 node

or modify from program :

process.env.UV_THREADPOOL_SIZE=64
//then execute some function that requires threadpool
require('fs').readFile('testing',function(){});

Testing threads:

ps -Lef | grep  "\<node\>" | wc -l
67
like image 175
user568109 Avatar answered Oct 04 '22 05:10

user568109


If you're running a Windows OS and running via a .js file you'll need to set the UV_THREADPOOL_SIZE prior to calling the script via node.

Example in cmd: SET UV_THREADPOOL_SIZE=2 && node my-file-to-run.js (no spaces around the =)

Or in Powershell: $env:UV_THREADPOOL_SIZE = 2 && node my-file-to-run.js

like image 23
mche Avatar answered Oct 04 '22 05:10

mche