.org/2001/XMLSchema-instance" xmlns="urn:infinispan:config:4.0">
<transport transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport"
clusterName="infinispan-cluster"
distributedSyncTimeout="50000">
<property name="configurationFile" value="stacks/tcp.xml"/>
<l1 enabled="true" lifespan="60000"/>
<hash numOwners="2" rehashRpcTimeout="60000"/>
<transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"/>
<namedCache name="allocation">
<transaction useEagerLocking="true" transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"/> </namedCache>
<namedCache name="exclusion">
<clustering mode="replication">
<expiration lifespan="5000"/>
<namedCache name="content">
<clustering mode="replication">
tips:
transporttransport
这里是将transportclass指定为JGroupsTransport,这里的transport必须是org.infinispan.remoting.transport.Transport的子类,infinispan自己仅仅实现了jgroups的transport,如果不想用jgroups的话,那么自己基于socket实现一个transport也是可以的。
clusterName="infinispan-cluster"
这里指定cluster name,只有在同一个cluster内部的节点才能互相复制数据。
nodeName="ClusterTest"
nodeName在默认情况下可以不写
<property name="configurationFile"value="stacks/tcp.xml"/>
这个属性很重要,表示stacks的配置信息是从statcks/tcp.xml里读取,注意,对应的name一定要设置成configurationFile。当然也可以使用编程的方式来指定,这里总共可以有四种方式,具体配置和代码可以参考infinispan的官方文档。
default的这一段是对cache做一些通用的配置,其中需要注意的是clusteringmode="r",mode有三种模式,local,replication anddistribution,如果不写模式的话,默认就是local,r和d分别是replication以及distribution的简写。
在infinispan里我们可以使用jpa或者jta的transactionmanager来管理事务,如果是测试环境下,则可以使用dummy transactionmanager(infinispan自己提供的,只是如果需要跟spring一起用的话,需要将这个transactionmanager作为spring中jta transaction manager的构造函数参数注入)
expirationlifespan="5000"也很重要,它规定了多长时间缓存的对象过期。当然这也可以在cache层面用编码的方式来指定。
jgroups的基本配置
使用tcp
<config xmlns="urn:org:jgroups"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:org:jgroups file:schema/JGroups-2.8.xsd">
discard_incompatible_packets="true"
enable_diagnostics="false"
skip_suspected_members="true"
thread_pool.enabled="true"
thread_pool.min_threads="2"
thread_pool.max_threads="8"
thread_pool.keep_alive_time="5000"
thread_pool.queue_enabled="false"
thread_pool.queue_max_size="100"
thread_pool.rejection_policy="Run"
oob_thread_pool.enabled="true"
oob_thread_pool.min_threads="2"
oob_thread_pool.max_threads="8"
oob_thread_pool.keep_alive_time="5000"
oob_thread_pool.queue_enabled="false"
oob_thread_pool.queue_max_size="100"
oob_thread_pool.rejection_policy="Run"/>
<!-- you need add initial hosts list in initial_hosts-->
initial_hosts="localhost[7800],localhost[7801]}"
num_initial_members="1"/>
<!-- use multicast here -->
<!--<MPING bind_addr="127.0.0.1" break_on_coord_rsp="true"-->
<!--mcast_addr="230.8.8.8" mcast_port="17890" ip_ttl="2"-->
<!--num_initial_members="3"/>-->
<MERGE2 max_interval="30000"
Note that this is an atypically short timeout and a small number of retries
configured this way to speed up unit testing, since we know all nodes run in the same JVM
and hence failure detections will be very quick.
<FD timeout="3000" max_tries="3"/>
<VERIFY_SUSPECT timeout="1500"/>
use_mcast_xmit="false" gc_lag="0"
retransmit_timeout="300,600,1200,2400,4800"
discard_delivered_msgs="false"/>
<UNICAST timeout="300,600,1200"/>
<pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
<pbcast.GMS print_local_addr="false" join_timeout="7000" view_bundling="true"/>
<FC max_credits="2000000"
<FRAG2 frag_size="60000"/>
<pbcast.STREAMING_STATE_TRANSFER/>
<!-- <pbcast.STATE_TRANSFER/> -->
<pbcast.FLUSH timeout="0"/>
使用udp.xml
<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-2.8.xsd">
mcast_port="${jgroups.udp.mcast_port:45555}"
ucast_recv_buf_size="20000000"
ucast_send_buf_size="640000"
mcast_recv_buf_size="25000000"
mcast_send_buf_size="640000"
discard_incompatible_packets="true"
ip_ttl="${jgroups.udp.ip_ttl:2}"
enable_diagnostics="true"
thread_naming_pattern="cl"
thread_pool.enabled="true"
thread_pool.min_threads="2"
thread_pool.max_threads="8"
thread_pool.keep_alive_time="5000"
thread_pool.queue_enabled="true"
thread_pool.queue_max_size="10000"
thread_pool.rejection_policy="discard"
oob_thread_pool.enabled="true"
oob_thread_pool.min_threads="1"
oob_thread_pool.max_threads="8"
oob_thread_pool.keep_alive_time="5000"
oob_thread_pool.queue_enabled="false"
oob_thread_pool.queue_max_size="100"
oob_thread_pool.rejection_policy="Run"/>
num_initial_members="3"/>
<MERGE2 max_interval="30000"
<VERIFY_SUSPECT timeout="1500" />
<pbcast.NAKACK use_stats_for_retransmission="false"
use_mcast_xmit="true" gc_lag="0"
retransmit_timeout="300,600,1200"
discard_delivered_msgs="true"/>
<UNICAST timeout="300,600,1200"/>
<pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
<pbcast.GMS print_local_addr="true" join_timeout="3000"
<FRAG2 frag_size="60000" />
<!--pbcast.STREAMING_STATE_TRANSFER /-->
<pbcast.STATE_TRANSFER />
tips:
大部分情况下tcp/udp的配置没有这么复杂,这两个是最复杂的例子,如果自己配置的话
<pbcast.FLUSHtimeout="0"/>是非常重要的,这个配置是告诉jgroups立即刷新而不是等待
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70000523/viewspace-3168526/
,如需转载,请注明出处,否则将追究法律责任。