AWS上的memcached-session-manager

时间:2012-06-13 11:03:16

标签: amazon-web-services memcached session-management session-replication amazon-elasticache

我在Amazon Web Services上运行了一个使用Elastic Beanstalk部署并在至少2个EC2微型实例上运行的网站。自动扩展策略已到位,因此可以根据网站中的流量进行扩展和缩小。由于此自动扩展策略,我想避免使用粘性会话,因此我使用memcached-session-manager。我正在使用Amazon ElastiCache(小实例)作为memcached服务器。

context.xml中的配置如下:

<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
    memcachedNodes="sessions.myinstancecode.0001.use1.cache.amazonaws.com:11211"
    sticky="false"
    sessionBackupAsync="false"
    lockingMode="none"
    transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory" />

当流量较低(即少于10个在线用户)时,此工作正常,但有时会导致EC2实例重新启动。您可以想象,如果网站当前在两个实例上运行并且他们都决定同时重新启动,那么该网站将无法访问,这是一个大问题。这些是在EC2实例决定重新启动之前在Amazon S3上轮换的tail_catalina.log中的最后一行:

Jun 13, 2012 12:32:27 AM de.javakaffee.web.msm.BackupSessionTask handleException
WARNING: Could not store session 42F9761AC24F826E1FC3F2A834FBF442 in memcached.
Note that this session was relocated to this node because the original node was not available.
net.spy.memcached.internal.CheckedOperationTimeoutException: Timed out waiting for operation - failing node: sessions.myinstancecode.0001.use1.cache.amazonaws.com/10.194.23.99:11211
    at net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:73)
    at de.javakaffee.web.msm.BackupSessionTask.storeSessionInMemcached(BackupSessionTask.java:230)
    at de.javakaffee.web.msm.BackupSessionTask.doBackupSession(BackupSessionTask.java:195)
    at de.javakaffee.web.msm.BackupSessionTask.call(BackupSessionTask.java:120)
    at de.javakaffee.web.msm.BackupSessionTask.call(BackupSessionTask.java:51)
    at de.javakaffee.web.msm.BackupSessionService$SynchronousExecutorService.submit(BackupSessionService.java:339)
    at de.javakaffee.web.msm.BackupSessionService.backupSession(BackupSessionService.java:198)
    at de.javakaffee.web.msm.MemcachedSessionService.backupSession(MemcachedSessionService.java:967)
    at de.javakaffee.web.msm.SessionTrackerValve.backupSession(SessionTrackerValve.java:226)
    at de.javakaffee.web.msm.SessionTrackerValve.invoke(SessionTrackerValve.java:128)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:680)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:636)
Jun 13, 2012 12:32:28 AM de.javakaffee.web.msm.LockingStrategy onAfterBackupSession
WARNING: An error occurred during onAfterBackupSession.
net.spy.memcached.internal.CheckedOperationTimeoutException: Timed out waiting for operation - failing node: sessions.myinstancecode.0001.use1.cache.amazonaws.com/10.194.23.99:11211
    at net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:73)
    at de.javakaffee.web.msm.LockingStrategy.onAfterBackupSession(LockingStrategy.java:287)
    at de.javakaffee.web.msm.MemcachedSessionService.backupSession(MemcachedSessionService.java:970)
    at de.javakaffee.web.msm.SessionTrackerValve.backupSession(SessionTrackerValve.java:226)
    at de.javakaffee.web.msm.SessionTrackerValve.invoke(SessionTrackerValve.java:128)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:680)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:636)

似乎Amazon ElastiCache节点出现故障,但问题是,检查Amazon CloudWatch,我可以看到CPU利用率从未超过8%。亚马逊ElastiCache节点出现故障是否有任何原因,即使它没有那么紧张?此外,为什么当Amazon ElastiChace节点出现故障时,亚马逊决定重启(或更好:终止并启动新实例)?

非常感谢任何帮助。

谢谢!

1 个答案:

答案 0 :(得分:8)

你应该从documentation增加memcached-session-manager的sessionBackupTimeout:

  

sessionBackupTimeout(可选,默认为100)

     

考虑会话备份后的超时(以毫秒为单位)   因为蜜蜂失败了。仅在会话期间评估此属性   同步存储(通过sessionBackupAsync设置)。默认值   是100毫秒。