Elffuss BraidHub

kikocis/java-driver public

77a4c2107385 · 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```java
17cluster.getConfiguration().getPoolingOptions()
18 .setHeartbeatIntervalSeconds(60);
19```
20
21This can be changed at runtime, but only connections created after that
22will use the new interval. Most users will want to do this at startup:
23
24```java
25Cluster cluster = Cluster.builder()
26 .addContactPoint("127.0.0.1")
27 .withPoolingOptions(new PoolingOptions()
28 .setHeartbeatIntervalSeconds(60))
29 .build();
30```
31
32The heartbeat interval should be set higher than
33[SocketOptions.readTimeoutMillis](http://www.datastax.com/drivers/java/2.1/com/datastax/driver/core/SocketOptions.html#getReadTimeoutMillis()):
34the read timeout is the maximum time that the driver waits for a regular
35query to complete, therefore the connection should not be considered
36idle before it has elapsed.
37
38To disable heartbeat, set the interval to 0.
39
40Implementation note: the dummy request sent by heartbeat is an
41[OPTIONS](https://github.com/apache/cassandra/blob/trunk/doc/native_protocol_v3.spec#L278)
42message.