Skip to content

Commit 3f223be

Browse files
author
Inigo Goiri
committed
HDFS-14844. Make buffer of BlockReaderRemote#newBlockReader#BufferedOutputStream configurable. Contributed by Lisheng Sun.
1 parent b3173e1 commit 3f223be

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/HdfsClientConfigKeys.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ public interface HdfsClientConfigKeys {
148148
"dfs.client.key.provider.cache.expiry";
149149
long DFS_CLIENT_KEY_PROVIDER_CACHE_EXPIRY_DEFAULT =
150150
TimeUnit.DAYS.toMillis(10); // 10 days
151+
String DFS_CLIENT_BLOCK_READER_REMOTE_BUFFER_SIZE_KEY =
152+
"dfs.client.block.reader.remote.buffer.size";
153+
int DFS_CLIENT_BLOCK_READER_REMOTE_BUFFER_SIZE_DEFAULT = 8192;
151154

152155
String DFS_DATANODE_KERBEROS_PRINCIPAL_KEY =
153156
"dfs.datanode.kerberos.principal";

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/impl/BlockReaderFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ private BlockReader getRemoteBlockReader(Peer peer) throws IOException {
855855
fileName, block, token, startOffset, length,
856856
verifyChecksum, clientName, peer, datanode,
857857
clientContext.getPeerCache(), cachingStrategy,
858-
networkDistance);
858+
networkDistance, configuration);
859859
}
860860

861861
@Override

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/impl/BlockReaderRemote.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.UUID;
3030

3131
import org.apache.hadoop.classification.InterfaceAudience;
32+
import org.apache.hadoop.conf.Configuration;
3233
import org.apache.hadoop.fs.ReadOption;
3334
import org.apache.hadoop.hdfs.BlockReader;
3435
import org.apache.hadoop.hdfs.PeerCache;
@@ -55,6 +56,9 @@
5556
import org.slf4j.Logger;
5657
import org.slf4j.LoggerFactory;
5758

59+
import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.DFS_CLIENT_BLOCK_READER_REMOTE_BUFFER_SIZE_DEFAULT;
60+
import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.DFS_CLIENT_BLOCK_READER_REMOTE_BUFFER_SIZE_KEY;
61+
5862
/**
5963
* This is a wrapper around connection to datanode
6064
* and understands checksum, offset etc.
@@ -391,10 +395,13 @@ public static BlockReader newBlockReader(String file,
391395
Peer peer, DatanodeID datanodeID,
392396
PeerCache peerCache,
393397
CachingStrategy cachingStrategy,
394-
int networkDistance) throws IOException {
398+
int networkDistance, Configuration configuration) throws IOException {
395399
// in and out will be closed when sock is closed (by the caller)
400+
int bufferSize = configuration.getInt(
401+
DFS_CLIENT_BLOCK_READER_REMOTE_BUFFER_SIZE_KEY,
402+
DFS_CLIENT_BLOCK_READER_REMOTE_BUFFER_SIZE_DEFAULT);
396403
final DataOutputStream out = new DataOutputStream(new BufferedOutputStream(
397-
peer.getOutputStream()));
404+
peer.getOutputStream(), bufferSize));
398405
new Sender(out).readBlock(block, blockToken, clientName, startOffset, len,
399406
verifyChecksum, cachingStrategy);
400407

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/erasurecode/StripedBlockReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private BlockReader createBlockReader(long offsetInBlock) {
129129
return BlockReaderRemote.newBlockReader(
130130
"dummy", block, blockToken, offsetInBlock,
131131
block.getNumBytes() - offsetInBlock, true, "", peer, source,
132-
null, stripedReader.getCachingStrategy(), -1);
132+
null, stripedReader.getCachingStrategy(), -1, conf);
133133
} catch (IOException e) {
134134
LOG.info("Exception while creating remote block reader, datanode {}",
135135
source, e);

hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4098,6 +4098,18 @@
40984098
</description>
40994099
</property>
41004100

4101+
<property>
4102+
<name>dfs.client.block.reader.remote.buffer.size</name>
4103+
<value>8192</value>
4104+
<description>
4105+
The output stream buffer size of a DFSClient remote read. The buffer default value is 8KB. The buffer includes
4106+
only some request parameters that are: block, blockToken, clientName, startOffset, len, verifyChecksum,
4107+
cachingStrategy.
4108+
It is recommended to adjust the value according to the workload, which can reduce unnecessary memory
4109+
usage and the frequency of the garbage collection. A value of 512 might be reasonable.
4110+
</description>
4111+
</property>
4112+
41014113
<property>
41024114
<name>dfs.content-summary.limit</name>
41034115
<value>5000</value>

0 commit comments

Comments
 (0)