【问题标题】:Spymemcached issue with 2 nodes configured配置了 2 个节点的 Spymemcached 问题
【发布时间】:2017-12-14 00:47:20
【问题描述】:

我正在为我的项目使用 Ketama 算法的 spymemcached。我确实有两个 memcached 服务器作为 HA(高可用性)的一部分运行,我的配置是

hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=true
hibernate.cache.region.factory_class=kr.pe.kwonnam.hibernate4memcached.Hibernate4MemcachedRegionFactory
hibernate.cache.default_cache_concurrency_strategy=NONSTRICT_READ_WRITE
hibernate.cache.region_prefix=myProjectCache
hibernate.cache.use_structured_entries=false
h4m.adapter.class=kr.pe.kwonnam.hibernate4memcached.spymemcached.SpyMemcachedAdapter
h4m.timestamper.class=kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamperMemcachedImpl

h4m.adapter.spymemcached.hosts=host1:11211,host2:11211
h4m.adapter.spymemcached.hashalgorithm=KETAMA_HASH
h4m.adapter.spymemcached.operation.timeout.millis=5000
h4m.adapter.spymemcached.transcoder=kr.pe.kwonnam.hibernate4memcached.spymemcached.KryoTranscoder
h4m.adapter.spymemcached.cachekey.prefix=myProject
h4m.adapter.spymemcached.kryotranscoder.compression.threashold.bytes=20000

# 10 minutes
h4m.expiry.seconds=600
# a day
h4m.expiry.seconds.validatorCache.org.hibernate.cache.spi.UpdateTimestampsCache=86400
# 1 hour
h4m.expiry.seconds.validatorCache.org.hibernate.cache.internal.StandardQueryCache=3600
# 30 minutes
h4m.expiry.seconds.myProjectCache.database1=1800
h4m.expiry.seconds.myProjectCache.database2=1800

按照以下链接进行配置:

SpyMemcachedAdapter

节点 host1 和 host2 都可以访问、启动并运行。

问题:

作为测试 HA 的一部分,当我关闭一个 memcached (host1) 时,我的应用程序正在连接到 host2,但只有在尝试为每个请求连接 host1(这将超时 - 因为 host1 已关闭)之后。这将导致花费太多时间 下面是每个请求都抛出的异常

2017-07-07 17:27:31.915 [SimpleAsyncTaskExecutor-6] ERROR u.c.o.sProcessor - TransId:004579 - Exception occurred while processing request :Timeout waiting for value: waited 5,000 ms. Node status: Connection Status { /host1:11211 active: false, authed: true, last read: 247,290 ms ago /host2:11211 active: true, authed: true, last read: 5 ms ago }
 2017-07-07 17:28:54.666 INFO net.spy.memcached.MemcachedConnection:  Reconnecting due to failure to connect to {QA sa=/host1:11211, #Rops=0, #Wops=214, #iq=0, topRop=null, topWop=Cmd: 5 Opaque: 341143 Key: myProject.myProjectCache.databse1@ Amount: 0 Default: 1499444604639 Exp: 2592000, toWrite=0, interested=0}
    java.net.ConnectException: Connection refused
        at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
        at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
        at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:677)
        at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:436)
        at net.spy.memcached.MemcachedConnection.run(MemcachedConnection.java:1446)
    2017-07-07 17:28:54.666 WARN net.spy.memcached.MemcachedConnection:  Closing, and reopening {QA sa=/host1:11211, #Rops=0, #Wops=214, #iq=0, topRop=null, topWop=Cmd: 5 Opaque: 341143 Key: myProject.myProjectCache.databse1@ Amount: 0 Default: 1499444604639 Exp: 2592000, toWrite=0, interested=0}, attempt 14.
    2017-07-07 17:28:54.841 WARN net.spy.memcached.MemcachedConnection:  Could not redistribute to another node, retrying primary node for myProject.myProjectCache.databse1@-1:my.co.org.myProject.dao.entity.databse1.tablexyz#14744.

第一次使用memcached,不知道是不是spymemcached的行为?或者我在我的配置中遗漏了什么?要么 通过更改超时配置,它会解决处理请求所花费的时间吗?

非常感谢任何建议/帮助。

【问题讨论】:

    标签: memcached spymemcached


    【解决方案1】:

    如果您使用的是使用 OOTB ConnectionFactoryBuilder 的 DefaultConnectionFactory,则在失败的操作计数达到 timeoutExceptionThreshold(在 spymemcached 的 2.7 版中)初始化为 998 后将发生重新连接。因此,如果您创建自己的 ConnectionFactory 并将 timeoutExceptionThreshold 更改为较低的值那么您应该会看到自动恢复。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2022-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多