From e690cd5011dabea730bf6cb822e7d31e8c4b719a Mon Sep 17 00:00:00 2001 From: Haohui Mai Date: Wed, 4 Jan 2017 21:01:23 -0800 Subject: [PATCH] HDFS-11280. Allow WebHDFS to reuse HTTP connections to NN. Contributed by Zheng Shao. --- .../org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 166e3c3a499..1a180b18285 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 @@ -663,6 +663,8 @@ protected HttpURLConnection connect(URL url) throws IOException { url = new URL(conn.getHeaderField("Location")); redirectHost = url.getHost() + ":" + url.getPort(); } finally { + // TODO: consider not calling conn.disconnect() to allow connection reuse + // See http://tinyurl.com/java7-http-keepalive conn.disconnect(); } } @@ -895,7 +897,9 @@ final T getResponse(HttpURLConnection conn) throws IOException { 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(); } } @@ -942,6 +946,9 @@ public void close() throws IOException { 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(); } }