Reputation: 2493
Let's say I have a machine running 5 different nodejs processes. Does each node process have its own libuv thread pool, or do they all share a global threadpool?
I'm confused because I'd asume libuv threadpool is per-process, but in libuv documentation (http://docs.libuv.org/en/latest/threadpool.html) it says:
The threadpool is global and shared across all event loops
I'm not sure if I'm really understanding what does "all event loops" mean.
So, going back to my example. If I have 5 nodejs processes, and given that the default threadpool size for libuv is 4, do I end up using:
a) 9 threads: 5 nodejs event loops + 4 libuv threads for a global threadpool
b) 25 threads: 5 nodejs event loops + (5 * 4) libuv threads for having 5 different threadpools each with 4 threads.
c) none of the above?
Thanks!
Upvotes: 3
Views: 565
Reputation: 106698
When the documentation says "all events loops" it's referring to all libuv event loops in the same process. The "global" part being referred to is within the bounds of a single process.
There is no way for libuv to coordinate with arbitrary child processes to ensure only so many threads are used system-wide amongst all processes using libuv. That would probably require a configuration file or something, which libuv does not utilize.
So if you have 5 node processes, then assuming each process is using the default libuv thread pool size, you would have a total of 20 libuv threads (5 processes * 4 threads each). Now keep in mind each process will have more than 4 threads, but not all of those are libuv threads. For example, you have the main thread that is used for javascript execution, but there are also threads that V8 uses for various tasks like optimizing code, garbage collection, etc..
Upvotes: 5