Reputation: 1208
While doing some research on Node.js and libuv I started a simple node server with UV_THREADPOOL_SIZE=1
and looked at pstree to see how much threads it really uses.
for Node.js 0.10 pstree -p | grep node
produces
node(5157)-+-{node}(5158)
`-{node}(5162)
To make things a bit more complicated I also tried the same with 0.12 and iojs 3.3. The number of threads differs for every version.
Total number of threads vs thread pool size
0.10: UV_THREADPOOL_SIZE + 1
0.12: UV_THREADPOOL_SIZE + 2
3.3: UV_THREADPOOL_SIZE + 4
I also tried to set higher numbers for the thread pool size to make sure that I'm not below some minimum value.
My questions are:
Upvotes: 1
Views: 1113
Reputation: 2010
I can't really speak for the Node/V8 part, but in general amy libuv application will use at least 1 + UV_THREADPOOL_SIZE threads.
The first thread is the one which runs the libuv loop by calling uv_run, which is usually the main thread. libuv then has a thread pool of UV_THREADPOLL_SIZE size, where filesystem and DNS operations are run. Network i/o is performed in the loop thread by using epoll / kqueue, etc.
Upvotes: 3