Why does my activity monitor show Node.js using multiple threads?
Asked Answered
J

1

9

I opened my activity monitory in OSX to to see how Node was getting along and to my surprise it's using 8 threads. How can in be!!?

Node with 8 threads

Judo answered 7/2, 2014 at 18:25 Comment(6)
Well, is it working OK?Strum
I think he's confused because Node is single threaded, not because something isn't working correctly.Polyunsaturated
@MartinJames, yes it's working just fine. I'm just curious.Judo
possible duplicate of How is Node.js inherently faster when it still relies on Threads internally?Himelman
Node is single-threaded from a user application context; it is free to use multiple threads inside the engine.Ritter
Every IO operation and many other things does use behind the scenes threads (from libraries) to keep you application context unblocked.Fuegian
S
9

Node.js is single-threaded.

However, it is built on libuv which handles all low-level platform-dependent stuff, including async IO.

Now the issue is that there is no good API for async IO in operating systems nowadays. Different APIs exist, but they all have their issues.

So in order to implement cross-platform async API, libuv emulates it using a thread pool. This is where those threads are coming from.

Sublieutenant answered 8/2, 2014 at 0:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.