5 ms·
> The nodejs model for high concurrency I keep reading this and I don't understand. ¿How can a single thread process be concurrent?
by mcosta 12y ago
> The nodejs model for high concurrency
I keep reading this and I don't understand. ¿How can a single thread process be concurrent?
- mateo411 12y agoTwisted, 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.
- deleted 12y ago[deleted]
- fbuilesv 12y agoTraditionally in CS, concurrent != parallel. If you have a blocking operation (say a database read) your program can do something else while it waits for a response from the DB (this gives you pseudo-parallelism). That is the concurrency that evented frameworks like Node or EventMachine are usually associated with.