3 ms·
Twisted, Nodejs and all of these other frameworks use the select system call under the hood. This works well when the process is IO bound. Processes that are re
by mateo411 12y ago
Twisted, Nodejs and all of these other frameworks use the select system call under the hood. This works well when the process is IO bound. Processes that are responding the HTTP requests or reading or writing to databases tend to be IO bound.
The select system call takes a set of file descriptors and returns which file descriptors you can read, because new data is available to read. These frameworks read from these file descriptors and dispatch the new data to a callback method. The event loop only processes one thing at a time, because it is single threaded. However, since reading from the file descriptor and processing the callback is usually fast, this scales very well. Once again, it only scales well for IO bound operations. This uses less memory than having a single thread for each HTTP request, and it definitely uses less memory than having a single process for each HTTP request.