HDFS Performance Tuning: NameNode, DataNode, Small Files and Short-Circuit Reads

Big Data and Hadoop Administrator 16 min min read Updated: Nov 17, 2026 Advanced
HDFS Performance Tuning: NameNode, DataNode, Small Files and Short-Circuit Reads
Advanced Topic 1 of 3

Method: Measure, Change One Thing, Measure Again

  1. Define the symptom (slow listing, slow reads, job waits)
  2. Find the layer: client, NameNode, DataNode, disk, network
  3. Collect baseline numbers
  4. Change one setting or fix one cause
  5. Compare and write down the result
  6. Roll back if there is no gain

Benchmark First

bash JAR=$HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-client-jobclient-*-tests.jar hadoop jar $JAR TestDFSIO -write -nrFiles 20 -size 5GB -resFile /tmp/write.txt hadoop jar $JAR TestDFSIO -read -nrFiles 20 -size 5GB -resFile /tmp/read.txt hadoop jar $JAR TestDFSIO -clean # NameNode metadata load (many small operations) hadoop jar $JAR nnbench -operation create_write -maps 12 -numberOfFiles 1000 -baseDir /benchmarks/nnbench

Compare throughput per node with the speed of the disks and network. If 12 disks can give 1.5 GB/s and you see 200 MB/s, something is limiting.

NameNode Tuning

SymptomCheckSetting / action
Slow ls, RPC timeoutsRpcQueueTimeAvgTime, CallQueueLengthRaise dfs.namenode.handler.count (about 20 x ln(cluster size)), enable the service RPC port for DataNode traffic
Long GC pausesGC logsRight-size heap, use G1GC, tune young gen, avoid swap
Block report stormsStartup timeStagger dfs.blockreport.initialDelay, use incremental block reports
Lock contentionSlow on heavy writesFewer huge deletes at once, separate hot paths via federation
Audit log slows downDisk IOUse async audit logging and a separate disk
xml <property><name>dfs.namenode.handler.count</name><value>128</value></property> <property><name>dfs.namenode.service.handler.count</name><value>64</value></property> <property><name>dfs.namenode.servicerpc-address.prod.nn1</name><value>nn1.hadoop.example.com:8022</value></property> <!-- DataNodes and ZKFC use this port --> <property><name>dfs.namenode.audit.log.async</name><value>true</value></property>
Service RPC: A separate port for DataNode and ZKFC traffic means client overload cannot block heartbeats and failover health checks.

DataNode Tuning

xml <property><name>dfs.datanode.handler.count</name><value>20</value></property> <property><name>dfs.datanode.max.transfer.threads</name><value>16384</value></property> <property><name>dfs.datanode.balance.bandwidthPerSec</name><value>104857600</value></property> <property><name>dfs.datanode.du.reserved</name><value>107374182400</value></property> <!-- 100 GB per volume kept for non-HDFS use --> <property><name>dfs.datanode.fsdataset.volume.choosing.policy</name> <value>org.apache.hadoop.hdfs.server.datanode.fsdataset.AvailableSpaceVolumeChoosingPolicy</value></property>

Short-Circuit Local Reads

When a client (for example a Spark executor) and a DataNode are on the same host, the client can read the block file directly instead of going through the DataNode over TCP.

xml <property><name>dfs.client.read.shortcircuit</name><value>true</value></property> <property><name>dfs.domain.socket.path</name><value>/var/lib/hadoop-hdfs/dn_socket</value></property>
bash mkdir -p /var/lib/hadoop-hdfs && chown hdfs:hadoop /var/lib/hadoop-hdfs && chmod 755 /var/lib/hadoop-hdfs

Block Size

Block sizeUse
128 MB (default)General
256 MBLarge sequential files (fewer blocks = less NameNode memory)
64 MB or smallerRarely a good idea

Block size is set per file at write time (dfs.blocksize). Changing the default does not affect existing files.

The Small File Problem

  • Each file, directory and block costs about 150 bytes or more of NameNode heap
  • Millions of 1 MB files waste memory, increase RPC load and create too many MapReduce/Spark tasks
  • Hive, Spark and streaming jobs are the usual sources
bash # find candidates: directories with many files and tiny average size hdfs oiv -p Delimited -i fsimage -o /tmp/fs.tsv awk -F'\t' '$7>0 && $7<10485760 {split($1,p,"/"); d=p[2]"/"p[3]"/"p[4]; c[d]++; s[d]+=$7} END{for(k in c) print c[k], s[k]/c[k], k}' /tmp/fs.tsv | sort -rn | head
FixHow
Compact in Spark/HiveRead and write with coalesce(n) or INSERT OVERWRITE ... DISTRIBUTE BY, ALTER TABLE ... CONCATENATE (ORC)
Use container formatsORC/Parquet instead of many text files, Avro or SequenceFile for logs
Hadoop archives (HAR)hadoop archive -archiveName logs.har -p /logs /archive (read-only, still stresses name space less)
Stop the sourceStreaming micro-batches: use larger triggers, Delta/Hudi/Iceberg compaction
QuotasName quota per team

Network and OS Checks

bash iperf3 -s # on node A iperf3 -c nodeA -P 4 # on node B: expect ~9.4 Gbit/s on 10GbE iostat -xm 5 # %util, await per disk sar -n DEV 5 3 # NIC throughput and errors ethtool eth0 | grep -E "Speed|Duplex"
Disk problems look like Hadoop problems: A single slow disk (high await) can slow down a whole job because tasks wait for the slowest replica. Use SMART monitoring and dfs.datanode.slow.io.warning.threshold.ms logs to find outliers.
Slow node detection: Enable the DataNode peer and disk outlier detection (dfs.datanode.peer.stats.enabled, dfs.datanode.fileio.profiling.sampling.percentage) so slow nodes are reported in the NameNode UI.

Conclusion

Benchmark first, then tune: more NameNode handlers with a service RPC port, DataNode threads and volume policy, short-circuit reads, proper block sizes, and a real fix for small files. Always change one thing at a time.

Quick Summary: TestDFSIO baseline; handlers + service RPC; short-circuit; fix small files.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators