Heroku的粘性会议

时间:2018-12-26 23:17:50

标签: node.js heroku sticky-session

我们有一个运行SocketIO并在heroku上集群的NodeJS应用程序。为了使SocketIO正常工作,我们使用redis-adapter,如此处讨论的:https://socket.io/docs/using-multiple-nodes/

然后,我们实现了粘性会话,如此处的粘性会话文档所示:https://github.com/elad/node-cluster-socket.io

事实证明,当我们部署到Heroku时,connection.remoteAddress位于:

// Create the outside facing server listening on our port.
var server = net.createServer({ pauseOnConnect: true }, function(connection) {
    // We received a connection and need to pass it to the appropriate
    // worker. Get the worker for this connection's source IP and pass
    // it the connection.
    var index = worker_index(connection.remoteAddress, num_processes);
    var worker = workers[index];
    worker.send('sticky-session:connection', connection);
}).listen(port);

实际上是某些heroku路由服务器的IP地址,而不是客户端IP。我已经看到请求标头“ x-forwarded-for”可以用于获取客户端IP,但是当我们以这种方式暂停连接时,我们甚至还没有标头?

1 个答案:

答案 0 :(得分:0)

我们到处寻找解决方案,但是显然没有好的解决方案。

以下是一些更好的建议:

https://github.com/indutny/sticky-session/issues/6

https://github.com/indutny/sticky-session/pull/45

它们似乎都没有表现良好的性能,因此我们最终只将SocketIO通信更改为Websockets。这样就无需一起进行粘性会话。

相关问题