Getting Started Part 3: Memcached-based tomcat cluster session multiple tomcat serialization strategy configuration

Multiple tomcat serialization strategies are configured as follows:
1. java default serialization tomcat configuration
conf/context.xml add
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
   memcachedNodes="n1:192.168.100.208:11211 n2:192.168.100.208:11311"     
lockingMode="auto"
sticky="false" 
requestUriIgnorePattern= ".*\.(png|gif|jpg|css|js)$"    
sessionBackupAsync= "false"   
sessionBackupTimeout= "100"      
transcoderFactoryClass= "de.javakaffee.web.msm.JavaSerializationTranscoderFactory"    
    />
lib adds jar package:
spymemcached-2.10.3.jar
memcached-session-manager-1.7.0.jar
memcached-session-manager-tc7-1.7.0.jar


二、javolution序列化tomcat配置
conf/context.xml添加
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
   memcachedNodes="n1:192.168.100.208:11211 n2:192.168.100.208:11311"   
lockingMode="auto"
sticky="false" 
requestUriIgnorePattern= ".*\.(png|gif|jpg|css|js)$"    
sessionBackupAsync= "false"   
sessionBackupTimeout= "100"  
copyCollectionsForSerialization="true"   
transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"    
    />
lib增加jar包
msm-javolution-serializer-cglib-1.3.0.jar
msm-javolution-serializer-jodatime-1.3.0.jar
spymemcached-2.10.3.jar
javolution-5.4.3.1.jar
msm-javolution-serializer-1.7.0.jar
memcached-session-manager-1.7.0.jar
memcached-session-manager-tc7-1.7.0.jar

三、xstream序列化tomcat配置
conf/context.xml添加
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
   memcachedNodes="n1:192.168.100.208:11211 n2:192.168.100.208:11311"   
lockingMode="auto"
sticky="false" 
requestUriIgnorePattern= ".*\.(png|gif|jpg|css|js)$"    
sessionBackupAsync= "false"   
sessionBackupTimeout= "100"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.xstream.XStreamTranscoderFactory"    
    />
lib增加jar包
xmlpull-1.1.3.1.jar
xpp3_min-1.1.4c.jar
xstream-1.4.6.jar
msm-xstream-serializer-1.7.0.jar
spymemcached-2.10.3.jar
memcached-session-manager-1.7.0.jar
memcached-session-manager-tc7-1.7.0.jar

四、flexjson序列化tomcat配置
conf/context.xml添加
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
   memcachedNodes="n1:192.168.100.208:11211 n2:192.168.100.208:11311"     
lockingMode="auto"
sticky="false" 
requestUriIgnorePattern= ".*\.(png|gif|jpg|css|js)$"    
sessionBackupAsync= "false"   
sessionBackupTimeout= "100"      
transcoderFactoryClass="de.javakaffee.web.msm.serializer.json.JSONTranscoderFactory"    
    />
lib增加jar包
flexjson-3.1.jar
msm-flexjson-serializer-1.7.0.jar
spymemcached-2.10.3.jar
memcached-session-manager-1.7.0.jar
memcached-session-manager-tc7-1.7.0.jar

五、kryo序列化tomcat配置
conf/context.xml添加
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
   memcachedNodes="n1:192.168.100.208:11211 n2:192.168.100.208:11311"   
lockingMode="auto"
sticky="false" 
requestUriIgnorePattern= ".*\.(png|gif|jpg|css|js)$"    
sessionBackupAsync= "false"   
sessionBackupTimeout= "100"    
copyCollectionsForSerialization="true"   
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"    
    />
lib增加jar包
kryo-1.04.jar
minlog-1.2.jar
asm-3.2.jar
reflectasm-1.01.jar
kryo-serializers-0.11.jar
msm-kryo-serializer-1.7.0.jar
spymemcached-2.10.3.jar
memcached-session-manager-1.7.0.jar
memcached-session-manager-tc7-1.7.0.jar

The configuration of various situations is as above. It is said that the serialization efficiency of kryo is relatively fast and has not been tested.
Choose one of the methods. After deploying two tomcat ports, 8080 and 8181
, respectively, check whether the access refresh SessionID is the same.
http://127.0.0.1:8080/t.jsp
SessionID:37B7F153AB3567295B2FBF1831475F5F-n1
SessionIP:127.0.0.1 
SessionPort:8080 

http://127.0.0.1:8181/t.jsp
SessionID:37B7F153AB3567295B2FBF1831475F5F-n1
SessionIP:127.0.0.1 
SessionPort:8181  
The test result is consistent with the SessionID.

For configuration examples, please refer to: http://download.csdn.net/detail/tianwei7518/6832985

When the session is stored in the memchached implementation. Its main function is to modify the session storage mechanism of tomcat, so that it can serialize the session and store it in memcached.
Manager tag attribute description
1.className  must be
class name: de.javakaffee.web.msm.MemcachedBackupSessionManager

2.  memcachedNodes must be
memcached nodes: this attribute should contain the uri addresses of all running memcached nodes or membase buckets. The attribute definition format of each memcached node is <id>:<host>:<port>, and multiple node definitions can be used directly Spaces or commas are separated, such as: memcachedNodes="n1:app01:11211,n2:app02:11211", if there is only a single memcached node, <id> is optional, just configure <host>:<port> Yes, in the form: memcachedNodes="localhost:11211".
If we configure membase, starting from version 1.6.0, we can configure and specify one or more membase bucket uris, such as: http://host1:8091/pools,http://host2:8091/pools . Bucket name and password are defined by attributes username,password. The membase buckets connection needs to follow the memcached protocol, and the data is transmitted through binary streams.

3.failoverNodes optional
Failover node: optional, not available for non-sticky sessions, the attribute must contain all the ids of the memcached node cluster. The node ids are separated by spaces or commas.

4.username optional
Used since version 1.6.0 and is optional. Used for membase bucket or SASL authentication, the password can be empty.

5.password option
is used since version 1.6.0 and is optional. Used for membase bucket or SASL authentication, the password can be empty.

6.memcachedProtocol    option
Define the memcached protocol, the text text is used by default, and the out attribute indicates the storage protocol used by memcached. Only text or binary is supported.

7. sticky    option
Define the session mode as sticky or non-sticky, the default is true, and non-sticky must be used when multiple tomcats are used

8. lockingMode    option
is only used for non-sticky sessions, the default value is none
none: never lock the session
all: the session will always be locked until the request ends
auto: for read-only requests, the session will not be locked, if If it is a non-read-only request, the session will be locked
. uriPattern:<regexp>: The request uri and query string are matched by regular expressions, and only the matching ones will be locked.
9.requestUriIgnorePattern   optional

This attribute is a regular expression for requests that cannot alter the backup session. If static files like css, javascript, images, etc. are served from the same Tomcat and the same application context, these requests will also go through memcached-session-manager. But these requests barely change within an http session, so they don't need to trigger a session backup. So those static files don't need to trigger session backup, you can use this attribute definition. This property must conform to the java regex regular specification.
    Such as: ".*\.(png|gif|jpg|css|js)$"  

10.sessionBackupAsync   option
Specifies whether the Session should be saved to Memcached asynchronously. If set to true, the backupThreadCount setting will take effect, if set to false, the expiration time set by sessionBackupTimeout will take effect.

11. The backupThreadCount    option is
 used to asynchronously save the number of threads of the Session, (if sessionBackupAsync="true"). The default is the number of cores in cup.

12. The sessionBackupTimeout    option
 sets the time used to back up a Session. If the operation exceeds the time, the save fails. This property only works when sessionBackupAsync="false". Default 100ms

13.operationTimeout    option is used
since version 1.6.0, the default value is 1000

14.sessionAttributeFilter    option
 This attribute is used to control the regular expression that the attribute value in the Session is saved to Memcached. Zheng Ze expression is used to match the attribute name in the session. For example, sessionAttributeFilter="^(userName|sessionHistory)$" specifies that only "userName" and "sessionHistory" attributes are stored in Memcached. Depends on the serialization strategy chosen.

15.transcoderFactoryClass    optional
 This property value is the factory class name of the transcoder that creates serialization and deserialization saved to the Session in Memcached. The specified class must implement de.javakaffee.web.msm.TranscoderFactory and provide a no-argument constructor. For example other valid implementations are provided in other packages/jars such as: msm-kryo-serializer, msm-xstrea-serializer and msm-javolution-serializer.
Default is de.javakaffee.web.msm.JavaSerializationTranscoderFactory

16.copyCollectionsForSerialization    optional The
default value is false.

17.customConverter    option
Define a special class and register it in the kryo custom converter to realize serialization.
18.enableStatistics option
 is used to specify whether to perform statistics. The default value is true.

19.   The enabled option
 specifies whether the session saved to Memcached is available and whether it can be changed through JMX. Only used for sticky sessions. The default value is true.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325451368&siteId=291194637