3 ms·
Shared-nothing is a design decision (and runtime/language limitation), due to the single-threaded nature of js. The workers can communicate with the master via
by ricardobeat 14y ago
Shared-nothing is a design decision (and runtime/language limitation), due to the single-threaded nature of js. The workers can communicate with the master via message passing: http://nodejs.org/api/cluster.html#cluster_worker_send_message_sendhandle http://nodejs.org/api/cluster.html#cluster_worker_send_messa...
The documentation has the primary goal of explaining how things work, not being the canonical style guide.
Take a similar example from the Go documentation:
const NCPU = 4 // number of CPU cores
func (v Vector) DoAll(u Vector) {
c := make(chan int, NCPU) // Buffering optional but sensible.
for i := 0; i < NCPU; i++ {
go v.DoSome(i*len(v)/NCPU, (i+1)*len(v)/NCPU, u, c)
}
// Drain the channel.
for i := 0; i < NCPU; i++ {
<-c // wait for one task to complete
}
// All done.
}