Tune Hadoop Cluster to get Maximum Performance (Part 2)
In previous part we have seen that how can we tune our operating system to get maximum performance for Hadoop, in this article I will be focusing on how to tune hadoop cluster to get performance boost on hadoop level
Before I actually start explaining tuning parameters let me cover some basic terms that are required to understand Hadoop level tuning.
What is YARN?
YARN – Yet another resource negotiator, this is Map-reduce version 2 with many new features such as dynamic memory assignment for mappers and reducers rather than having fixed slots etc.
What is Container?
Container represents allocated Resources like CPU, RAM etc. It’s a JVM process, in YARN AppMaster, Mapper and Reducer runs inside the Container.
Let’s get into the game now:
1. Resource Manager (RM) is responsible for allocating resources to mapreduce jobs.
2. For brand new Hadoop cluster (without any tuning) resource manager will get 8192MB (“yarn.nodemanager.resource.memory-mb”) memory per node only.
3. RM can allocate up to 8192 MB (“yarn.scheduler.maximum-allocation-mb”) to the Application Master container.
4. Default minimum allocation is 1024 MB (“yarn.scheduler.minimum-allocation-mb”).
5. The AM can only negotiate resources from Resource Manager that are in increments of (“yarn.scheduler.minimum-allocation-mb”) & it cannot exceed (“yarn.scheduler.maximum-allocation-mb”).
6. Application Master Rounds off (“mapreduce.map.memory.mb“) & (“mapreduce.reduce.memory.mb“) to a value devisable by (“yarn.scheduler.minimum-allocation-mb“).
What are these properties ? What can we tune ?
Default value is 1024m
Sets the minimum size of container that YARN will allow for running mapreduce jobs.
Default value is 8192m
The largest size of container that YARN will allow us to run the Mapreduce jobs.
Default value is 8GB
Total amount of physical memory (RAM) for Containers on worker node.
Set this property= Total RAM – (RAM for OS + Hadoop Daemons + Other services)
Default value is 2.1
The amount of virtual memory that each Container is allowed
This can be calculated with: containerMemoryRequest*vmem-pmem-ratio
These are the hard limits enforced by Hadoop on each mapper or reducer task. (Maximum memory that can be assigned to mapper or reducer’s container)
Default value – 1GB
The heapsize of the jvm –Xmx for the mapper or reducer task.
This value should always be lower than mapreduce.[map|reduce].memory.mb.
Recommended value is 80% of mapreduce.map.memory.mb/ mapreduce.reduce.memory.mb
The amount of memory for ApplicationMaster
heapsize for application Master
The number of cores that a node manager can allocate to containers is controlled by the yarn.nodemanager.resource.cpu-vcores property. It should be set to the total number of cores on the machine, minus a core for each daemon process running on the machine (datanode, node manager, and any other long-running processes).
Default value – 100MB
This is very important property to tune, when map task is in progress it writes output into a circular in-memory buffer. The size of this buffer is fixed and determined by io.sort.mb property
When this circular in-memory buffer gets filled (mapreduce.map. sort.spill.percent: 80% by default), the SPILLING to disk will start (in parallel using a separate thread). Notice that if the splilling thread is too slow and the buffer is 100% full, then the map cannot be executed and thus it has to wait.
Hadoop uses buffer size of 4KB by default for its I/O operations, we can increase it to 128K in order to get good performance and this value can be increased by setting io.file.buffer.size= 131072 (value in bytes) in core-site.xml
Short-circuit reads – When reading a file from HDFS, the client contacts the datanode and the data is sent to the client via a TCP connection. If the block being read is on the same node as the client, then it is more efficient for the client to bypass the network and read the block data directly from the disk.
We can enable short-circuit reads by setting this property to “true”
Default value is 10.
Now imagine the situation where map task is running, each time the memory buffer reaches the spill threshold, a new spill file is created, after the map task has written its last output record, there could be several spill files. Before the task is finished, the spill files are merged into a single partitioned and sorted output file.
The configuration property mapreduce.task.io.sort.factor controls the maximum number of streams to merge at once.
Default value is 5
The map output file is sitting on the local disk of the machine that ran the map task
The map tasks may finish at different times, so the reduce task starts copying their outputs as soon as each completes
The reduce task has a small number of copier threads so that it can fetch map outputs in parallel.
The default is five threads, but this number can be changed by setting the mapreduce.reduce.shuffle.parallelcopies property
I tried my best to cover as much as I can, there are plenty of things you can do for tuning! I hope this article was helpful to you. What I recommend you guys is try tuning above properties by considering total available memory capacity, total number of cores etc. and run the Teragen, Terasort etc. benchmarking tool to get the results, try tuning until you get best out of it!!