From 1bc9b316ba60b1ecc8d6fca8d78642933d2c186b Mon Sep 17 00:00:00 2001 From: Haohui Mai Date: Fri, 30 Dec 2016 22:17:49 -0800 Subject: [PATCH] HDFS-11280. Allow WebHDFS to reuse HTTP connections to NN. Contributed by Zheng Shao. --- .../org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java index 1607be9e95c..4cc5b671a55 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java @@ -667,7 +667,9 @@ public class WebHdfsFileSystem extends FileSystem url = new URL(conn.getHeaderField("Location")); redirectHost = url.getHost() + ":" + url.getPort(); } finally { - conn.disconnect(); + // Don't call conn.disconnect() to allow connection reuse + // See http://tinyurl.com/java7-http-keepalive + conn.getInputStream().close(); } } try { @@ -899,7 +901,9 @@ public class WebHdfsFileSystem extends FileSystem LOG.debug("Response decoding failure.", e); throw ioe; } finally { - conn.disconnect(); + // Don't call conn.disconnect() to allow connection reuse + // See http://tinyurl.com/java7-http-keepalive + conn.getInputStream().close(); } } @@ -946,6 +950,9 @@ public class WebHdfsFileSystem extends FileSystem try { validateResponse(op, conn, true); } finally { + // This is a connection to DataNode. Let's disconnect since + // there is little chance that the connection will be reused + // any time soonl conn.disconnect(); } }