ITPub博客

首页 > 数据库 > > infinispan配置

infinispan配置

作者:LCR_ 时间:2022-04-14 17:28:24 0 删除 编辑
  1. .org/2001/XMLSchema-instance" xmlns="urn:infinispan:config:4.0">
  2. <global>
  3. <transport transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport"
  4. clusterName="infinispan-cluster"
  5. nodeName="ClusterTest"
  6. distributedSyncTimeout="50000">
  7. <properties>
  8. <property name="configurationFile" value="stacks/tcp.xml"/>
  9. </properties>
  10. </transport>
  11. </global>
  12. <default>
  13. <clustering mode="r">
  14. <l1 enabled="true" lifespan="60000"/>
  15. <hash numOwners="2" rehashRpcTimeout="60000"/>
  16. <sync/>
  17. </clustering>
  18. <transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"/>
  19. </default>
  20. <namedCache name="allocation">
  21. <transaction useEagerLocking="true" transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"/> </namedCache>
  22. <namedCache name="exclusion">
  23. <clustering mode="replication">
  24. <sync/>
  25. </clustering>
  26. <expiration lifespan="5000"/>
  27. </namedCache>
  28. <namedCache name="content">
  29. <clustering mode="replication">
  30. <sync/>
  31. </clustering>
  32. </namedCache>
  33. </infinispan>



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


  1. <config xmlns="urn:org:jgroups"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="urn:org:jgroups file:schema/JGroups-2.8.xsd">
  4. <TCP bind_port="7800"
  5. loopback="true"
  6. port_range="30"
  7. recv_buf_size="20000000"
  8. send_buf_size="640000"
  9. discard_incompatible_packets="true"
  10. max_bundle_size="64000"
  11. max_bundle_timeout="30"
  12. enable_bundling="true"
  13. use_send_queues="true"
  14. sock_conn_timeout="300"
  15. enable_diagnostics="false"
  16. skip_suspected_members="true"
  17. thread_pool.enabled="true"
  18. thread_pool.min_threads="2"
  19. thread_pool.max_threads="8"
  20. thread_pool.keep_alive_time="5000"
  21. thread_pool.queue_enabled="false"
  22. thread_pool.queue_max_size="100"
  23. thread_pool.rejection_policy="Run"
  24. oob_thread_pool.enabled="true"
  25. oob_thread_pool.min_threads="2"
  26. oob_thread_pool.max_threads="8"
  27. oob_thread_pool.keep_alive_time="5000"
  28. oob_thread_pool.queue_enabled="false"
  29. oob_thread_pool.queue_max_size="100"
  30. oob_thread_pool.rejection_policy="Run"/>
  31. <!-- you need add initial hosts list in initial_hosts-->
  32. <TCPPING timeout="3000"
  33. initial_hosts="localhost[7800],localhost[7801]}"
  34. port_range="5"
  35. num_initial_members="1"/>
  36. <!-- use multicast here -->
  37. <!--<MPING bind_addr="127.0.0.1" break_on_coord_rsp="true"-->
  38. <!--mcast_addr="230.8.8.8" mcast_port="17890" ip_ttl="2"-->
  39. <!--num_initial_members="3"/>-->
  40. <MERGE2 max_interval="30000"
  41. min_interval="10000"/>
  42. <FD_SOCK/>
  43. <!--
  44. Note that this is an atypically short timeout and a small number of retries
  45. configured this way to speed up unit testing, since we know all nodes run in the same JVM
  46. and hence failure detections will be very quick.
  47. -->
  48. <FD timeout="3000" max_tries="3"/>
  49. <VERIFY_SUSPECT timeout="1500"/>
  50. <pbcast.NAKACK
  51. use_mcast_xmit="false" gc_lag="0"
  52. retransmit_timeout="300,600,1200,2400,4800"
  53. discard_delivered_msgs="false"/>
  54. <UNICAST timeout="300,600,1200"/>
  55. <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
  56. max_bytes="400000"/>
  57. <pbcast.GMS print_local_addr="false" join_timeout="7000" view_bundling="true"/>
  58. <FC max_credits="2000000"
  59. min_threshold="0.10"/>
  60. <FRAG2 frag_size="60000"/>
  61. <pbcast.STREAMING_STATE_TRANSFER/>
  62. <!-- <pbcast.STATE_TRANSFER/> -->
  63. <pbcast.FLUSH timeout="0"/>
  64. </config>


使用udp.xml


  1. <config xmlns="urn:org:jgroups"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/JGroups-2.8.xsd">
  4. <UDP
  5. mcast_port="${jgroups.udp.mcast_port:45555}"
  6. tos="8"
  7. ucast_recv_buf_size="20000000"
  8. ucast_send_buf_size="640000"
  9. mcast_recv_buf_size="25000000"
  10. mcast_send_buf_size="640000"
  11. loopback="false"
  12. discard_incompatible_packets="true"
  13. max_bundle_size="64000"
  14. max_bundle_timeout="30"
  15. ip_ttl="${jgroups.udp.ip_ttl:2}"
  16. enable_bundling="true"
  17. enable_diagnostics="true"
  18. thread_naming_pattern="cl"
  19. timer.num_threads="4"
  20. thread_pool.enabled="true"
  21. thread_pool.min_threads="2"
  22. thread_pool.max_threads="8"
  23. thread_pool.keep_alive_time="5000"
  24. thread_pool.queue_enabled="true"
  25. thread_pool.queue_max_size="10000"
  26. thread_pool.rejection_policy="discard"
  27. oob_thread_pool.enabled="true"
  28. oob_thread_pool.min_threads="1"
  29. oob_thread_pool.max_threads="8"
  30. oob_thread_pool.keep_alive_time="5000"
  31. oob_thread_pool.queue_enabled="false"
  32. oob_thread_pool.queue_max_size="100"
  33. oob_thread_pool.rejection_policy="Run"/>
  34. <PING timeout="2000"
  35. num_initial_members="3"/>
  36. <MERGE2 max_interval="30000"
  37. min_interval="10000"/>
  38. <FD_SOCK/>
  39. <FD_ALL/>
  40. <VERIFY_SUSPECT timeout="1500" />
  41. <BARRIER />
  42. <pbcast.NAKACK use_stats_for_retransmission="false"
  43. exponential_backoff="0"
  44. use_mcast_xmit="true" gc_lag="0"
  45. retransmit_timeout="300,600,1200"
  46. discard_delivered_msgs="true"/>
  47. <UNICAST timeout="300,600,1200"/>
  48. <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
  49. max_bytes="1000000"/>
  50. <pbcast.GMS print_local_addr="true" join_timeout="3000"
  51. view_bundling="true"/>
  52. <FC max_credits="500000"
  53. min_threshold="0.20"/>
  54. <FRAG2 frag_size="60000" />
  55. <!--pbcast.STREAMING_STATE_TRANSFER /-->
  56. <pbcast.STATE_TRANSFER />
  57. <pbcast.FLUSH />
  58. </config>


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

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

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70000523/viewspace-3168526/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2022-02-22

  • 博文量
    1402
  • 访问量
    15008