我的主机允许端口 8000 到 8010
var express = require('express')
, https = require('https')
, app = express()
, cluster = require('cluster')
, numCPUs = require('os').cpus().length
, RedisStore = require("socket.io/lib/stores/redis")
, redis = require("socket.io/node_modules/redis");
, pub = redis.createClient(8002)
, sub = redis.createClient(8002)
, client = redis.createClient(8002);
, server = https.createServer(options,app);
, io = require('socket.io').listen(server);
io.set('store',new RedisStore({redisPub:pub,redisSub:sub,redisClient:client}));
if(cluster.isMaster){for(var i=0;i<numCPUs;i++){cluster.fork();}}
else{
console.log(numCPUs);
io.sockets.on('connection',function(socket){/*do stuff*/});
server.listen(8002);
}
我真的很难理解我是否因为端口而无法连接到 redis,或者是否打开了 socket.io 提供的 redis...
events.js:72
throw er; // Unhandled 'error' event
^
Error: Redis connection to 127.0.0.1:8002 failed - connect ECONNREFUSED
at RedisClient.on_error (/home/engine/public_html/node_modules/socket.io/node_modules/redis/index.js:149:24)
at Socket.<anonymous> (/home/engine/public_html/node_modules/socket.io/node_modules/redis/index.js:83:14)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:426:14
at process._tickCallback (node.js:415:13)
[root@vps ~]# info - socket.io started
另外,我不明白这怎么能给我额外的工人(我 console.log(numCPUs) 并且它说 1,这是否意味着我只有 1 个工人?如果是这样,这意味着性能没有变化;使这种努力毫无意义!?)。