Use the following recommendations to tune Hadoop Distributed File System (HDFS) in E-MapReduce (EMR) for better performance and cluster stability. Each section explains the root cause of a common issue and how to address it.
Control the number of small files
The HDFS NameNode keeps metadata for every file in memory. When a large number of small files accumulate, the NameNode hits a memory bottleneck even if total disk capacity is not exhausted.
Merge existing small files into fewer, larger files to reduce NameNode memory pressure.
Limit files per directory
Spark, YARN, and other services can continuously write files to the same HDFS directory. HDFS enforces a maximum number of files per directory, and exceeding the limit causes job failures.
Plan your data layout in advance — classify files by time period or business type so no single directory grows unbounded. Set dfs.namenode.fs-limits.max-directory-items to define the limit. A value of 1,000,000 works well for most workloads.
To add the parameter:
-
In the EMR console, go to the HDFS service page and click the Configure tab.
-
Click the hdfs-site tab.
-
Click Add Configuration Item, add
dfs.namenode.fs-limits.max-directory-items, and set the value. -
Click Save.
For detailed steps, see Manage configuration items.
Tolerate failed DataNode volumes
By default, if multiple data storage volumes are configured for a DataNode and one of the volumes fails, the DataNode stops providing services. By default, at least one available volume is configured.
Raising the threshold lets a DataNode continue operating as long as the number of failed volumes stays within the configured limit (dfs.datanode.failed.volumes.tolerated = 0 by default).
To change the threshold:
-
In the EMR console, go to the HDFS service page and click the Configure tab.
-
Search for
dfs.datanode.failed.volumes.toleratedand update the value.
| Parameter | Default value | Description |
|---|---|---|
dfs.datanode.failed.volumes.tolerated |
0 | Maximum number of failed data volumes a DataNode tolerates before stopping services. |
If a DataNode has a failed disk and no other node can take over its workload, temporarily increase this value so the DataNode can keep serving data while you repair the disk.
Balance DataNode capacity
Adding DataNodes to an EMR cluster can leave data unevenly distributed across nodes, causing some DataNodes to become overloaded. Run the HDFS balancer to redistribute data.
The balancer consumes network bandwidth on DataNodes. Run it during off-peak hours.
Run the balancer
-
Log in to a node in your cluster.
-
(Optional) Set the balancer's maximum bandwidth:
hdfs dfsadmin -setBalancerBandwidth <bandwidth in bytes per second>Choose a value based on cluster load:
Cluster state Recommended value Equivalent Heavy load 2097152020 MB/s Normal 209715200200 MB/s Idle 10737418241 GB/s -
Switch to the
hdfsuser and start the balancer:su hdfs /opt/apps/HDFS/hdfs-current/sbin/start-balancer.sh -threshold 10The
-threshold 10flag means the cluster is considered balanced when no DataNode's disk usage deviates from the cluster average by more than 10%. -
Monitor progress in the balancer log:
tail -f /var/log/emr/hadoop-hdfs/hadoop-hdfs-balancer-master-1-1.c-xxx.logReplace
hadoop-hdfs-balancer-master-1-1.c-xxxwith the actual log file name on your cluster.
The balancer has finished when the log output contains Successfully.