Reputation: 12034
I have read a lot of stuff about custering, redis but I could not find any real sample.
I have a simple socket.io application and I need to scale this application to many servers.
Looks like socket.io and RedisStore is the solution.
Does anyone has a real world nippet on how he uses socket.io on many servers ?
Upvotes: 1
Views: 485
Reputation: 3666
You need to npm install
the package socket.io-redis
. Then start the server by command redis-server
.
Add the following lines to your code.
var io = require('socket.io')(3000);
var redis = require('socket.io-redis');
io.adapter(redis({ host: 'localhost', port: 6379 }));
Then you need to modify your nginx configurations file to enable load balancing as in, http://socket.io/docs/using-multiple-nodes/#nginx-configuration
upstream io_nodes {
ip_hash;
server 127.0.0.1:6001;
server 127.0.0.1:6002;
server 127.0.0.1:6003;
server 127.0.0.1:6004;
}
Restart your nginx server and then run node server. This should scale your server too.
Upvotes: 2