`
ginge
  • 浏览: 211878 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Note on JGroup Cluster of TCP_NIO Transport

阅读更多
Our application need to meet the reliable communication and the least data loss requirements for the JGroup cluster. The JGroup-2.6.1 release provides some out-of-box configurations in xml format. I choose the tcp-nio.xml configuration, because the inefficiency of the traditional IO model and unreliable data transmission of UDP. In this article I will try to explain why we prefer TCP-NIO method and then the configuration details from tcp-nio.xml.

1
1.1
Why TCP-NIO?

Traditional I/O classes have primarily been stream-oriented, often invoking methods on several layers of objects to handle individual bytes or characters.

This object-oriented approach, composing behaviors by plugging I/O objects together, offering tremendous flexibility but can be a performance killer when large amounts of data must be handled. Efficiency is the goal of I/O, and efficient I/O often doesn't map well to objects. Efficient I/O usually means that you must take the shortest path from Point A to Point B. Complexity destroys performance when doing high-volume I/O.

The traditional I/O abstractions of the Java platform have served well and are appropriate for a wide range of uses. But these classes do not scale well when moving large amounts of data, nor do they provide some common I/O functionality widely available on most operating systems today. These features — such as file locking, non-blocking I/O, readiness selection, and memory mapping — are essential for scalability and may be required to interact properly with non-Java applications, especially at the enterprise level. The classic Java I/O mechanism doesn't model these common I/O services.

Java Specification Request#51 (http://jcp.org/jsr/detail/51.jsp) details the need for high-speed, scalable I/O, which better leverages the I/O capabilities of the underlying operating system.

—from O’Reilly Java NIO

1.2
Why not UDP?
Our application might need to go over WAN, and there is chance that some routers over become overloaded which result in discarding packets. The Order the router drops a packet is Broadcast, Multicast, and finally Unicast.


2
2.1 Overview
JGroups uses a JChannel as the main API to connect to a cluster, send and receive messages, and to register listeners that are called when things (such as member joins) happen.

What is sent around are Messages, which contain a byte buffer (the payload), plus the sender's and receiver's address. Addresses are subclasses of org.jgroups.Address, and usually contain an IP address plus a port.

To join a cluster, we'll use a JChannel. An instance of JChannel is created with a configuration (e.g. an XML file) which defines the properties of the channel.

The protocol stack contains a number of protocol layers in a bidirectional list. All messages sent and received over the channel have to pass through the protocol stack. Every layer may modify, reorder, pass or drop a message, or add a header to a message.

The protocol stack in the xml configuration file outlines the protocols bottom-up, take tcp-nio,xml for example, bottom protocol is TCP_NIO and the upmost protocol is pbcast.STREAMING_STATE_TRANSFER. The order shouldn’t be changed.

2.2
Let’s take a look at the configuration:
<config>
<TCP_NIO
        bind_addr="localhost"
            start_port="7800"
            loopback="true"
            recv_buf_size="20000000"
            send_buf_size="640000"
            discard_incompatible_packets="true"
            max_bundle_size="64000"
            max_bundle_timeout="30"
            use_incoming_packet_handler="true"
            enable_bundling="true"
            use_send_queues="false"
            sock_conn_timeout="300"
            skip_suspected_members="true"
            use_concurrent_stack="true"

            thread_pool.enabled="true"
            thread_pool.min_threads="1"
            thread_pool.max_threads="25"
            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="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"

            reader_threads="3"
            writer_threads="3"
            processor_threads="0"
            processor_minThreads="0"
            processor_maxThreads="0"
            processor_queueSize="100"
            processor_keepAliveTime="9223372036854775807"/>
    <TCPPING timeout="3000"
             initial_hosts="${jgroups.tcpping.initial_hosts:localhost[7800],localhost[7801]}"
             port_range="1"
             num_initial_members="3"/>
    <MERGE2 max_interval="100000"
              min_interval="20000"/>
    <FD_SOCK/>
    <FD timeout="10000" max_tries="5"   shun="true"/>
    <VERIFY_SUSPECT timeout="1500"  />
    <pbcast.NAKACK
                   use_mcast_xmit="false" gc_lag="0"
                   retransmit_timeout="300,600,1200,2400,4800"
                   discard_delivered_msgs="true"/>
    <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
                   max_bytes="400000"/>
    <VIEW_SYNC avg_send_interval="60000"/>
    <pbcast.GMS print_local_addr="true" join_timeout="3000"
                shun="true"
                view_bundling="true"/>
    <FC max_credits="2000000"
        min_threshold="0.10"/>
    <FRAG2 frag_size="60000"  />
    <pbcast.STREAMING_STATE_TRANSFER/>
</config>



1) TCP is a replacement of UDP as bottom layer in cases where IP Multicast based on UDP is not desired. This may be the case when operating over a WAN, where routers will discard IP MCAST. As a rule of thumb UDP is used as transport for LANs, whereas TCP is used for WANs. Whereas TCPNIO is a replacement of TCP, TCP_NIO performs much better because it fully take advantage of the NIO services.
2) TCPPING The TCPPING protocol layer retrieves the initial membership in answer to the GMS's FIND_INITIAL_MBRS event.
3) MERGE2 If a group gets split for some reasons (e.g. network partition), this protocol merges the subgroups back into one group.
4) FD_SOCK Failure detection protocol based on a ring of TCP sockets created between group members.
5) FD Failure detection based on heartbeat messages. If reply is not received without timeout ms, max_tries times, a member is declared suspected, and will be excluded by GMS. If we use FD_SOCK instead, then we don't send heartbeats, but establish TCP sockets and declare a member dead only when a socket is closed.
6) VERIFY_SUBSPECT Verifies that a suspected member is really dead by pinging that member once again. Drops suspect message if member does respond. Tries to minimize false suspicions.
7) pbcast.NAKACK Lossless and FIFO delivery of multicast messages, using negative acks. E.g. when receiving P:1, P:3, P:4, a receiver asks P for retransmission of message 2.
8) VIEW_SYNC Periodically sends the view to the group. When a view is received which is greater than the current view, we install it. Otherwise we simply discard it. This is used to solve the problem for unreliable view dissemination outlined in JGroups/doc/ReliableViewInstallation.txt. This protocol is supposed to be just below GMS.
9) pbcast.GMS Group Membership Service. Responsible for joining/leaving members. Also handles suspected members, and excludes them from the membership. Sends Views (topology configuration) to all members when a membership change has occurred.
10) FC Credit based flow control protocol. When senders send faster than receivers can process the messages, over time the receivers will run out of memory. Therefore the senders have to be throttled to the fastest rate at which all receivers can process messages.
11) FRAG2  Fragments messages larger than frag_size bytes
12) STREAMING_STATE_TRANSFER   In order to transfer application state to a joining member of a group pbcast.STATE_TRANSFER has to load entire
state into memory and send it to a joining member. Major limitation of this approach is that the state transfer that isvery large (>1Gb) would likely result in OutOfMemoryException. In order to alleviate this problem a new state transfer methodology, based on a streaming state transfer




Details descriptions of each protocols and its configuration parameter can be found on JGroup WIKI



2.2 Notes on some important parameters:
2.2.1 bind_addr on TCP-NIO

On which address JGroup to create the server socket. Though optional, it’s Useful in case of a multi-homed machine and you just want it bind on the specific address. If not specified, the server socket will be created on all available interfaces

2.2.2 initial_hosts on TCPPING
The comma-separated lists of hosts names and ports used to connect to get the initial memberships. Note that there should not be spaces between the entries in the list. TCPPING.initial_hosts should contain the universe of all possible members. If you decide to add a new member who isn't listed in TCP.initial_hosts, that node will still be able to join, but you may have the problem


For example, there are 192.168.1.1, 192.168.1.2, 192.168.1.3 and 192.168.1.4 starting at port 7800 in the cluster:

Your TCPPING’s configuration should be :
<TCPPING timeout="3000"
             initial_hosts="${jgroups.tcpping.initial_hosts: 192.168.1.1 [7800], 192.168.1.2 [7800], 192.168.1.3 [7800], 192.168.1.4 [7800]}"
             port_range="1"
             num_initial_members="4"/>




All the other protocols and their respective parameters can remain untouched.
分享到:
评论

相关推荐

    jgroup使用实例

    JGroup是Java编程语言中的一款强大且灵活的集群通信库,专为构建高可用性、高性能的分布式系统而设计。它的核心目标是提供可靠的消息传递,确保数据在多个节点之间的一致性和完整性。本实例将深入讲解如何使用JGroup...

    Jgroup学习总结

    **JGroup学习总结** JGroup是一个开源的Java框架,专门用于构建高可用、容错的分布式系统。它提供了一整套服务,包括组成员管理、消息传递、故障检测和恢复等,是许多分布式应用和中间件的基础。这篇博客将深入探讨...

    jgroup手册

    Reliable group communication with JGroups 3.x Preface This is the JGroups manual. It provides information about: ...The focus is on how to use JGroups, not on how JGroups is implemented.

    jgroup master

    JGroups支持多种传输层协议,包括TCP、UDP和多播等,并允许开发人员自定义网络栈来满足特定的应用需求。JGroups的核心组成部分是**通道(Channel)**,它为应用程序提供了一个简单的API来发送和接收消息。 - **通道...

    jgroup代码

    根据提供的文档内容,本文将对“jgroup代码”的安装步骤及如何编写一个简单的应用进行详细的阐述与解析。 ### 一、jgroup代码简介 JGroups是一个高性能、可扩展且易于使用的分布式通信库,用于实现集群中的节点...

    jgroup配置[归类].pdf

    本文将详细解析JGroup中的Transport protocols(传输协议)和Reliable Message(可靠消息)机制。 **4.1 Transport protocols** 传输协议是协议栈的最底层,它们负责消息的发送和接收。JGroups提供了两种主要的...

    jgroup配置[收集].pdf

    JGroup提供了两种主要的传输协议:UDP和TCP。 **4.1.1 UDP** UDP(User Datagram Protocol)协议使用IP多播向集群广播消息,同时利用UDP数据报向单个成员发送单播消息。JGroup启动时会开启两个套接字,一个是多播套...

    jgroup笔记.doc

    JGroup 是一个强大的开源库,专门用于构建集群通信系统。它的主要目标是在集群内部实现可靠的消息传递,确保数据的一致性和高可用性。与 Java Message Service (JMS) 不同,JGroup 更专注于消息传递,而不是队列和...

    EHCACHE集群配置-JGroup篇

    EHCAHCE基于JGROUP的集群配置方案,内含相关配置文件,及配置说明

    《jgroup in action》

    根据提供的信息,《jgroup in action》是一本关于JGroups工具包的书籍,它详细介绍了如何使用JGroups进行可靠的多播通信。JGroups是强大的UUP(User-level UDP)开源组件,已被JBoss采用,用于底层通信。下面我们将...

    java SWT编写JGroup局域网聊天程序

    ### Java SWT 编写 JGroup 局域网聊天程序知识点详解 #### 一、概述 在本篇文章中,我们将深入探讨如何使用Java Swing Toolkits (SWT) 和 JGroups 库来开发一个局域网内的聊天应用程序。文章的标题提到了“Java ...

    Jgroups-all.jar

    JGroup可以基于TCP协议来实现消息广播,也可以通过UDP方式来广播消息,利弊不言而喻,TCP可靠,但是代价大,性能没有UDP来的好,UDP速度快,代价小,但是消息的丢失率以及无序性有着很大的限制。但是JGroup在UDP方式...

    jboss jdbc json jgroup.jar

    在IT行业中,JBoss、JDBC、JSON和JGroup是四个关键的概念,它们在不同的领域发挥着重要作用。这里,我们将深入探讨这些技术及其在实际应用中的相关知识点。 首先,JBoss是一个开源的应用服务器,它是Java EE(企业...

    jgroup-3.0.1

    《JGroup-3.0.1:构建高效集群通信的核心技术》 JGroup是一个开源的Java框架,专门用于构建高可用、高性能的集群系统。它提供了健壮的组通信服务,包括成员资格管理、消息传递、故障检测以及一致性算法等。在版本...

    GroupData:使用JGroup实现分布式数据结构(堆栈和集合)

    它基于IP多播(也支持TCP),但是有一些特殊功能,例如可靠性和组成员身份。 在这个项目中,我通过使用JGroups作为消息传递工具实现了分布式(复制)堆栈和集合。 这些复制的数据结构将使用状态转移来处理新成员...

    Java多播通讯框架 JGroups

    7. **性能优化**:通过多种策略和协议组合,如TCP、UDP、NIO等,优化通信效率。 **JGroups协议栈**: JGroups的灵活性在于它的协议栈,由多个协议层组成,每个协议层负责特定的功能。常见的协议包括: - **TP...

    JGROUPS集群框架源码分析之消息发送、处理、接收

    组协议栈是由多个协议层组成的,如UDP、TCP、FRAG等,每个协议层都有特定的职责,如网络传输、消息分片或重传。 - **协议处理**:消息通过协议栈时,每个协议层都有机会修改或处理消息,如添加头信息、确保顺序等...

    encache+jgroups集群缓存共享

    它的协议栈可以根据具体需求进行配置,支持TCP、UDP等多种传输协议,以及一系列优化策略,如GMS(Group Membership Service)用于管理群组成员,FLUSH协议用于一致性保证,NAKACK用于可靠的消息传递等。 在EnCache...

    基于JGROUPS的ehcache的分布式缓存复制

    在IT行业中,分布式缓存是一种优化高并发场景下数据访问性能的重要技术,它通过在网络中的多台服务器上分发数据来提高系统的响应速度和可扩展性。本文将深入探讨基于JGROUPS的Ehcache实现的分布式缓存复制,这是一种...

Global site tag (gtag.js) - Google Analytics