2015-09-10 4 views
9

は 、ノードのスレッド自然についてthis great answerを読んだ後、私は、スレッドプールのサイズを変更するUV_THREADPOOL_SIZEシステム変数でプレイし始め、そして私が何か面白いものを見つけました:ノードは実際にいくつのスレッドを作成しますか?

私は

process.env.UV_THREADPOOL_SIZE = 10; 

を設定すると、私は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); 

それを実行した後、私は入力します。

ps -Lef | grep test.js | grep -v grep 

、以下の結果を得る:あなたがそこにある見ることができるように

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 

を15スレッド実行中。

UV_THREADPOOL_SIZE = 1と設定すると、6スレッドが得られます。

readFile行をコメントアウトすると(スレッドプールが初期化されないため)、スレッドが5つ取得されます。

私は、起動時のNodeが5つのスレッドを作成するという結論を下します。なぜ1ではない?

誰かがこれにいくつかの光を当てることができますか?

編集:私はブランドの新しいノードを使用してい 4.0.0

答えて

9

4つの余分なスレッドがfor use by V8をしています。 V8はこれらのスレッドを使用して、GC関連のバックグラウンド・タスクやコンパイラ・タスクの最適化などのさまざまなタスクを実行します。

+0

簡単明瞭に。ありがとう! :) – Curious

関連する問題