Elffuss BraidHub

kikocis/java-driver public

2f8dc102409e · 1.6 KiBRenderedRawPermalink
1## Connection heartbeat
2
3If connections stay idle for too long, they might be dropped by
4intermediate network devices (routers, firewalls...). Normally, TCP
5keepalive should take care of this; but tweaking low-level keepalive
6settings might be impractical in some environments.
7
8The driver provides application-side keepalive in the form of a
9connection heartbeat: when a connection has been idle for a given amount
10of time, the driver will simulate activity by writing a dummy request to
11it.
12
13This feature is enabled by default. The default heartbeat interval is 30
14seconds, it can be customized through `PoolingOptions`:
15
16 cluster.getConfiguration().getPoolingOptions()
17 .setHeartbeatIntervalSeconds(60);
18
19This can be changed at runtime, but only connections created after that
20will use the new interval. Most users will want to do this at startup:
21
22 Cluster cluster = Cluster.builder()
23 .addContactPoint("127.0.0.1")
24 .withPoolingOptions(new PoolingOptions()
25 .setHeartbeatIntervalSeconds(60))
26 .build();
27
28The heartbeat interval should be set higher than
29[SocketOptions.readTimeoutMillis](http://www.datastax.com/drivers/java/2.1/com/datastax/driver/core/SocketOptions.html#getReadTimeoutMillis()):
30the read timeout is the maximum time that the driver waits for a regular
31query to complete, therefore the connection should not be considered
32idle before it has elapsed.
33
34To disable heartbeat, set the interval to 0.
35
36Implementation note: the dummy request sent by heartbeat is an
37[OPTIONS](https://github.com/apache/cassandra/blob/trunk/doc/native_protocol_v3.spec#L278)
38message.