Table of Contents


img-20260722-080742.png

Requirements

4 VM’s per user

workstation (namenode / resourcemanager / secondary namenode)
dn1 (datanode / nodemanager)
dn2 (datanode / nodemanager)
dn3 (datanode / nodemanager)

Configuration

verify /etc/hosts

$ cat /etc/hosts
# START of managed by Ansible
127.0.0.1 localhost
 
172.31.15.115 hdfs-cfreire-dn2
172.31.0.216  hdfs-cfreire-dn3
172.31.2.211  hdfs-cfreire-workstation
172.31.11.225 hdfs-cfreire-dn1
 
# END of managed by Ansible

Point all datanodes to workstation (resourcemanager)

$HADOOP_HOME/etc/hadoop/yarn-site.xml

<property>
  <name>yarn.resourcemanager.hostname</name>
  <value>hdfs-cfreire-workstation</value>
</property>

Point all nodes to workstation (namenode)

$HADOOP_HOME/etc/hadoop/core-site.xml

<property>
  <name>fs.default.name</name>
  <value>hdfs://hdfs-cfreire-workstation:9000</value>
</property>
 

Add workers to workstation (master)

etc/hadoop/workers

hdfs-cfreire-dn1
hdfs-cfreire-dn2
hdfs-cfreire-dn3

Fix capacity to scheduler to 50% of resources
$HADOOP_HOME/etc/hadoop/capacity-scheduler.xml

<!-- capacity-scheduler.xml -->
<property>
  <name>yarn.scheduler.capacity.maximum-am-resource-percent</name>
  <value>0.5</value>
</property>

test configuration

$ hadoop conftest
 
/usr/local/hadoop-3.5.0/etc/hadoop/kms-site.xml: valid
/usr/local/hadoop-3.5.0/etc/hadoop/mapred-site.xml: valid
/usr/local/hadoop-3.5.0/etc/hadoop/hdfs-rbf-site.xml: valid
/usr/local/hadoop-3.5.0/etc/hadoop/hadoop-policy.xml: valid
/usr/local/hadoop-3.5.0/etc/hadoop/httpfs-site.xml: valid
/usr/local/hadoop-3.5.0/etc/hadoop/hdfs-site.xml: valid
/usr/local/hadoop-3.5.0/etc/hadoop/yarn-site.xml: valid
/usr/local/hadoop-3.5.0/etc/hadoop/capacity-scheduler.xml: valid
/usr/local/hadoop-3.5.0/etc/hadoop/kms-acls.xml: valid
/usr/local/hadoop-3.5.0/etc/hadoop/core-site.xml: valid

Start cluster

Format namenode on workstation

hdfs namenode -format

Start all from workstation

start-all.sh

Diagnostic cluster

master java services

$ jps
 
26240 Jps
25625 SecondaryNameNode
25323 NameNode
25886 ResourceManager

worker java services

$ jps
25138 NodeManager
24947 DataNode
25253 Jps

Test cluster

$ yarn node -list
 
2026-07-22 21:07:33,304 INFO client.DefaultNoHARMFailoverProxyProvider: Connecting to ResourceManager at /0.0.0.0:8032
Total Nodes:3
         Node-Id             Node-State Node-Http-Address       Number-of-Running-Containers
hdfs-cfreire-dn1:39823          RUNNING hdfs-cfreire-dn1:8042                              0
hdfs-cfreire-dn2:35543          RUNNING hdfs-cfreire-dn2:8042                              0
hdfs-cfreire-dn3:36849          RUNNING hdfs-cfreire-dn3:8042                              0
 
$ yarn node -list -showDetails
2026-07-22 21:07:56,899 INFO client.DefaultNoHARMFailoverProxyProvider: Connecting to ResourceManager at /0.0.0.0:8032
2026-07-22 21:07:57,209 INFO conf.Configuration: resource-types.xml not found
2026-07-22 21:07:57,210 INFO resource.ResourceUtils: Unable to find 'resource-types.xml'.
Total Nodes:3
         Node-Id             Node-State Node-Http-Address       Number-of-Running-Containers
hdfs-cfreire-dn1:39823          RUNNING hdfs-cfreire-dn1:8042                              0
Detailed Node Information :
        Configured Resources : <memory:7200, vCores:2>
        Allocated Resources : <memory:0, vCores:0>
        Resource Utilization by Node : PMem:1826 MB, VMem:1826 MB, VCores:0.0
        Resource Utilization by Containers : PMem:0 MB, VMem:0 MB, VCores:0.0
        Node-Labels : 
hdfs-cfreire-dn2:35543          RUNNING hdfs-cfreire-dn2:8042                              0
Detailed Node Information :
        Configured Resources : <memory:7200, vCores:2>
        Allocated Resources : <memory:0, vCores:0>
        Resource Utilization by Node : PMem:1877 MB, VMem:1877 MB, VCores:0.0066644456
        Resource Utilization by Containers : PMem:0 MB, VMem:0 MB, VCores:0.0
        Node-Labels : 
hdfs-cfreire-dn3:36849          RUNNING hdfs-cfreire-dn3:8042                              0
Detailed Node Information :
        Configured Resources : <memory:7200, vCores:2>
        Allocated Resources : <memory:0, vCores:0>
        Resource Utilization by Node : PMem:1822 MB, VMem:1822 MB, VCores:0.013328891
        Resource Utilization by Containers : PMem:0 MB, VMem:0 MB, VCores:0.0
        Node-Labels : 
 

Maintenance

# refresh nodes  
hdfs dfsadmin -refreshNodes
 
# report node status  
hdfs dfsadmin -report
 
#List all the available TaskTrackers with the following command
hadoop job -list-active-trackers
 

Remove node

  1. Edit hdfs-site.xml add an entry for dfs.hosts.exclude with the location of the file
  2. Add the hostname to the file mentioned in dfs.hosts.exclude that you are planning to remove

report node status

hdfs dfsadmin -report

Managing a Hadoop Cluster

# Check the status of all the files on HDFS
$ hdfs fsck /
 
Connecting to namenode via http://hdfs-cfreire-workstation:9870/fsck?ugi=redhat&path=%2F
FSCK started by redhat (auth:SIMPLE) from /172.31.2.211 for path / at Wed Jul 22 20:50:51 WEST 2026
 
 
Status: HEALTHY
 Number of data-nodes:  3
 Number of racks:               1
 Total dirs:                    1
 Total symlinks:                0
 
Replicated Blocks:
 Total size:    0 B
 Total files:   0
 Total blocks (validated):      0
 Minimally replicated blocks:   0
 Over-replicated blocks:        0
 Under-replicated blocks:       0
 Mis-replicated blocks:         0
 Default replication factor:    3
 Average block replication:     0.0
 Missing blocks:                0
 Corrupt blocks:                0
 Missing replicas:              0
 Blocks queued for replication: 0
 
Erasure Coded Block Groups:
 Total size:    0 B
 Total files:   0
 Total block groups (validated):        0
 Minimally erasure-coded block groups:  0
 Over-erasure-coded block groups:       0
 Under-erasure-coded block groups:      0
 Unsatisfactory placement block groups: 0
 Average block group size:      0.0
 Missing block groups:          0
 Corrupt block groups:          0
 Missing internal blocks:       0
 Blocks queued for replication: 0
FSCK ended at Wed Jul 22 20:50:51 WEST 2026 in 1 milliseconds
 
# Check the locations of file
hdfs fsck / -files
 
# Check the locations of file blocks containing rack
hdfs fsck / -files -locations
 
# Check the locations of file blocks containing rack information
hdfs fsck / -files -blocks -racks
 

Exercise: Partitioning Data for Performance

Problem: You have a large log file (access.log) containing web server access records. To process this file efficiently using Hadoop Streaming, you want to partition it into 8 smaller files and then process these partitions in parallel.

Instructions:

  1. Create a sample access.log file: Generate a file with at least 100 lines of dummy access log data. Each line should be unique enough to demonstrate partitioning.
  2. Split the access.log file: Use a shell command to split access.log into 8 equal-sized partitions.
  3. Upload partitions to HDFS: Create an input directory in HDFS and upload all the partitioned files into it.
  4. Run a Hadoop Streaming job: Execute a simple Hadoop Streaming job that reads from the HDFS input directory containing the partitioned files. Configure the job to use 8 reducers to match the number of partitions. For this exercise, a simple mapper and reducer that just passes through the data (e.g., cat for mapper and reducer) is sufficient to demonstrate the partitioning.

Solution:

1. Create a sample access.log file:

# Create working directory
mkdir work && cd work
 
# Create directory on hdfs
hdfs dfs -mkdir -p /user/redhat/work
 
# Generate a dummy access.log file with 100 lines
for i in $(seq 1 100); do
  echo "192.168.1.$((i%255)) - user$i [$(date +'%d/%b/%Y:%H:%M:%S %z')] \"GET /page$i.html HTTP/1.1\" 200 1234 \"-\" \"Mozilla/5.0\"" >> access.log
done

2. Split the access.log file:

split -n l/4 access.log part_access_ -d --additional-suffix=.log

This command will create files like part_access_00.log, part_access_01.log, …, part_access_07.log.

3. Upload partitions to HDFS:

hdfs dfs -mkdir -p /user/redhat/input_access_logs
hdfs dfs -put part_access_*.log input_access_logs/
hdfs dfs -ls input_access_logs
hdfs fsck /user/redhat -files

4. Run a Hadoop Streaming job:

For this example, we’ll use cat as a placeholder mapper and reducer to simply demonstrate that the job runs across the partitions.

yarn jar $HADOOP_HOME/share/hadoop/tools/lib/hadoop-streaming-3.5.0.jar \
  -D mapreduce.job.reduces=2 \
  -D mapreduce.map.memory.mb=1024 \
  -D mapreduce.reduce.memory.mb=1024 \
  -D yarn.app.mapreduce.am.resource.mb=1024 \
  -input /user/redhat/input_access_logs \
  -output /user/redhat/output_access_logs_$(date +'%Y%m%d-%H%M') \
  -mapper /bin/cat \
  -reducer /bin/cat

Verification:

After the job completes, you can check the output in HDFS:

hdfs dfs -ls /user/redhat/output_access_logs_YYYYMMDD-HHMM/

You should see 8 part-r-xxxxx files, indicating that 8 reducers processed the data, each likely handling one of the input partitions.

hdfs dfs -cat /user/hadoop/output_access_logs_YYYYMMDD-HHMM/part-r-00000 | head -n 5

This will show the first 5 lines of one of the output files.

Python MapReducer benchmark

Count login attempts in fail access log file.

Number of lines in files

  • 100 bigdata-sample.txt
  • 350922 bigdata-medium.txt
  • 2316606 bigdata-complete.txt

sample file

bigdata-sample.txt

Sep 13 07:38:34 moodle sshd[60588]: Failed password for root from 222.186.42.137 port 58082 ssh2
Sep 13 07:38:36 moodle unix_chkpwd[60660]: password check failed for user (root)
Sep 13 07:38:36 moodle sshd[60588]: pam_succeed_if(sshd:auth): requirement "uid >= 1000" not met by user "root"
Sep 13 07:38:37 moodle sshd[60588]: Failed password for root from 222.186.42.137 port 58082 ssh2
Sep 13 07:38:37 moodle unix_chkpwd[60661]: password check failed for user (root)
Sep 13 07:38:37 moodle sshd[60588]: pam_succeed_if(sshd:auth): requirement "uid >= 1000" not met by user "root"
Sep 13 07:38:39 moodle sshd[60588]: Failed password for root from 222.186.42.137 port 58082 ssh2
Sep 13 07:38:42 moodle sshd[60588]: Received disconnect from 222.186.42.137 port 58082:11:  [preauth]
Sep 13 07:38:42 moodle sshd[60588]: Disconnected from 222.186.42.137 port 58082 [preauth]
Sep 13 07:38:42 moodle sshd[60588]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=222.186.42.137  user=root
 

logins_fail_map.py

#!/usr/bin/python3
 
import re
import sys
 
query = r'(.*) moodle.*authentication failure.*rhost=(.*)  user=(.*)'
 
for line in sys.stdin:
    result = re.match(query, line)
    if result:
        print(result.group(1), result.group(2), result.group(3), sep=',')
 

logins_fail_reducer.py

#!/usr/bin/python3
 
import sys
 
user_counter = {}
 
for line in sys.stdin:
    user = line.rstrip().split(",")[2]
    if user not in user_counter:
        user_counter[user] = 0
    else:
        user_counter[user] = user_counter[user] +1
print(user_counter)
 

Start yarn job

# Test map script
python3 logins_fail_map.py < bigdata-sample.txt
 
# Test reducer script
python3 logins_fail_map.py < bigdata-sample.txt | python3 logins_fail_reducer.py
 
# Create working dir on hdfs
hdfs dfs -mkdir bigdata-files
 
# put sample
hdfs dfs -put bigdata-medium.txt bigdata-files/
 
hadoop jar $HADOOP_HOME/share/hadoop/tools/lib/hadoop-streaming-3.5.0.jar \
-files logins_fail_map.py,logins_fail_reducer.py \
-input bigdata-files/bigdata-medium.txt \
-output output-$(date +'%Y%m%d-%H%M') \
-mapper logins_fail_map.py \
-reducer logins_fail_reducer.py
 
# Result
File System Counters
	FILE: Number of bytes read=1151931
	FILE: Number of bytes written=3269990
 
Job Counters 
	Launched map tasks=2
	Launched reduce tasks=1
	Data-local map tasks=2
	Total time spent by all maps in occupied slots (ms)=12539 # time
	Total time spent by all reduces in occupied slots (ms)=10844 # time
 
Map-Reduce Framework
	Map input records=350922  # lines
	Map output records=30581
	Map output bytes=1090763
	Map output materialized bytes=1151937
	Input split bytes=266
	Combine input records=0
	Combine output records=0
	Reduce input groups=30230
	Reduce shuffle bytes=1151937
	Reduce input records=30581
	Reduce output records=1
	Spilled Records=61162
	Shuffled Maps =2
	Failed Shuffles=0
	Merged Map outputs=2
	GC time elapsed (ms)=118
	CPU time spent (ms)=7440
	Physical memory (bytes) snapshot=829440000
	Virtual memory (bytes) snapshot=9600212992
	Total committed heap usage (bytes)=483393536
	Peak Map Physical memory (bytes)=311533568
	Peak Map Virtual memory (bytes)=3193638912
	Peak Reduce Physical memory (bytes)=222720000
	Peak Reduce Virtual memory (bytes)=3213070336
 
 

Process complete file

hdfs dfs -put bigdata-complete.txt bigdata-files/
 
$ hadoop jar $HADOOP_HOME/share/hadoop/tools/lib/hadoop-streaming-3.5.0.jar \
-files logins_fail_map.py,logins_fail_reducer.py \
-input bigdata-files/bigdata-complete.txt \
-output output-$(date +'%Y%m%d-%H%M') \
-mapper logins_fail_map.py \
-reducer logins_fail_reducer.py
 
# Results
 File System Counters
	FILE: Number of bytes read=7288531
	FILE: Number of bytes written=15543199
 
Job Counters 
	Launched map tasks=2
	Launched reduce tasks=1
	Data-local map tasks=2
	Total time spent by all maps in occupied slots (ms)=15755
	Total time spent by all reduces in occupied slots (ms)=3937
	Total time spent by all map tasks (ms)=15755
	Total time spent by all reduce tasks (ms)=3937
 
Map-Reduce Framework
	Map input records=2316606
	Map output records=192923
	Map output bytes=6902679
	Map output materialized bytes=7288537
	Input split bytes=270
	Combine input records=0
	Combine output records=0
	Reduce input groups=192786
	Reduce shuffle bytes=7288537
	Reduce input records=192923
	Reduce output records=1
	Spilled Records=385846
	Shuffled Maps =2
	Failed Shuffles=0
	Merged Map outputs=2
	GC time elapsed (ms)=91
	CPU time spent (ms)=11070
	Physical memory (bytes) snapshot=919642112
	Virtual memory (bytes) snapshot=9585643520
	Total committed heap usage (bytes)=545259520
	Peak Map Physical memory (bytes)=353574912
	Peak Map Virtual memory (bytes)=3193933824
	Peak Reduce Physical memory (bytes)=219017216
	Peak Reduce Virtual memory (bytes)=3198070784
 

Split to increase speed

split -n l/4 bigdata-complete.txt part_ -d --additional-suffix=.txt
 
hdfs dfs -put part_*.txt bigdata-files/
 
$ hadoop jar $HADOOP_HOME/share/hadoop/tools/lib/hadoop-streaming-3.5.0.jar \
	-D mapreduce.job.reduces=4 \
	-files logins_fail_map.py,logins_fail_reducer.py \
	-input bigdata-files/ \
	-output output-$(date +'%Y%m%d-%H%M') \
	-mapper logins_fail_map.py -reducer logins_fail_reducer.py
 
File System Counters
	FILE: Number of bytes read=7288531
	FILE: Number of bytes written=15543132
	FILE: Number of read operations=0
	FILE: Number of large read operations=0
	FILE: Number of write operations=0
	HDFS: Number of bytes read=237015891
	HDFS: Number of bytes written=389
	HDFS: Number of read operations=11
	HDFS: Number of large read operations=0
	HDFS: Number of write operations=2
	HDFS: Number of bytes read erasure-coded=0
Job Counters 
	Killed map tasks=1
	Launched map tasks=2
	Launched reduce tasks=1
	Data-local map tasks=2
	Total time spent by all maps in occupied slots (ms)=14139
	Total time spent by all reduces in occupied slots (ms)=3511
	Total time spent by all map tasks (ms)=14139
	Total time spent by all reduce tasks (ms)=3511
	Total vcore-milliseconds taken by all map tasks=14139
	Total vcore-milliseconds taken by all reduce tasks=3511
	Total megabyte-milliseconds taken by all map tasks=14478336
	Total megabyte-milliseconds taken by all reduce tasks=3595264
Map-Reduce Framework
	Map input records=2316606
	Map output records=192923
	Map output bytes=6902679
	Map output materialized bytes=7288537
	Input split bytes=252
	Combine input records=0
	Combine output records=0
	Reduce input groups=192786
	Reduce shuffle bytes=7288537
	Reduce input records=192923
	Reduce output records=1
	Spilled Records=385846
	Shuffled Maps =2
	Failed Shuffles=0
	Merged Map outputs=2
	GC time elapsed (ms)=104
	CPU time spent (ms)=11170
	Physical memory (bytes) snapshot=946585600
	Virtual memory (bytes) snapshot=9586528256
	Total committed heap usage (bytes)=556793856
	Peak Map Physical memory (bytes)=365424640
	Peak Map Virtual memory (bytes)=3193958400
	Peak Reduce Physical memory (bytes)=226250752
	Peak Reduce Virtual memory (bytes)=3198619648
Shuffle Errors
	BAD_ID=0
	CONNECTION=0
	IO_ERROR=0
	WRONG_LENGTH=0
	WRONG_MAP=0
	WRONG_REDUCE=0
File Input Format Counters 
	Bytes Read=237015639
File Output Format Counters 
	Bytes Written=389

Hadoop MapReduce Benchmark — Comparative Report

RunDatasetLayoutWall-clock*Killed mapsVerdict
run1350,922 lines (~34 MB)sample~23.4 s0Baseline; reduce dominates
run22,316,606 lines (~226 MB)1 file~19.7 s0Fast, but read pattern = single split chain
run32,316,606 lines (~226 MB)2 parts~17.6 s1Fastest wall-clock, but paid for speculative execution

* Wall-clock ≈ Total time spent by all maps + Total time spent by all reduces (sequential phases, same cluster of 2 mappers / 1 reducer).

  1. The Indicators That Actually Matter

Not all 60+ counters in a Hadoop job summary carry signal. For comparing these three runs, focus on these:

End-to-end latency (wall-clock)

The sum of Total time spent by all maps + Total time spent by all reduces is a tight proxy for job latency because map and reduce phases are serialized when there is only one reducer.

Metricrun1run2run3
Map phase (ms)12,53915,75514,139
Reduce phase (ms)10,8443,9373,511
Total (ms)23,38319,69217,650
Map share54 %80 %80 %

Why it matters: the only metric users actually feel.

Throughput (records / MB per second)

Normalize by data size to compare efficiency, not raw size.

Metricrun1run2run3
Input records / s (map)27,985147,038163,851
Input MB / s (map)2.8615.0416.76
Output records / s (reduce)2.8249.054.9

Why it matters: shows whether the cluster is CPU/IO-bound or just paying fixed startup cost.

Reduce-vs-Map imbalance

A reducer that finishes in <2 s after a 15 s map is healthy (good overlap with shuffle). A reducer that takes ~87 % of the map time on small data is paying fixed overhead, not doing work.

run1run2run3
Reduce / Map ratio0.860.250.25

In run1 the reducer is the bottleneck. In run2/3 the reducer is essentially free because the cost is amortized over ~6.6× more data.

What the Killed map tasks = 1 in run3 really means

Hadoop’s speculative execution is on by default. When the JobTracker/AM sees one map of the same split lagging, it schedules a duplicate on another node. Whichever finishes first wins; the other is KILLED.

Concrete implications:

  1. run3’s 14,139 ms “map time” is misleading — it includes a successful retry that masked a slow first attempt.
  2. The cluster is heterogeneous or contended at the moment of run3 (or that one part-file was on a slower DataNode). Otherwise speculation would not have triggered.
  3. If you want a fair comparison, look at Total time spent by all maps in occupied slots (ms): run2 = 15,755 ms, run3 = 14,139 ms. The savings are smaller than the wall-clock delta suggests once you account for the wasted attempt.
  4. To eliminate the noise: disable speculation (mapreduce.map.speculative=false) and rerun, or ensure input parts are byte-balanced and on identical storage tiers.

Headline Numbers — At a Glance

                          run1         run2         run3
                          ----         ----         ----
input lines            350,922    2,316,606    2,316,606
input MB (HDFS read)      34.2        226.0        226.0
map tasks                    2            2            2
reduce tasks                 1            1            1
killed map tasks             0            0            1
map time (ms)           12,539       15,755       14,139
reduce time (ms)        10,844        3,937        3,511
wall-clock (ms)         23,383       19,692       17,650
CPU time (ms)            7,440       11,070       11,170
GC time (ms)               118           91          104
peak map RAM (MB)          297          337          349
peak reduce RAM (MB)       212          209          216
throughput (rec/s)      27,985      147,038      163,851
throughput (MB/s)         2.86        15.04        16.76
map-output records      30,581      192,923      192,923
reduce-output records        1            1            1
data-local tasks           2/2          2/2          2/2

Recommendations

  1. Drop run1 as a production benchmark. Its reduce overhead dominates and gives a pessimistic picture. Use it only as a smoke test.
  2. Between run2 and run3, run2 is the cleaner measurement. Same resource consumption, no killed tasks, deterministic.
  3. Pre-splitting to 2 parts saved ~10 % of wall-clock but introduced a speculative-execution failure. Net gain is real but smaller than it looks. With 3+ parts the saving grows sub-linearly (Amdahl).
  4. Bigger lever than splitting: more reducers. A single reducer is serialising the entire aggregation. Going from 1 → 4 reducers typically gives 2–3× on this workload shape.
  5. The job is map-bound at scale. Future tuning should target the map side: larger blocks (already 128 MB here, fine), compression (Snappy for intermediate), or a Combiner to shrink Map output bytes.
  6. Disable speculation for benchmarks (mapreduce.map.speculative=false) so Killed map tasks = 1 does not contaminate timing comparisons.

Reproducing the comparison

# Each job prints this block; capture with >> or 2>&1.
hadoop jar <job.jar> <MainClass> \
    -Dmapreduce.job.workflow.id=runN \
    <input-path> <output-path> 2>&1 | tee runN.txt

For apples-to-apples timing across runs, also set:

<property>
  <name>mapreduce.map.speculative</name><value>false</value>
</property>
<property>
  <name>mapreduce.reduce.speculative</name><value>false</value>
</property>