CommunicationSpi provides basic plumbing to send and receive grid messages and is utilized for all distributed grid operations, such as task execution, monitoring data exchange, distributed event querying, and others. Ignite provides
TcpCommunicationSpi as the default implementation of
CommunicationSpi, that uses TCP/IP to communicate with other nodes.
To enable communication with other nodes,
TcpCommunicationSpi.ATTR_PORT local node attributes. At start up, this SPI tries to start listening to the local port specified by the
TcpCommunicationSpi.setLocalPort(int) method. If the local port is occupied, then the SPI will automatically increment the port number until it can successfully bind for listening. The
TcpCommunicationSpi.setLocalPortRange(int) configuration parameter controls the maximum number of ports that the SPI will try before it fails.
Local Port Range
Port range comes in very handy when starting multiple grid nodes on the same machine or even in the same VM. In this case, all nodes can be brought up without a single change in the configuration.
IPv4 vs IPv6
Ignite tries to support IPv4 and IPv6 but this can sometimes lead to issues where the cluster becomes detached. A possible solution — unless you require IPv6 — is to restrict Ignite to IPv4 via the
The following configuration parameters can be optionally configured on
Sets local host address for socket binding.
Any available local IP address.
Sets local port for socket binding.
Controls maximum number of local ports tried if all previously tried ports are occupied.
Sets value for the
Sets connect timeout used when establishing connection with remote nodes.
Sets maximum idle connection timeout upon which a connection to client will be closed.
Sets the buffer size ratio for this SPI. As messages are sent, the buffer size is adjusted using this ratio.
Sets the minimum number of messages for this SPI, that are buffered prior to sending.
Sets a flag indicating whether dual socket connection between nodes should be enforced. If set to true, two separate connections will be established between communicating nodes: one for outgoing messages, and one for incoming. When set to false, a single TCP connection will be used for both directions.
This parameter is used only when
Sets connection buffer size for synchronous connections. Increase buffer size if using synchronous send and sending large amount of small sized messages. However, most of the time this should be set to 0 (default).
Sets the count of selectors to be used in TCP server.
Default count of selectors equals to the expression result -
This parameter is used only when
Sets connection buffer flush frequency in milliseconds. This parameter makes sense only for synchronous send when connection buffer size is not 0. Buffer will be flushed once within specified period if there is not enough messages to make it flush automatically.
Switches between using NIO direct and NIO heap allocation buffers. Although direct buffers perform better, in some cases (especially on Windows) they may cause JVM crashes. If that happens in your environment, set this property to false.
Switches between using NIO direct and NIO heap allocation buffers usage for message sending in asynchronous mode.
Switches between synchronous and asynchronous message sending.
Sets the port which will be used by
Sets receive buffer size for sockets created or accepted by this SPI. If not provided, the default is 0 which leaves the buffer unchanged after socket creation (i.e. uses Operating System default value).
Sets send buffer size for sockets created or accepted by this SPI. If not provided, the default is 0 which leaves the buffer unchanged after socket creation (i.e. uses Operating System default value).
<bean class="org.apache.ignite.configuration.IgniteConfiguration"> ... <property name="communicationSpi"> <bean class="org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi"> <!-- Override local port. --> <property name="localPort" value="4321"/> </bean> </property> ... </bean>
TcpCommunicationSpi commSpi = new TcpCommunicationSpi(); // Override local port. commSpi.setLocalPort(4321); IgniteConfiguration cfg = new IgniteConfiguration(); // Override default communication SPI. cfg.setCommunicationSpi(commSpi); // Start grid. Ignition.start(cfg);
Updated about a year ago