From 8e0e7107547f902028ff686079b517c5edb2c08e Mon Sep 17 00:00:00 2001 From: Haohui Mai Date: Tue, 8 Aug 2017 14:58:11 -0700 Subject: [PATCH] HDFS-10326. Disable setting tcp socket send/receive buffers for write pipelines. Contributed by Daryn Sharp. (cherry picked from commit 6801b898d53cf603dea134fc8b492e16f65049fd) --- .../hadoop/hdfs/protocol/HdfsConstants.java | 4 ++-- .../src/main/resources/hdfs-default.xml | 9 ++++++--- .../hadoop/hdfs/TestDFSClientSocketSize.java | 20 +++++++++++-------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/HdfsConstants.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/HdfsConstants.java index a3af28a4f8c..7e522403827 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/HdfsConstants.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/HdfsConstants.java @@ -48,8 +48,8 @@ public class HdfsConstants { public static final byte COLD_STORAGE_POLICY_ID = 2; public static final String COLD_STORAGE_POLICY_NAME = "COLD"; - // TODO should be conf injected? - public static final int DEFAULT_DATA_SOCKET_SIZE = 128 * 1024; + public static final int DEFAULT_DATA_SOCKET_SIZE = 0; + /** * A special path component contained in the path for a snapshot file/dir */ diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml b/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml index a7d4ef5dd71..97d87175e28 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml @@ -2437,13 +2437,14 @@ dfs.client.socket.send.buffer.size - 131072 + 0 Socket send buffer size for a write pipeline in DFSClient side. This may affect TCP connection throughput. If it is set to zero or negative value, no buffer size will be set explicitly, thus enable tcp auto-tuning on some system. + The default value is 0. @@ -2848,23 +2849,25 @@ dfs.datanode.transfer.socket.send.buffer.size - 131072 + 0 Socket send buffer size for DataXceiver (mirroring packets to downstream in pipeline). This may affect TCP connection throughput. If it is set to zero or negative value, no buffer size will be set explicitly, thus enable tcp auto-tuning on some system. + The default value is 0. dfs.datanode.transfer.socket.recv.buffer.size - 131072 + 0 Socket receive buffer size for DataXceiver (receiving packets from client during block writing). This may affect TCP connection throughput. If it is set to zero or negative value, no buffer size will be set explicitly, thus enable tcp auto-tuning on some system. + The default value is 0. diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientSocketSize.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientSocketSize.java index a2a7afcc097..4b286f2e9cf 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientSocketSize.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientSocketSize.java @@ -30,7 +30,6 @@ import java.io.IOException; import java.net.Socket; -import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.DFS_CLIENT_SOCKET_SEND_BUFFER_SIZE_DEFAULT; import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.DFS_CLIENT_SOCKET_SEND_BUFFER_SIZE_KEY; import static org.junit.Assert.assertTrue; @@ -42,15 +41,16 @@ public class TestDFSClientSocketSize { } /** - * The setting of socket send buffer size in - * {@link java.net.Socket#setSendBufferSize(int)} is only a hint. Actual - * value may differ. We just sanity check that it is somewhere close. + * Test that the send buffer size default value is 0, in which case the socket + * will use a TCP auto-tuned value. */ @Test public void testDefaultSendBufferSize() throws IOException { - assertTrue("Send buffer size should be somewhere near default.", - getSendBufferSize(new Configuration()) >= - DFS_CLIENT_SOCKET_SEND_BUFFER_SIZE_DEFAULT / 2); + final int sendBufferSize = getSendBufferSize(new Configuration()); + LOG.info("If not specified, the auto tuned send buffer size is: {}", + sendBufferSize); + assertTrue("Send buffer size should be non-negative value which is " + + "determined by system (kernel).", sendBufferSize > 0); } /** @@ -73,6 +73,10 @@ public void testSpecifiedSendBufferSize() throws IOException { sendBufferSize1 > sendBufferSize2); } + /** + * Test that if the send buffer size is 0, the socket will use a TCP + * auto-tuned value. + */ @Test public void testAutoTuningSendBufferSize() throws IOException { final Configuration conf = new Configuration(); @@ -80,7 +84,7 @@ public void testAutoTuningSendBufferSize() throws IOException { final int sendBufferSize = getSendBufferSize(conf); LOG.info("The auto tuned send buffer size is: {}", sendBufferSize); assertTrue("Send buffer size should be non-negative value which is " + - "determined by system (kernel).", sendBufferSize > 0); + "determined by system (kernel).", sendBufferSize > 0); } private int getSendBufferSize(Configuration conf) throws IOException {