var cluster = require(‘cluster’); var http = require(‘http’); var numCPUs = require(‘os’).cpus().length;
if (cluster.isMaster) { // Fork workers. for (var i = 0; i < numCPUs; i++) { cluster.fork(); }
cluster.on('exit’, function(worker, code, signal) { console.log(‘worker ' + worker.process.pid + ' died’); }); } else { // Workers can share any TCP connection // In this case its a HTTP server http.createServer(function(req, res) { res.writeHead(200); res.end(“hello world\n”); }).listen(8000); }
这是官方手册的例子,上面只有子线程用作服务器,如果master也createServer,会不会有影响?
用手点击没有区别,现在还不会模拟高并发环境,有高手测试过吗?