Node实际创建了多少个线程?

Ole*_*leg 22 multithreading threadpool node.js libuv

在阅读关于Node的线程性质的这个很好的答案后,我开始使用UV_THREADPOOL_SIZE系统变量来改变线程池的大小,我发现了一些有趣的东西:

当我设置

process.env.UV_THREADPOOL_SIZE = 10;
Run Code Online (Sandbox Code Playgroud)

我的Node进程中有15个线程(我认为它应该是10 + 1主节点线程= 11).

看看我的剧本:

process.env.UV_THREADPOOL_SIZE = 10;

//init thread pool by calling `readFile` function
require('fs').readFile(__filename, 'utf8', function(err, content) {});

//make node not exiting
setInterval(function() {}, 1000);
Run Code Online (Sandbox Code Playgroud)

运行后我输入:

ps -Lef | grep test.js | grep -v grep
Run Code Online (Sandbox Code Playgroud)

并获得以下结果:

olegssh   4869  4301  4869  0   15 16:38 pts/0    00:00:00 /home/olegssh/node/bin/node test.js
olegssh   4869  4301  4870  0   15 16:38 pts/0    00:00:00 /home/olegssh/node/bin/node test.js
olegssh   4869  4301  4871  0   15 16:38 pts/0    00:00:00 /home/olegssh/node/bin/node test.js
olegssh   4869  4301  4872  0   15 16:38 pts/0    00:00:00 /home/olegssh/node/bin/node test.js
olegssh   4869  4301  4873  0   15 16:38 pts/0    00:00:00 /home/olegssh/node/bin/node test.js
olegssh   4869  4301  4874  0   15 16:38 pts/0    00:00:00 /home/olegssh/node/bin/node test.js
olegssh   4869  4301  4875  0   15 16:38 pts/0    00:00:00 /home/olegssh/node/bin/node test.js
olegssh   4869  4301  4876  0   15 16:38 pts/0    00:00:00 /home/olegssh/node/bin/node test.js
olegssh   4869  4301  4877  0   15 16:38 pts/0    00:00:00 /home/olegssh/node/bin/node test.js
olegssh   4869  4301  4878  0   15 16:38 pts/0    00:00:00 /home/olegssh/node/bin/node test.js
olegssh   4869  4301  4879  0   15 16:38 pts/0    00:00:00 /home/olegssh/node/bin/node test.js
olegssh   4869  4301  4880  0   15 16:38 pts/0    00:00:00 /home/olegssh/node/bin/node test.js
olegssh   4869  4301  4881  0   15 16:38 pts/0    00:00:00 /home/olegssh/node/bin/node test.js
olegssh   4869  4301  4882  0   15 16:38 pts/0    00:00:00 /home/olegssh/node/bin/node test.js
olegssh   4869  4301  4883  0   15 16:38 pts/0    00:00:00 /home/olegssh/node/bin/node test.js
Run Code Online (Sandbox Code Playgroud)

如您所见,有15个线程正在运行.

如果我设置UV_THREADPOOL_SIZE = 1,我得到6个线程.

如果我注释掉该readFile行(所以线程池没有初始化),我得到5个线程.

所以我得出结论,启动时Node创建了5个线程.为什么不是1?

有人可以对此有所了解吗?

编辑:我正在使用全新的Node 4.0.0

msc*_*dex 23

4个额外的线程供V8使用.V8使用这些线程执行各种任务,例如与GC相关的后台任务和优化编译器任务.