节点集群(nodejs)的问题
我浏览了这段代码(节点集群的示例),它工作正常,没有错误,但 http 服务器没有响应。 根据日志,它已创建工作人员并且正在运行
var cluster = require('cluster')
, http = require('http');
var server = http.createServer(function(req, res){
console.log('%s %s', req.method, req.url);
var body = 'Hello World';
res.writeHead(200, { 'Content-Length': body.length });
res.end(body);
});
cluster(server)
.use(cluster.logger('logs'))
.use(cluster.stats())
.use(cluster.pidfiles('pids'))
.use(cluster.cli())
.use(cluster.repl(8888))
.listen(3000);
i went through this code (sample of node-cluster), its working fine without errors, but no response from http server.
as per logs it was created workers and those are running
var cluster = require('cluster')
, http = require('http');
var server = http.createServer(function(req, res){
console.log('%s %s', req.method, req.url);
var body = 'Hello World';
res.writeHead(200, { 'Content-Length': body.length });
res.end(body);
});
cluster(server)
.use(cluster.logger('logs'))
.use(cluster.stats())
.use(cluster.pidfiles('pids'))
.use(cluster.cli())
.use(cluster.repl(8888))
.listen(3000);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刚刚在节点 0.4.12 上测试了您的代码,它工作正常。我尝试使用
curl
发出请求,它按预期返回Hello world
。您确定没有错误并且您的节点版本是 0.4 吗?如果我没记错的话,他们从 0.5 开始就添加了内置集群功能。
Just tested your code on node 0.4.12, it works fine. I tried to make a request with
curl
and it returnsHello world
as it should.Are you sure that there are no errors and you have node version 0.4? They added build-in cluster functionality since 0.5 if I recall it correctly.