When a request comes into a nodejs server, how does it handle the request?
I understand it has a different way of handling requests, as it doesn’t spawn a new thread for each request (or I guess it doesn’t use a traditional thread pool either).
Can someone explain to me what is going on under the hood, and does the flavour of linux matter here?
Node tells the operating system (through
epoll,kqueue,/dev/poll, orselect) that it should be notified when a new connection is made, and then it goes to sleep. If someone new connects, then it executes the callback. Each connection is only a small heap allocationIt is “event driven” where it handles IO in an async fashion (non blocking I/O). It internally does threading needed to do
epoll,kqueue,/dev/poll, orselecthandling, but for you as a user/client it is absolutely transparent.e.g. epoll is not really a thread pool, but an OS’ I/O event notification facility, that
node.jssits on top of.