首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Heroku上的粘性会话

Heroku上的粘性会话
EN

Stack Overflow用户
提问于 2018-12-27 07:17:50
回答 1查看 255关注 0票数 1

我们有一个在SocketIO上运行的NodeJS应用程序,并在heroku上进行集群。为了让SocketIO正常工作,我们使用这里讨论的redis适配器:https://socket.io/docs/using-multiple-nodes/

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

事实证明,当我们部署到Heroku时,其中的connection.remoteAddress:

代码语言:javascript
复制
// 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,但是当我们以这种方式暂停连接时,我们甚至还没有这些头?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-28 04:33:33

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

以下是一些更好的建议:

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

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

它们在性能方面似乎都不是很好,因此我们最终将SocketIO通信改为只使用Websockets。这消除了所有粘性会话的需要。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53938147

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档