[英]Scaling to 2+ dynos on Heroku with socket.io-redis and RedisToGo
I'm trying to use socket.io-redis to scale my app on Heroku to 2 dynos (or more). 我正在尝试使用socket.io-redis将我在Heroku上的应用程序缩放到2 dynos(或更多)。 Here is my code (where config.redis is just an object housing RedisToGo port, host, and pass values): 这是我的代码(config.redis只是一个包含RedisToGo端口,主机和传递值的对象):
var redisApp = require('redis');
var redis = require('socket.io-redis');
if(process.env.NODE_ENV === 'production') {
var socketpub = redisApp.createClient(config.redis.port, config.redis.host, {auth_pass: config.redis.pass, return_buffers: true});
var socketsub = redisApp.createClient(config.redis.port, config.redis.host, {auth_pass: config.redis.pass, detect_buffers: true});
var client = redisApp.createClient(config.redis.port, config.redis.host, {auth_pass: config.redis.pass, return_buffers: true});
socketio.adapter(redis({
pubClient: socketpub,
subClient: socketsub,
redisClient: client
}));
}
On the client side I have: 在客户端,我有:
var ioSocket = io('', {
path: '/socket.io-client',
'force new connection': true,
transports: ['websocket']
});
..so socket.io doesn't try to use polling. ..so socket.io不会尝试使用轮询。
I also have the right Heroku env vars configured for RedisToGo (REDISTOGO_HOST, REDISTOGO_PASS, REDISTOGO_PORT). 我还为RedisToGo配置了正确的Heroku env变量(REDISTOGO_HOST,REDISTOGO_PASS,REDISTOGO_PORT)。
When we're scaled to 1 dyno, the socket behavior is perfect. 当我们将比例缩放为1 dyno时,套接字行为是完美的。 At 2 dynos, the behavior is way off - requests are being randomly made to either 1 dyno or the other, and the socket events being emitted are sent only to clients running on the dyno to which the request was made and not all (which socket.io-redis & RedisToGo should be taking care of). 在2个dyno上,行为很不正常-向1个dyno或另一个dyno随机发出请求,并且发出的套接字事件仅发送给在向其发出请求的dyno上运行的客户端,而不是所有客户端(哪个socket) .io-redis和RedisToGo应该得到照顾)。
Any thoughts would be greatly appreciated! 任何想法将不胜感激!
not sure if this helps you but I am using in this way redis and socketio and it is working good. 不知道这是否对您有帮助,但是我以这种方式使用redis和socketio,并且效果很好。
var redis = require('redis').createClient;
var adapter = require('socket.io-redis');
var port = config.redistogo.port;
var host = config.redistogo.host;
var pub = redis(port, host, {
auth_pass: auth_pass
});
var sub = redis(port, host, {
detect_buffers: true,
auth_pass: auth_pass
});
io.adapter(adapter({
pubClient: pub,
subClient: sub
}));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.