Site icon DataFlair

Rack Awareness in Hadoop HDFS – An Introductory Guide

rack awareness in hadoop

Ever thought how NameNode choose the Datanode for storing the data blocks and their replicas?

HDFS stores files across multiple nodes (DataNodes) in a cluster. To get the maximum performance from Hadoop and to improve the network traffic during file read/write, NameNode chooses the DataNodes on the same rack or nearby racks for data read/write. Rack awareness is the concept of choosing the closer DataNode based on rack information.

In this article, we will study the rack awareness concept in detail.

We will first see what is the rack, what is rack awareness, the reason for using rack awareness, block replication policies, and benefits of Rack Awareness.

Let’s start with the introduction of the rack.

What is a rack?

The Rack is the collection of around 40-50 DataNodes connected using the same network switch. If the network goes down, the whole rack will be unavailable. A large Hadoop cluster is deployed in multiple racks.

What is Rack Awareness in Hadoop HDFS?

In a large Hadoop cluster, there are multiple racks. Each rack consists of DataNodes. Communication between the DataNodes on the same rack is more efficient as compared to the communication between DataNodes residing on different racks.

To reduce the network traffic during file read/write, NameNode chooses the closest DataNode for serving the client read/write request. NameNode maintains rack ids of each DataNode to achieve this rack information. This concept of choosing the closest DataNode based on the rack information is known as Rack Awareness.

Technology is evolving rapidly!
Stay updated with DataFlair on WhatsApp!!

A default Hadoop installation assumes that all the DataNodes reside on the same rack.

 Why Rack Awareness?

The reasons for the Rack Awareness in Hadoop are:

  1. To reduce the network traffic while file read/write, which improves the cluster performance.
  2. To achieve fault tolerance, even when the rack goes down (discussed later in this article).
  3. Achieve high availability of data so that data is available even in unfavorable conditions.
  4. To reduce the latency, that is, to make the file read/write operations done with lower delay.

NameNode uses a rack awareness algorithm while placing the replicas in HDFS.

Let us now study the replica placement via Rack Awareness in Hadoop.

Replica placement via Rack awareness in Hadoop

We know HDFS stores replicas of data blocks of a file to provide fault tolerance and high availability. Also, the network bandwidth between nodes within the rack is higher than the network bandwidth between nodes on a different rack.

If we store replicas on different nodes on the same rack, then it improves the network bandwidth, but if the rack fails (rarely happens), then there will be no copy of data on another rack.

Again, if we store replicas on unique racks, then due to the transfer of blocks to multiple racks while writes increase the cost of writes.

Therefore, NameNode on multiple rack cluster maintains block replication by using inbuilt Rack awareness policies which says:

For the common case where the replication factor is three, the block replication policy put the first replica on the local rack, a second replica on the different DataNode on the same rack, and a third replica on the different rack.

Also, while re-replicating a block, if the existing replica is one, place the second replica on a different rack. If the existing replicas are two and are on the same rack, then place the third replica on a different rack.

This policy improves write performance and network traffic without compromising fault tolerance.

Rack Awareness Example

In the above GIF, we are having a file “File.txt” divided into three blocks A, B, and C. To provide fault tolerance, HDFS creates replicas of blocks. NameNode places the first copy of each block on the closest DataNode, the second replica of each block on different DataNode on the same rack, and the third replica on different DataNode on a different rack.

What about performance?

Advantages of Implementing Rack Awareness

Some of the main advantages of Rack Awareness are:

1. Preventing data loss against rack failure

Rack Awareness policy puts replicas at different rack as well, thus ensures no data loss even if the rack fails.

2. Minimize the cost of write and maximize the read speed

Rack awareness reduces write traffic in between different racks by placing write requests to replicas on the same rack or nearby rack, thus reducing the cost of write. Also, using the bandwidth of multiple racks increases the read performance.

3. Maximize network bandwidth and low latency

Rack Awareness enables Hadoop to maximize network bandwidth by favoring the transfer of blocks within racks over transfer between racks. Especially with rack awareness, the YARN is able to optimize MapReduce job performance. It assigns tasks to nodes that are ‘closer’ to their data in terms of network topology. This is particularly beneficial in cases where tasks cannot be assigned to nodes where their data is stored locally.

Summary

In this article, you have studied the rack awareness concept, which is the selection of the closest node based on the rack information.

We have seen the reasons for introducing rack awareness in Hadoop like network bandwidth, high availability, etc.

We have also discussed the Rack awareness policy used by the NameNode to maintain block replication. The article also enlisted the advantages of Rack Awareness.

Now, its time to explore how Hadoop HDFS achieves High Availability

Any Doubt? Ask our DataFlair experts in the comment section.

Keep Learning

Exit mobile version