4 ms·
You should update the node.js docs if you consider the original JS snippet ugly, because that's where I pulled the original code sample from verbatim. In any c
by enneff 14y ago
You should update the node.js docs if you consider the original JS snippet ugly, because that's where I pulled the original code sample from verbatim.
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.
- ricardobeat 14y agoShared-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. }
- exogen 14y agoRead again, he didn't say it was ugly. He just pointed out that it wasn't 1:1 because the Go code omitted the logging and comments. A valid criticism.
- ilaksh 14y agoThe 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
- ilaksh 14y agoI made a mistake, did not mean to include 'localhost' in there.