Node doesn't always use a thread pool. At its core it relies on operating system's ability to intimate it about certain events, for example kequeue, epoll etc.
The burden of actually executing the async operation and notifying node lies with OS. But for cases where that's not possible, it falls back to the threadpool. For example dns resolution is handled by thread pool, but file and socket operations are mostly OS.
Instead of forking (crude-cloning) processes into splitted (distinct) context for each child process,
we instead employ workers (CPU heavy computations e.g. for DNS lookup) within single-threaded-context (thread pool) . I see workers (a.k.a. threads) as some sort of virtualization (optimization) within same boundaries of memory (RAM) at time . This image helped me a lot to comprehend what I stated in my comment above ; I'll be honest I may be mistaken , always welcome to give alternative argument for that .
That's a nice article! Although, just to re-iterate, I was talking about the threadpool which libuv maintains.
A very brief explaination :
As I mentioned, at its core, node expects the OS to do the heavylifting. And different Operating Systems have different mechanism of doing that, hence node folks built an abstraction library called libuv. This library abstracts event loop and the OS interactions(fun fact, you can use this lib stand alone).
Now, let's say there's an operation which node wants to do differently, or there's something which OS can't handle or doesn't support. To manage such scenarios libuv has its own threadpool, and this threadpool(default size 4) simulates the async behavior which node expects from OS.
Node doesn't always use a thread pool. At its core it relies on operating system's ability to intimate it about certain events, for example kequeue, epoll etc.
The burden of actually executing the async operation and notifying node lies with OS. But for cases where that's not possible, it falls back to the threadpool. For example dns resolution is handled by thread pool, but file and socket operations are mostly OS.
How do you know this? Did you read this somewhere or did you come across some system tool which helped you to see this? Please let us know...
Checkout the following resources:
dev.to/iostreamer/comment/1n64e
dev.to/iostreamer/threads-in-nodej...
youtu.be/PNa9OMajw9w
Thanks for adding up☺️
Instead of forking (crude-cloning) processes into splitted (distinct) context for each child process,
we instead employ workers (CPU heavy computations e.g. for DNS lookup) within single-threaded-context (thread pool) . I see workers (a.k.a. threads) as some sort of virtualization (optimization) within same boundaries of memory (RAM) at time . This image helped me a lot to comprehend what I stated in my comment above ; I'll be honest I may be mistaken , always welcome to give alternative argument for that .
That's a nice article! Although, just to re-iterate, I was talking about the threadpool which libuv maintains.
A very brief explaination :
As I mentioned, at its core, node expects the OS to do the heavylifting. And different Operating Systems have different mechanism of doing that, hence node folks built an abstraction library called
libuv
. This library abstracts event loop and the OS interactions(fun fact, you can use this lib stand alone).Now, let's say there's an operation which node wants to do differently, or there's something which OS can't handle or doesn't support. To manage such scenarios libuv has its own threadpool, and this threadpool(default size 4) simulates the async behavior which node expects from OS.