zaharpopov zaharpopov - 9 months ago 99
Javascript Question

Node.js on multi-core machines

Node.js looks interesting, BUT I must miss something - isn't Node.js tuned only to run on a single process and thread?

Then how does it scale for multi-core CPUs and multi-CPU servers? After all, it is all great to make fast as possible single-thread server, but for high loads I would want to use several CPUs. And the same goes for making applications faster - seems today the way is use multiple CPUs and parallelize the tasks.

How does Node.js fit into this picture? Is its idea to somehow distribute multiple instances or what?

Answer Source

I can't delete this answer, but it's outdated, now. For a more detailed answer, see Dave Dopson's below.

Node.js doesn't support multiple CPUs out of the box, yet as per the web page:

But what about multiple-processor concurrency? Threads are necessary to scale programs to multi-core computers. Processes are necessary to scale to multi-core computers, not memory-sharing threads. The fundamentals of scalable systems are fast networking and non-blocking design—the rest is message passing. In future versions, Node.js will be able to fork new processes (using the Web Workers API), but this is something that fits well into the current design.

But you can still use the other cores; you just have to write more code. It's not something that Node.js will do automatically for you. On the positive side, this gives you more control.