在tomcat实例之间共享会话(不使用粘滞会话) [英] Share Sessions between tomcat instances (without using Sticky Sessions)

查看:162
本文介绍了在tomcat实例之间共享会话(不使用粘滞会话)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将有3个Tomcat服务器和一个负载均衡器,可以在不使用'粘性会话


我想在服务器之间共享会话数据,我正在考虑将它们保存在数据库中。我想使用 memcached 作为我的数据库前面的一层来更快地提供请求并不要让我的数据库负载很重


我正在考虑提供我的自定义tomcat管理器,它在获取/持久化会话数据到DB之前使用memcached,因为此刻我没有看到透明的方式(这意味着我必须在我转换到另一个应用服务器的情况下再次管理它。)


这是一个很好的解决方案还是你看到了更好的方法?

I'm going to have 3 Tomcat servers and a Load Balancer that dispatches the requests without using 'sticky sessions'.

I want to share sessions' data between the servers and I'm thinking in persisting them in DB. I'd like to use memcached as a layer in front of my DB to serve the requests faster and to don't put my db under heavy load.

I'm thinking in providing my customized tomcat Manager that uses memcached before getting/persisting session data to DB as at the moment I don't see a transparent way of doing it (it means that I'll have to manage it again in the case I switch to another app server).

Is this a good solution or do you see a better approach?

推荐答案

在数据库中保留会话限制了您的可伸缩性。如果可伸缩性对您来说不重要,那么(db + memcached)是一种有效的方法。

Persisting sessions in the database limits your scalability. If scalability is not that important for you this (db + memcached) is a valid approach.

使用nonsticky-sesions时需要注意的一件事是并发请求:当你有例如ajax-requests(并行/并发执行)它们将由不同的tomcats服务(由于非粘性),因此可以同时访问会话。只要您有可能修改会话的并发请求,您就需要实现某种同步/会话锁定。

One thing you need to keep in mind when using nonsticky-sesions are concurrent requests: when you have e.g. ajax-requests (executed in parallel/concurrently) they will be served by different tomcats (due to non-stickyness) and therefore access the session concurrently. As long as you have concurrent requests that might modify the session you need to implement some kind of synchronization / session locking.

也许这对您很感兴趣:我创建了 memcached-session-manager ,旨在实现最佳性能和无限可扩展性。它可以与任何与memcached兼容的后端(例如memcachedb,membase等或只是memcached)一起使用。
虽然它最初是为粘性会话方法创建的,但已经有一个非粘性分支 - 现有的示例应用,展示了它是如何工作的。
现在有一个邮件列表中有关非粘性会话进一步改进的帖子(处理并发请求并防止单点故障)。

Perhaps this is of interest for you: I created the memcached-session-manager with the goal of both optimal performance and unlimited scalability. It can work with any memcached-compatible backend (e.g. also memcachedb, membase etc. or just memcached). Although it was originally created for a sticky-sessions approach, there's already a branch for nonsticky-sessions existing and a sample app showing how/that it works. Right now there's a thread on the mailing list on further improvements for nonsticky-sessions (handling of concurrent requests and preventing single-point-of-failure).

这篇关于在tomcat实例之间共享会话(不使用粘滞会话)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆