Session Replication across WLS Cluster
【早期文章,迁移过来】
Weblogic即可以实现一个Cluster内的instance的session复制,也可以实现多个Cluster之间的session复制。通常用的就是一个Custer内的负载均衡,实现高可用性。Weblogic提供两个方式的Http Session复制:
要实现Weblogic Cluster负载均衡,在网络上必须要有一个负载均衡器,比如F5、Apache等,如果是跨机器的Cluster节点,网络必须通
3.1 Session必须序列化
为了支持in-memory http session复制,所有的servlet和jsp会话数据必须序列化,实现java.io.Serializable接口,而且注意下面内容,来自官方文档:
Serialization is the process of converting a complex data structure, such as a parallel arrangement of data (in which a number of bits are transmitted at a time along parallel channels) into a serial form (in which one bit at a time is transmitted); a serial interface provides this conversion to enable data transmission.
3.2 用setAttribute 修改 Session 状态
在http servlet实现了javax.servlet.http.HttpSession
,用
HttpSession.setAttribute
代替
putValue
方法去修改
session
对象。
putValue
方法是不建议用,同样用
removeAttribute
代替
removeValue
去删除
session
对象。
3.3 避免大的session对象
因为往session中存放的数据比较大时,系统的响应速度明显变慢,有时会出现内存溢出的情况。
3.4 框架的使用
在特定的框架集(frameset)中,确保只有一个框架(frame)创建和修改会话数据;必须确保只在第一个框架集的一个框架中创建会话,其他框架集访问该session。
If you are designing a Web application that utilizes multiple frames, keep in mind that there is no synchronization of requests made by frames in a given frameset. For example, it is possible for multiple frames in a frameset to create multiple sessions on behalf of the client application, even though the client should logically create only a single session.
In a clustered environment, poor coordination of frame requests can cause unexpected application behavior. For example, multiple frame requests can “reset” the application’s association with a clustered instance, because the proxy plug-in treats each request independently. It is also possible for an application to corrupt session data by modifying the same session attribute via multiple frames in a frameset.
4.1 在Cluster中需要配置复制组
4.2 Weblogic.xml配置
domain_directory/applications/application_directory/Web-Inf/weblogic.xml
<session-descriptor>
<session-param>
<param-name>PersistentStoreType</param-name>
<param-value>replicated</param-value>
</session-param>
</session-descriptor>