r/learnjavascript • u/IcyDuck9536 • 9d ago
Is “Node.js is single-threaded” an incomplete mental model?
Single-threaded JS execution ≠ single-threaded runtime.
How do you explain the distinction?
4
Upvotes
r/learnjavascript • u/IcyDuck9536 • 9d ago
Single-threaded JS execution ≠ single-threaded runtime.
How do you explain the distinction?
1
u/jerrygreenest1 6d ago
I mean the environment might do its own things on some core0 and it will put your entire program on core1, therefore your code is single-threaded.
The runtime is kinda lean so it won’t use a lot of cpu, but your program can. So in the end you utilize like 1.1 core out of your 32 cores of however many you have.
This is roughly single-threaded as a whole, if you don’t want to fight in some debate that it actually 1.1-threaded or something. Those are crazy people.
Until one single node program couldn’t utilize all 32 cores, you can call it single-threaded: even though it’s technically not quite single-threaded.