I have 3 servers running NodeJs, and they are connected to each other using Redis (1 master, 2 subordinates).
The problem I am facing is that working on a system on a single server works fine, but when I scale it to 3 NodeJS servers, it starts to skip messages and the system becomes unstable.
My balancer does not accept sticky sessions. Therefore, every time requests from a client arrive at it, they can go to another server.
I point all NodeJS servers to Redis Master.
It seems that socket.io stores information on each server and is not distributed using redis.
I use socket.io V9, I suspect that I do not have handshake code, could this be the reason?
My code for setting socket.io is:
var express = require('express'); var io = require('socket.io'); var redis = require('socket.io/node_modules/redis'); var RedisStore = require('socket.io/lib/stores/redis'); var pub = redis.createClient("a port", "an ip"); var sub = redis.createClient("a port", "an ip"); var client = redis.createClient("a port", "an ip"); var events = require('./modules/eventHandler'); exports.createServer = function createServer() { var app = express(); var server = app.listen(80); var socketIO = io.listen(server); socketIO.configure(function () { socketIO.set('store', new RedisStore({ redisPub: pub, redisSub: sub, redisClient: client })); socketIO.set('resource', '/chat/socket.io'); socketIO.set('log level', 0); socketIO.set('transports', [, 'htmlfile', 'xhr-polling', 'jsonp-polling']); });
source share