I have noticed that when spawning a very simple node process, htop
will show multiple (what I learned today is called) userland process threads.
echo "setInterval(() => console.log(' '), 1000);" > test.js
node test.js
# while node is running, somewhere else:
htop
What I see now in htop, filtering by the script name:
- the main process (indicated in white color, with little but increasing CPU time)
- some (~5 or 6, depending on the machine?!) green lines, indicating userland process threads. Some of them seem to gather a tiny bit of CPU time.
- Oddly enough, this only happens on my linux machines (tested on two, bionic and xenial ubuntu). On MacOS, it only shows a single process. This might be related to mismatching htop versions though …
Most search results around node and threads talk about worker threads, but I don't assume they're involved here. The behavior is similar even on node v8, where there was no such thing (and also, I'm not creating them, or even importing the worker_threads
module).
Answers such as this one and this one talk about an internal thread pool. But the numbers don't match (supposedly, there should be only 4 extra threads), and not seeing them on MacOS also doesn't make sense to me, and node creating them in the first place when there is no I/O whatsoever seems weird as well.
My questions:
- Am I right in assuming that those threads have nothing to do with worker threads?
- What is the purpose of those threads? Do they indeed belong to the internal thread pool?
- If they do, why do I get more than 4 (without
UV_THREADPOOL_SIZE
being set)? And none on MacOS?
Versions:
- Ubuntu 16 and 18 LTS
- MacOS 11.2, both m1 and intel chips
- Node 8 and 14 (tested both versions on all OSes, results stay the same)
- htop 2.1 (on linux) and 3.0 (on MacOS)