Nach this great answer über Knoten Thread Natur zu lesen, begann ich mit UV_THREADPOOL_SIZE
Systemvariable zu spielen, um die Größe des Thread-Pools zu ändern, und ich fand etwas Interessantes:Wie viele Threads erstellt der Knoten tatsächlich?
Als ich
process.env.UV_THREADPOOL_SIZE = 10;
Set I 15 erhalten Threads in meinem Node-Prozess (ich dachte, es sollte 10 + 1 Hauptknoten Thread = 11 sein).
Werfen Sie einen Blick auf mein Skript:
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);
Nach dem Ausführen Typ I:
ps -Lef | grep test.js | grep -v grep
und die folgenden Ergebnisse erhalten:
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
Wie Sie sehen können gibt es sind 15 Threads laufen.
Wenn ich UV_THREADPOOL_SIZE = 1
setze, erhalte ich 6 Threads.
Wenn ich die readFile
Zeile auskommentieren (so dass der Threadpool nicht initialisiert wird), erhalte ich 5 Threads.
So mache ich eine Schlussfolgerung, dass Knoten beim Start 5 Threads erstellt. Warum nicht 1?
Kann jemand etwas Licht darauf werfen?
Edit: ich ganz neu Knoten bin mit 4.0.0
Kurz und deutlich. Vielen Dank! :) – Curious