java - 使用 TCP 的 Ehcache Jgroups 复制在具有 2 节点集群的 AWS 云中不起作用

标签 java caching tcp ehcache jgroups

下面是我们正在使用的 ehcache 配置。我们使用 Jgroups 进行缓存复制。

ehcache.xml

<defaultCache
        maxElementsInMemory="10000"
        eternal="false"
        timeToIdleSeconds="1200"
        timeToLiveSeconds="86400"
        overflowToDisk="true"
        diskSpoolBufferSizeMB="30"
        maxElementsOnDisk="10000000"
        diskPersistent="false"
        diskExpiryThreadIntervalSeconds="120"
        memoryStoreEvictionPolicy="LRU">
    <cacheEventListenerFactory
            class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
            properties="replicateAsynchronously=true,replicatePuts=true,replicateUpdates=true,replicateUpdatesViaCopy=true,replicateRemovals=true" />
</defaultCache>

jgroups_tcp_config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="urn:org:jgroups"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/JGroups-3.0.xsd">
   <!--Configure node ip inside bind_addr-->
   <TCP bind_addr="host1" bind_port="7831" max_bundle_size="9999999"/>
   <!--Configure nodes inside 'initial_hosts' property-->
   <TCPPING timeout="3000" initial_hosts="host1[7831],host2[7831]" port_range="1" num_initial_members="3"/>
   <FRAG2 frag_size="9999999"/>
   <MERGE3 max_interval="30000" min_interval="10000"/>
   <FD timeout="3000" max_tries="10"/>
   <VERIFY_SUSPECT timeout="1500"/>
   <pbcast.NAKACK use_mcast_xmit="false" exponential_backoff="500" discard_delivered_msgs="false"/>
   <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000" max_bytes="400000"/>
   <pbcast.GMS print_local_addr="true" join_timeout="5000" view_bundling="true"/>
</config>

最初从日志中我们可以看到节点正在聚集。我们还可以看到消息正在跨节点复制。但一段时间后,我们看到消息不再被复制,因此导致错误行为。我们使用的jgroups配置有问题吗?

我们还尝试使用 NAKACK2,但消息根本没有跨节点复制。我们只是在上面指定的配置中用 NAKACK2 替换了 NAKACK。不确定我们哪里出错了。

最佳答案

我们在 AWS 云中面临的上述问题。Ehcache Jgroups tcp 将无法在云环境中工作,因为云 VPN 不支持 TCP 多播,因为节点发现不会发生,为了解决这个问题,我们使用 jgroups_s3_config.xml 而不是AWS 云中的 jgroups_tcp_config.xml。通过以下 jgroups_s3_config.xml 配置,我们已经解决了这个问题。

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="urn:org:jgroups"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/JGroups-3.1.xsd">
    <TCP loopback="true" bind_port="7800"/>
    <S3_PING location="s3 bucket name should be in the same region in which app servers are running" 
    access_key="s3 bucket access key from aws credential file" 
    secret_access_key="s3 bucket secret access key from aws credential file" timeout="10000" num_initial_members="2"/>
    <FRAG2/>
    <MERGE2 min_interval="10000" max_interval="30000"/>
    <FD_ALL timeout="12000" interval="3000" timeout_check_interval="4000"/>
    <VERIFY_SUSPECT timeout="1500"/>
    <pbcast.NAKACK2 use_mcast_xmit="false" discard_delivered_msgs="false"/>
    <UNICAST2 timeout="300,600,1200"/>
    <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000" max_bytes="40K"/>
    <pbcast.GMS print_local_addr="true" join_timeout="5000" view_bundling="true"/>
</config>

此外,我们必须设置 JAVA_OPTS。

  export JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true"

关于java - 使用 TCP 的 Ehcache Jgroups 复制在具有 2 节点集群的 AWS 云中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46329967/

相关文章:

java - "Escaped hexadecimal"到 boolean 值

JAVA获取URL API

java - 识别路由器/防火墙后面的客户端

iphone - 在 iPhone 上缓存整个网页

ios - 如何在 swift 5 中缓存图像?

multithreading - 在 Haskell 中使用共享套接字的多线程

java - 使用 JUnit 进行数据库单元测试

jquery - 停止 jQuery Mobile 缓存动态页面

tcp - TCP消息的顺序?

c - 如何将 HTML 页面从 C 网络服务器发送到网络浏览器