Heartbeat Architecture
Heartbeat
heartbeat is a background task that sends periodic ping requests to the Tarantool node and
analyzes the results of successful and unsuccessful ping requests. The heartbeat task is set up for
each PoolEntry in IProtoClientPool. The main purpose of heartbeat -
to monitor the availability of the connection to the Tarantool node
How It Works
To determine the availability of the Tarantool node, a sliding window approach is used. Let's imagine
that the following heartbeat settings were specified:
invalidationThreshold == 2deathThreshold == 4windowSize == 3
Availability analysis of the node is performed using ping requests. If the number of failed ping requests
at the moment of consideration exceeds the value invalidationThreshold in the window, then the connection is excluded
from the connection pool for selection by the balancer (4,5,6). For
the excluded connection, the heartbeat process continues. Each exceeding of invalidationThreshold
increases the currentDeathThreshold counter by 1. If currentDeathThreshold reaches the
value deathThreshold, the connection is considered dead (status KILL) and the reconnection process
of the connection is started (7).
The transition from the INVALIDATE state to the ACTIVATE state occurs if in subsequent iterations
of availability analysis, the number of failed ping requests is less than the value invalidationThreshold.
The currentDeathThreshold counter is reset to the value 0 (see
diagram)
The transition from the KILL state to the ACTIVATE state occurs if the connection was successfully
reconnected.
Heartbeat Parameters
| Parameter Name | Description | Default Value |
| pingInterval | The time in milliseconds after which the next ping request is executed | 3000 |
| invalidationThreshold | The number of failed ping requests in the window, upon reaching which PoolEntry is removed from the connection pool (the balancer stops seeing this connection during selection). Ping requests on this connection continue to be executed | 2 |
| windowSize | The size of the sliding window (in terms of ping requests) | 4 |
| deathThreshold | The number of invalidationThreshold exceedances after which the connection is switched to the reconnection state | 4 |
| pingFunction | The method for executing the verification request (ping request) | IProtoClient::ping |
Parameter Configuration
To configure the heartbeat parameters, use the HeartbeatOpts API:
final HeartbeatOpts heartbeatOpts = HeartbeatOpts.getDefault()
.withPingInterval(pingInterval)
.withWindowSize(windowSize)
.withDeathThreshold(deathThreshold)
.withInvalidationThreshold(invalidationThreshold)
.withPingFunction(pingFunction);
final TarantoolCrudClient crudClient = TarantoolFactory.crud()
// ... other options
.withHeartbeat(heartbeatOpts)
.build();