/* * cluster module‘s example * 2016.02.16 * cswuyg * */ ‘use strict‘; var cluster = require(‘cluster‘); var http = require(‘http‘); var cpuCount = require(‘os‘).cpus().length; if (cluster.isMaster) { for (var i = 0; i < cpuCount; ++i) { cluster.fork(); } } else { http.createServer(function(req, res) { res.writeHead(200); res.end(‘hello world\n‘); console.log(cluster.worker.id); }).listen(8000); }
官方资料:https://nodejs.org/api/cluster.html
学习资料:http://www.infoq.com/cn/articles/nodejs-cluster-round-robin-load-balancing
nodejs changelog:https://github.com/nodejs/node/blob/v4.3.0/CHANGELOG.md
原文:http://www.cnblogs.com/cswuyg/p/5193313.html