views:

1417

answers:

8

node.js looks interesting BUT...

I must miss something - isn't node.js tuned only to run on a single process & 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?

+21  A: 

node.js can't use multiple CPUs, 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 will be able to fork new processes (using the Web Workers API ), but this is something that fits well into the current design.

Aaron Digulla
+12  A: 

One method would be to run multiple instances of node.js on the server and then put a load balancer (preferably a non-blocking one like nginx) in front of them.

Chandru
node.js is about as fast as nginx, you could put a node.js load balancer in front of your node.js servers if you wanted to as well :)
mikeal
ryan specifically said not to do this until node was more stable. Best way is to run nginx in front of node.
resopollution
as for nginx in front of node, it won't solve certain problems like if you have an in-memory queue. 2 node instances will not be able to access each other's queue.
resopollution
A: 

Well, Javascript Language itself isn't scale for multiple-processor concurrency from the start.

And most of the language which supports concurrency still need to write specific codes to do that, Javascript cannot touch such low level processing.

So it might need V8 team to re-design it to support that feature as they mentioned.

In future versions, Node will be able to fork new processes (using the Web Workers API ), but this is something that fits well into the current design.

S.Mark
+4  A: 

Future version of node will allow you to fork a process and pass messages to it and Ryan has stated he wants to find some way to also share file handlers, so it won't be a straight forward Web Worker implementation.

At this time there is not an easy solution for this but it's still very early and node is one of the fastest moving open source projects I've ever seen so expect something awesome in the near future.

mikeal
+1  A: 

It's also possible to design the web-service as several stand alone servers that listen to unix sockets, so that you can push functions like data processing into seperate processes.

This is similar to most scrpting/database web server architectures where a cgi process handles business logic and then pushes and pulls the data via a unix socket to a database.

the difference being that the data processing is written as a node webserver listening on a port.

it's more complex but ultimately its where multi-core development has to go. a multiprocess architecture using multiple components for each web request.

Fire Crow
+1  A: 

I'm using

Node worker

To run processes in a simple way from my main process. Seems to be working great while we wait for the official way to come around.

Cheers

Christian

christkv
+3  A: 

Multi-node harnesses all the cores that you may have.
Have a look at http://github.com/kriszyp/multi-node.

For simpler needs, you can start up multiple copies of node on different port numbers and put a load balancer in front of them.

CyberED
+2  A: 

This link could provide valuable insight on node.js with multi-code processor.

http://developer.yahoo.net/blog/archives/2010/07/multicore_http_server_with_nodejs.html#1

And here are some threads talking about node.js on multicore processors.

http://groups.google.com/group/nodejs/browse_thread/thread/36146559c089dca0

Rosdi