基于Java IO 序列化方案的memcached-session-manager多memcached节点配置

session的序列化方案官方推荐的有4种

  1. java serialization
  2. msm-kryo-serializer
  3. msm-javolution-serializer
  4. msm-xstream-serializer

关于这几种,官方也给出了比较:

  • Java serialization is very robust and a proven technology. The biggest disadvantage IMHO is that different class versions cannot be handled.
  • Kryo is an extremely fast binary serialization library. In the popular thrift-protobuf-compare benchmark it's one of the fastest serialization toolkits - and it differs from the fastest in that it does NOT need a schema definition of serialized data, which is a requirement for serialization arbitrary session data. A disadvantage of using kryo based serialization is that it's binary - you just cannot look how the serialized object graph looks like. This is my favorite serialization strategy, just because of its great performance.
  • Javolution is a very good and fast xml binding toolkit. The reflection part is written by me and adds the bits that are actually binding POJOs to xml. It is covered well with unit tests, however I cannot guarantee that there's no issue left to solve (actually this serialization strategy was in use in my own projects, now replaced by kryo based serialization).
  • XStream based serialization should be very robust as this is an often used java object binding library. The biggest disadvantage IMHO is the relatively bad performance.

要注意的是javolution是唯一支持copyCollectionsForSerialization="true"时对能对线程不安全的collection进行序列化特性的,其他的方案要对序列化线程不安全的collection时特别处理,性能最好的序列化方案是Kryo。

网上有一些例子都是关于Javolution的,我个人倾向于使用Kryo,至于序列化出现的问题还可以自己解决,不过先使用java IO来配置,先用起来,以后再慢慢优化,换成Kryo。

直接在CATALINAHOME/lib/下添加memcached−2.5.jar和memcached−session−manager−1.4.0.jar ,然后对CATALINA_HOME/conf/server.xml修改相应的配置

复制代码
   <Context path="/webapp" docBase="D:\webapp\WebRoot" reloadable="false">  
     <Manager   
        className= "de.javakaffee.web.msm.MemcachedBackupSessionManager"  
        memcachedNodes= "n1:192.168.112.1:11211,n2:192.168.112.2:11211"   
        sticky="false"   
        lockingMode="auto"   
        requestUriIgnorePattern= ".*\.(png|gif|jpg|css|js)$"    
        sessionBackupAsync= "false"   
        sessionBackupTimeout= "0"   
        memcachedProtocol="binary"  
        transcoderFactoryClass= "de.javakaffee.web.msm.JavaSerializationTranscoderFactory"    
     />  
   </Context>  

由于项目对session 管理模式是non-sticky的,所以不配置failoverNodes,任何一个web工程对session的修改要及时更新到memcache上,所以sessionBackupTimeout为0(不同的应用有不同的配置,这样配置是符合我现在这个项目要求的)。

相关推荐
爱学习的小可爱卢5 分钟前
JavaEE进阶——SpringBoot统一功能处理全解析
java·spring boot·后端·java-ee
汤姆yu8 分钟前
基于springboot的二手物品交易系统的设计与实现
java·spring boot·后端
0思必得09 分钟前
[Web自动化] CSS基础概念和介绍
前端·css·python·自动化·html·web自动化
计算机徐师兄12 分钟前
Python基于Django的MOOC线上课程推荐数据分析与可视化系统(附源码,文档说明)
python·数据分析·django·慕课线上课程推荐·慕课线上课程推荐可视化系统·pytho线上课程推荐可视化·线上课程推荐数据分析可视化系统
free-elcmacom14 分钟前
Python实战项目<2>使用Graphviz绘制流程框图
开发语言·python·graphviz
中国胖子风清扬18 分钟前
Spring AI Alibaba + Ollama 实战:基于本地 Qwen3 的 Spring Boot 大模型应用
java·人工智能·spring boot·后端·spring·spring cloud·ai
ljuncong21 分钟前
python的装饰器怎么使用
开发语言·python
foundbug99934 分钟前
Modbus协议C语言实现(易于移植版本)
java·c语言·前端
该用户已不存在34 分钟前
没有这7款工具,难怪你的Python这么慢
后端·python
听风吟丶38 分钟前
Java 反射机制深度解析:从原理到实战应用与性能优化
java·开发语言·性能优化