infinispan配置

来源:互联网 发布:java实现九九乘法表 编辑:程序博客网 时间:2024/05/16 18:00
<?xml version="1.0" encoding="UTF-8"?><infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:infinispan:config:4.0">    <global>      <transport transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport"                 clusterName="infinispan-cluster"                 nodeName="ClusterTest"                 distributedSyncTimeout="50000">               <properties>                 <property name="configurationFile" value="stacks/tcp.xml"/>         </properties>      </transport>                                 </global>    <default>        <clustering mode="r">            <l1 enabled="true" lifespan="60000"/>            <hash numOwners="2" rehashRpcTimeout="60000"/>            <sync/>        </clustering>        <transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"/>    </default>    <namedCache name="allocation">      <transaction useEagerLocking="true" transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"/>                </namedCache><namedCache name="exclusion">          <clustering mode="replication">            <sync/>        </clustering>        <expiration lifespan="5000"/>      </namedCache>   <namedCache name="content">          <clustering mode="replication">            <sync/>        </clustering>      </namedCache>       </infinispan>



tips:
transporttransportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport"
这里是将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">   <TCP bind_port="7800"        loopback="true"        port_range="30"        recv_buf_size="20000000"        send_buf_size="640000"        discard_incompatible_packets="true"        max_bundle_size="64000"        max_bundle_timeout="30"        enable_bundling="true"        use_send_queues="true"        sock_conn_timeout="300"        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-->   <TCPPING timeout="3000"            initial_hosts="localhost[7800],localhost[7801]}"                       port_range="5"            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"           min_interval="10000"/>   <FD_SOCK/>   <!--       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"/>   <pbcast.NAKACK         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"                  max_bytes="400000"/>   <pbcast.GMS print_local_addr="false" join_timeout="7000" view_bundling="true"/>   <FC max_credits="2000000"       min_threshold="0.10"/>   <FRAG2 frag_size="60000"/>   <pbcast.STREAMING_STATE_TRANSFER/>   <!-- <pbcast.STATE_TRANSFER/> -->   <pbcast.FLUSH timeout="0"/></config>

使用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">    <UDP         mcast_port="${jgroups.udp.mcast_port:45555}"         tos="8"         ucast_recv_buf_size="20000000"         ucast_send_buf_size="640000"         mcast_recv_buf_size="25000000"         mcast_send_buf_size="640000"         loopback="false"         discard_incompatible_packets="true"         max_bundle_size="64000"         max_bundle_timeout="30"         ip_ttl="${jgroups.udp.ip_ttl:2}"         enable_bundling="true"         enable_diagnostics="true"         thread_naming_pattern="cl"         timer.num_threads="4"         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"/>    <PING timeout="2000"            num_initial_members="3"/>    <MERGE2 max_interval="30000"            min_interval="10000"/>    <FD_SOCK/>    <FD_ALL/>    <VERIFY_SUSPECT timeout="1500"  />    <BARRIER />    <pbcast.NAKACK use_stats_for_retransmission="false"                   exponential_backoff="0"                   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"                   max_bytes="1000000"/>    <pbcast.GMS print_local_addr="true" join_timeout="3000"                view_bundling="true"/>    <FC max_credits="500000"                    min_threshold="0.20"/>    <FRAG2 frag_size="60000"  />    <!--pbcast.STREAMING_STATE_TRANSFER /-->    <pbcast.STATE_TRANSFER  />    <pbcast.FLUSH  /></config>

tips:
大部分情况下tcp/udp的配置没有这么复杂,这两个是最复杂的例子,如果自己配置的话
 

<pbcast.FLUSHtimeout="0"/>是非常重要的,这个配置是告诉jgroups立即刷新而不是等待


0 0
原创粉丝点击