Re:Why I went from Python to Go (and not node.js)
by ricardobeat on Friday September 14, 2012 @06:34PM
(#4524336)
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_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.
}
Re:Why I went from Python to Go (and not node.js)
by ilaksh on Friday September 14, 2012 @08:36PM
(#4524715)
The idea with node is that you dont normally need multiple threads or processes because you have nonblocking io.
http = require 'http'
server = http.createServer 'localhost', (req, res) ->
res.writeHead 200
res.end 'ok'
app = server.listen 3000
In any case, it's still not an apples to apples comparison. The node.js example forks separate processes that share nothing, while in the Go example it all runs in one process so the HTTP handlers can communicate with each other via channels or other shared data structures.