Yarn Distributed cache, no mapper/reducer
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache Hadoop is an open-source framework that allows for the distributed processing of large data sets across clusters of computers using simple programming models. One of Hadoop’s core components is YARN (Yet Another Resource Negotiator), which is responsible for managing compute resources in clusters and using them for scheduling users' applications. The YARN Distributed Cache plays a crucial role in improving the efficiency and performance of Hadoop jobs by caching files needed by applications.
Understanding YARN Distributed Cache
The YARN Distributed Cache is designed to cache files, when needed, so that they do not have to be downloaded or generated every time they are required. This feature is particularly useful in the context of Hadoop MapReduce jobs where the same data may be needed repeatedly by multiple tasks across different nodes in the cluster.
When a Hadoop job is submitted, the files specified as being part of the Distributed Cache are copied to each of the YARN cluster nodes before the execution of any tasks begins. By doing so, tasks do not need to fetch these files from a central source, thus reducing the load on the network and speeding up the processing of tasks.
Key Features:
- Resource sharing: Once a file is placed in the Distributed Cache, it can be shared by multiple tasks in various jobs.
- Efficiency: Caching data locally saves significant time because the data does not need to be transferred over the network multiple times.
- Scalability: The Distributed Cache scales automatically as the use of Hadoop scales. As more nodes are added, the Distributed Cache capability expands.
Usage Examples
Adding Files to the Distributed Cache
To add files to the Distributed Cache, you can specify them in your job configuration:
Here, #yourfile is an alias for the file, providing a local reference for tasks to utilize.
Accessing Files in the Distributed Cache
To access these files within a Mapper or Reducer:
Best Practices and Considerations
When using the YARN Distributed Cache, there are several best practices and considerations to keep in mind:
- Correctness: Ensure that any file added to the cache is not modified during a job, as this could lead to inconsistent results or job failures.
- Performance: Use the Distributed Cache only for read-only files or static reference data to avoid duplication and excessive memory use.
- Cleanup: Files in the Distributed Cache are automatically deleted when the application finishes or is aborted.
Challenges
Despite its benefits, the Distributed Cache can introduce challenges such as cache coherency and management overhead, especially in very large clusters or in scenarios with highly dynamic data.
Technical Summary Table
| Feature | Description |
| Resource Sharing | Enables files to be shared among tasks, reducing redundant data transfers. |
| Efficiency | Local caching of files reduces network traffic and expedites task processing. |
| Scalability | As clusters grow, the Distributed Cache capability automatically expands. |
| Usage | Files are specified in job configurations and accessed via aliases in tasks. |
| Best Practices | Use for read-only or static data. Maintain the immutability of cached files. |
In summary, YARN's Distributed Cache is a powerful component that can significantly enhance the performance and efficiency of Hadoop applications by ensuring faster access to necessary data and reducing the overhead associated with data transfer across the network. However, it requires prudent management and usage to avoid common pitfalls such as cache incoherence and unnecessary resource consumption.
Related reading
- ZeroMQ Publish and Subscribe concurrently
- Zookeeper-Kafka and Consistent hashing
- ZooKeeper - clients co-ordination after one or more client lose connection with ZooKeeper
- ZooKeeper and Shared Nothing. Is it Scalable?
- Accessing a File from Distributed Cache in Pig UDF Java class, Amazon EMR
- Accessing data on distributed database on OrientDB
- Zookeeper (Curator framework) explicitly giving up the leaderLatch
- ZooKeeper session expired in tests

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.