From 4d6f9bef90dd31573e079f2e0e53c1d31f32b474 Mon Sep 17 00:00:00 2001 From: Andrew Kyle Purtell Date: Tue, 18 Aug 2009 02:06:51 +0000 Subject: [PATCH] HBASE-1754 use TCP keepalives git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@805252 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/hadoop/hbase/ipc/HBaseClient.java | 3 +++ src/java/org/apache/hadoop/hbase/ipc/HBaseServer.java | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/java/org/apache/hadoop/hbase/ipc/HBaseClient.java b/src/java/org/apache/hadoop/hbase/ipc/HBaseClient.java index 603203184fc..9d1840a45dc 100644 --- a/src/java/org/apache/hadoop/hbase/ipc/HBaseClient.java +++ b/src/java/org/apache/hadoop/hbase/ipc/HBaseClient.java @@ -77,6 +77,7 @@ public class HBaseClient { //maxIdleTime msecs final protected int maxRetries; //the max. no. of retries for socket connections protected boolean tcpNoDelay; // if T then disable Nagle's Algorithm + protected boolean tcpKeepAlive; // if T then use keepalives protected int pingInterval; // how often sends ping to the server in msecs protected SocketFactory socketFactory; // how to create sockets @@ -301,6 +302,7 @@ public class HBaseClient { try { this.socket = socketFactory.createSocket(); this.socket.setTcpNoDelay(tcpNoDelay); + this.socket.setKeepAlive(tcpKeepAlive); // connection time out is 20s NetUtils.connect(this.socket, remoteId.getAddress(), 20000); this.socket.setSoTimeout(pingInterval); @@ -637,6 +639,7 @@ public class HBaseClient { conf.getInt("ipc.client.connection.maxidletime", 10000); //10s this.maxRetries = conf.getInt("ipc.client.connect.max.retries", 10); this.tcpNoDelay = conf.getBoolean("ipc.client.tcpnodelay", false); + this.tcpKeepAlive = conf.getBoolean("ipc.client.tcpkeepalive", true); this.pingInterval = getPingInterval(conf); if (LOG.isDebugEnabled()) { LOG.debug("The ping interval is" + this.pingInterval + "ms."); diff --git a/src/java/org/apache/hadoop/hbase/ipc/HBaseServer.java b/src/java/org/apache/hadoop/hbase/ipc/HBaseServer.java index e884f81b5b9..5090909b4ed 100644 --- a/src/java/org/apache/hadoop/hbase/ipc/HBaseServer.java +++ b/src/java/org/apache/hadoop/hbase/ipc/HBaseServer.java @@ -145,7 +145,8 @@ public abstract class HBaseServer { private int maxQueueSize; protected int socketSendBufferSize; - protected final boolean tcpNoDelay; // if T then disable Nagle's Algorithm + protected final boolean tcpNoDelay; // if T then disable Nagle's Algorithm + protected final boolean tcpKeepAlive; // if T then use keepalives volatile protected boolean running = true; // true while server runs protected BlockingQueue callQueue; // queued calls @@ -391,6 +392,7 @@ public abstract class HBaseServer { channel.configureBlocking(false); channel.socket().setTcpNoDelay(tcpNoDelay); + channel.socket().setKeepAlive(tcpKeepAlive); SelectionKey readKey = channel.register(selector, SelectionKey.OP_READ); c = new Connection(channel, System.currentTimeMillis()); readKey.attach(c); @@ -998,6 +1000,7 @@ public abstract class HBaseServer { this.rpcMetrics = new HBaseRpcMetrics(serverName, Integer.toString(this.port)); this.tcpNoDelay = conf.getBoolean("ipc.server.tcpnodelay", false); + this.tcpKeepAlive = conf.getBoolean("ipc.server.tcpkeepalive", true); // Create the responder here responder = new Responder();