JGroups Settings

See the information about JGroups features and settings.

JGroups:

  • Is a Java toolkit for reliable multicast communication

  • Can be used to create groups of processes whose members can send messages to each other

  • Saves development time

  • Has a flexible protocol stack so an application can be deployed in different environments without having to change code

Main features of JGroups:

  • Membership

  • Transport protocols: UDP (IP Multicast), TCP, JMS

  • Fragmentation of large messages

  • Reliable unicast and multicast message transmission. Lost messages are retransmitted

  • Failure detection: crashed members are excluded from the membership

  • Ordering protocols: Atomic (all-or-none message delivery), Fifo, Causal, Total Order (sequencer or token based)

  • Encryption

  • Much faster message transmission than with UDP or TCP only

JGroups used in the Platform comes with two preconfigured setups - the first one using TCP and the second one using UDP as the transport protocol.

JGroups is much faster than using 'pure' UDP or TCP: in our local testing JGroups UDP cluster, sending 10 mln messages took 2 minutes as compared with 3 minutes with UDP Multicast. Cloud testing yielded similar speed improvement.

JGroups-based Cluster Implementation

Add the following properties to your local.properties file:

local.properties
cluster.broadcast.method.jgroups=de.hybris.platform.cluster.jgroups.JGroupsBroadcastMethod
cluster.broadcast.method.jgroups.tcp.bind_addr=12.34.56.78
cluster.broadcast.method.jgroups.tcp.bind_port=7800
cluster.broadcast.method.jgroups.channel.name=hybris-broadcast
cluster.broadcast.method.jgroups.configuration=jgroups-udp.xml

cluster.broadcast.method.jgroups.configuration property specifies the path to an xml file with the configuration settings. The default configuration for JGroups is UDP.

If you want to use the TCP configuration instead, change the jgroups.configuration property to:

 jgroups-tcp.xml 

If you want to use a custom configuration, specify your custom.xml file for UDP, and custom-jgroups-tcp.xml under your extension/resources/jgroups/, add in local.properties, and restart the server:

local.properties
cluster.broadcast.method.jgroups.configuration=custom.xml or custom-jgroups-tcp.xml

JGroups UDP

JGroups UDP clustering uses IP multicast for sending messages to all members of a group and UDP datagrams for unicast messages (sent to a single member). When started, it opens a unicast and multicast socket: the unicast socket is used to send/receive unicast messages, whereas the multicast socket sends/receives multicast messages. The channel's address becomes the address and port number of the unicast socket.

A protocol stack with UDP as transport protocol is typically used with groups whose members run on the same host or are distributed across a LAN. Before running such a stack, a programmer has to ensure that IP multicast is enabled across subnets. It’s often the case that IP multicast isn’t enabled across subnets. In such cases, the stack has to either use UDP without IP multicasting or other transports such as TCP.

JGroups Configuration File

JGroups UDP Configuration File

The following is an example of configuration in the jgroups_udp.xml file:

<!--
  Default stack using IP multicasting. It is similar to the "udp"
  stack in stacks.xml, but doesn't use streaming state transfer and flushing
-->

<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-4.0.xsd">
   <UDP
        mcast_port="${hybris.jgroups.mcast_port}"
        tos="8"
        ucast_recv_buf_size="20M"
        ucast_send_buf_size="640K"
        mcast_recv_buf_size="25M"
        mcast_send_buf_size="640K"
        max_bundle_size="64K"
        ip_ttl="${jgroups.udp.ip_ttl:8}"
        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"/>
         [...]
</config>

For full information on JGroup protocols, see Protocols Supported by JGroups.

JGroups TCP Configuration File

Specifying TCP in your protocol stack tells JGroups to use TCP to send messages between group members. Instead of using a multicast bus, the group members create a mesh of TCP connections.

The following is an example of configuration in the jgroups_tcp.xml file:

<!-- TCP based stack, with flow control and message bundling. This is usually used when IP multicasting cannot be used in a network, 
	e.g. because it is disabled (routers discard multicast).  -->
<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-4.0.xsd">
  <TCP
     recv_buf_size="${tcp.recv_buf_size:20M}"
     send_buf_size="${tcp.send_buf_size:640K}"
     max_bundle_size="64K"
     sock_conn_timeout="300"
     thread_pool.enabled="true"
     thread_pool.min_threads="1"
     thread_pool.max_threads="10"
     thread_pool.keep_alive_time="5000"
     bind_addr="${hybris.jgroups.bind_addr}"
     bind_port="${hybris.jgroups.bind_port}" />
       <JDBC_PING connection_driver="${hybris.database.driver}"
     connection_password="${hybris.database.password}"
     connection_username="${hybris.database.user}"
     connection_url="${hybris.database.url}"
     initialize_sql="${hybris.jgroups.schema}"
     datasource_jndi_name="${hybris.datasource.jndi.name}"
     remove_all_data_on_view_change=“${hybris.jgroups.remove_all_data_on_view_change}”
     write_data_on_find=“${hybris.jgroups.write_data_on_find}” />
         [...]
</config>