3 ms·
Is node really single threaded?!? What do people use it for? Interactive Prodigy games, or trawling AOL forums?
by hedora 9y ago
Is node really single threaded?!?
What do people use it for? Interactive Prodigy games, or trawling AOL forums?
- donatj 9y agoThey use it to spend hours of their day hiding the fact that it’s single threaded by doing EVERYTHING asynchronously. It’s a great time sink.
- nallerooth 9y agoAfter spending quite a lot of time trying to track down a memory leak in asynchronous JavaScript, opening up a PHP project felt really comfy.
- wmil 9y agoIt's the whole point of node. Instead of threading it's all async. Then you just spawn more processes to take advantage of your additional cores. It's a simpler model than trying to make everything thread safe and guess the correct number of threads.
- jhomedall 9y agoI don't use Node, but my understanding is as follows: Rather than blocking the thread on IO, you instead arrange for a callback to be executed once your IO operation is completed. The thread is then free to work on other tasks (e.g. other requests) while that operation is in progress. As a result, the thread is always busy. The main disadvantages of this are that you are switching from straightforward top-down code to a continuation-passing style (mitigated somewhat by promises and async functions), and the fact that CPU-bound code will prevent other tasks from being serviced during execution. There are similar facilities available in most languages now (including syntax sugar to help with things, such as C# through the async feature, and F# through the async computational expression), except that you also have the benefit of multiple threads.