- I have learned that node.js use libeio internally to perform async file I/O, with thread pool, on *nix platform, am I right?
- What about async network I/O? Is it done by libev? Is there also a thread pool?
- If there is thread pool inside, how could it be more efficient than traditional one-thread-per-request model? And is it one thread per I/O request?
- And what's the mechanism on windows? I know it's done by IOCP, and there's a kernel level thread pool, right?
- Why linux doesn't have a native completely AIO mechanism like windows IOCP yet? Will it have in future?
Update according to changchang's answer:
- I took a quick view at the source code @changchang have given, found that the default thread pool size can be reset by UV_THREADPOOL_SIZE, I'm wondering in which case this will be used?
- I also found getaddrinfo use this thread pool, is there any more except fs? And if all sync jobs will be done in this thread pool, is the default size '4' enough?
- As my understanding now, there will be 6 basic threads in node.js process: 1 V8 thread(event loop, where user javascript codes runs), 1 libuv event loop, and 4 in thread pool, am I right?
And how can I see these threads in my shell(Ubuntu)? I use ps -eLf | grep node | grep -v grep only saw two:
root 16148 7492 16148 0 2 20:43 pts/26 00:00:00 ./bin/node /home/aaron/workspace/test.js
root 16148 7492 16149 0 2 20:43 pts/26 00:00:00 ./bin/node /home/aaron/workspace/test.js
Uptil version 0.6 node used libev
to run event-loop and libeio
for asynchronous I/O, (Unix backend sits heavily on these two libraries). But libuv
has started replacing libev
and libeio
in version 0.8. It performs, mantains and manages all the io and events in the event pool. libuv
is the choice in cross-platform asynchronous IO libraries.
- Yes, upto node 0.6, deprecated in 0.8 and uses thread pool
Yes, but libev
does not use thread pool. See here
Clarification : According to the link in the question I posted, libeio
does support all POSIX functions dealing with I/O (which includes socket). But node author decided to use it for async file I/O only, and uses libev
for network I/O. I dont know where you heard it from but you can use epoll on regular files.
libev
uses event loop so no problems here.
- Yes IOCP handles async I/O in windows, kernel does use thread pools.
- New linux kernel has epoll, kqueue in new BSD kernel.
libev
and libeio
were for linux environment and provides event loop/async IO for all kernel (supports select, poll, epoll, kqueue).
Update questions:
- dont know much about
libuv
- maybe enough (dont know)
Here are my findings on Windows 8, checked it via Process Explorer. Showed 4 threads, 1 DLL, 1 File and 1 Section (total 7 entries) for a node application process.
ps -eLf
does show all threads and processes, maybe you are over-filtering it, just look for the node process pid like ps -eLf | grep x
where x is pid for node process.