以循环模式使用 tomcat
我想在配置中运行我的 tomcat 实例,其中通过循环将请求提供给多个 tomcat 实例。我不想使用任何内部集群管理器。
据我所知,如果每个请求都由不同的tomcat提供服务,则未知的sessionId将到达tomcat,因此它将被迫创建一个新会话并覆盖旧的sessionId。因此,对于每个请求,都会创建一个新会话。这似乎是一个很大的开销。
我对这件事的看法正确吗?有没有办法禁用 tomcats 会话管理?
问候, 迈克尔
I want to run my tomcat-instances in a configuration where requests are served to several tomcat-instance via round robin. I don't want to use any internal cluster manager.
As far as I see if every request is served by different tomcats, an unknown sessionId would arrive at a tomcat, so it would be forced to create an new session and overwrite the old sessionId. So for every request a new session would be created. This seems to be a lot of overhead.
Is my view on that things right? Is there a way to disable tomcats sessions management?
Regards,
Michael
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
基本上,您有两种选择:
1) 复制会话,以便任何 Tomcat 节点都可以访问它们。解决方案:Tomcat集群、memcached-session-manager,也可能是其他。
2) 使用负载均衡器并实现粘性会话。第一个请求将在循环的基础上随机路由,但后续请求将坚持到同一服务器。解决方案:mod_proxy,硬件流量管理器。
第一个选项的缺点是会话复制成本高昂,不太可靠,并且通常需要将仅可序列化的数据放入会话中。
第二种方法的缺点是,如果您关闭 Tomcat 进行维护,用户将被迫重新登录。
您错误地假设“对于每个请求都会创建一个新会话”。仅当之前未在同一服务器上创建,或者已创建但已过期时,才会创建新会话。
Basically you have two choices:
1) Replicate your sessions so they become reachable by any Tomcat node. Solutions: Tomcat Cluster, memcached-session-manager, possibly others.
2) Use a load balancer and implement sticky sessions. First requests will be routed randomly on a round robin basis, but subsequent requests will stick to the same server. Solutions: mod_proxy, hardware traffic managers.
The disadvantage of the first option is that session replication is costly, not very reliable and often requires
Serializable
-only data to be put in session.The disadvantage of the second approach is that if you shut down your Tomcat for maintenance, the users will be forced to log in again.
You are incorrectly assuming that "for every request a new session would be created". The new session will be created only if not created before on that same server, or if it was created but already expired.
我们通常在 Apache Web 服务器后面使用 Tomcat 和
mod_jk
来平衡 Tomcat 实例之间的请求。使用粘性会话用户只会在第一次请求时获得会话,之后将始终被定向到其会话源自的 Tomcat。因此,无需在所有 Tomcat 之间复制会话,并且请求也将分布在 Tomcat 之间。
当然,这并不能确保您所要求的某种循环赛。
We usually used Tomcat behind an Apache web server with
mod_jk
for load balancing the requests across the Tomcat instances.With sticky sessions a user will only get a session upon the first request and will afterwards always be directed to the Tomcat from where his session originates. So there is no need to replicate sessions across all Tomcats and the requests will be distributed across the Tomcats, too.
Of course, this does not ensure some kind of round-robin which you asked for.
仅当您的代码请求会话时才会创建会话,因此如果您的应用程序不需要会话,则只需不要访问它即可。查看 HttpServletRequest 中有关 getSession() 的部分
http://download.oracle.com/javaee/5/api/javax/servlet/http/HttpServletRequest.html#getSession(boolean)
我不确定是否有办法在不同的服务器之间复制会话tomcat 实例,但是如果您需要一些没有会话的用户状态,那么您可以使用 cookie 代替
编辑:如果您确实需要复制会话,您可以从阅读此 tomcat 文档开始。
http://tomcat.apache.org/tomcat-5.5-doc/cluster -howto.html
A session will only be created once your code requests the session so if your application doesn't require the session then just simply dont access it. Checkout the section on getSession() in HttpServletRequest
http://download.oracle.com/javaee/5/api/javax/servlet/http/HttpServletRequest.html#getSession(boolean)
I'm not sure if there is a way to replicate the session across different tomcat instances however if you require some user state without session then you can use cookies instead.
EDIT: If you do need to replicate the session you could probably start by reading this tomcat document.
http://tomcat.apache.org/tomcat-5.5-doc/cluster-howto.html