Sitemap

🌟Dealing with Small Files in Hadoop🌟

3 min readJun 10, 2024

--

Hadoop, the powerful warrior of big data processing, can easily handle terabytes of information. However, even the mightiest heroes have weaknesses, and that weakness comes in the form of small files. 🦸‍♂️

Although Hadoop is built to excel at managing massive datasets, many small files can overwhelm it. This is known as the “Small Files Issue.” 📁

Why Small Files Are a Big Problem?��

📍Hadoop Distributed File System (HDFS): At the core of Hadoop, HDFS breaks down data into fixed-size blocks, typically 64MB for Hadoop version 1.0 or 128MB for Hadoop version 2.0. Regardless of size, each file occupies at least one block. In short, a small file is significantly smaller than the HDFS block size.

📍Metadata Overload: HDFS keeps track of every file and block in the system. Managing a million tiny files, each using a block results in a massive amount of metadata for the NameNode to handle. This strains memory and slows down operations.

📍MapReduce Chaos: Hadoop’s processing engine, MapReduce, launches tasks (mappers) for each file. This can be inefficient for a large number of tiny files, leading to wasted resources and slower processing.

𝐒𝐜𝐞𝐧𝐚𝐫𝐢𝐨:

Imagine when we are analyzing web server logs. Each user visit creates a small log file. Millions of visits could result in millions of tiny files. Processing these files individually would be a nightmare for Hadoop. The NameNode would be overloaded with metadata, and MapReduce would be launching millions of inefficient tasks. How can we overcome such a problem? 🤔

𝐒𝐨𝐥𝐮𝐭𝐢𝐨𝐧:

📍 Here’s what we can do:

1. File Archiving: HAR is a file archiving format in Hadoop that combines multiple small files into a single archive file. It reduces the NameNode memory overhead, speeds up processing, reduces the number of files, and improves efficiency.

Get Lalitha Mohanasundaram’s stories in your inbox

Join Medium for free to get updates from this writer.

2. Sequence Files: Hadoop offers Sequence Files, a special format that groups multiple records into a single file. This allows efficient processing of logically small data units.

3. Compress small files: Compressing small files before storing them in HDFS can reduce storage overhead and improve processing efficiency. Use codecs like Snappy or Gzip for compression.

Creating HAR files

HAR (Hadoop Archive) is a file format that allows you to bundle small files into larger archive files. We can create HAR files using the har command provided by Hadoop utilities. This command creates a HAR file from a directory containing small files.

hadoop archive -archiveName <archive-name>.har -p <parent-dir> <src-dir> <dest-dir>

· <archive-name>: Name of the HAR file to be created.

· <parent-dir>: Parent directory of the source directory.

· <src-dir>: Source directory containing the small files.

· <dest-dir>: Destination directory where the HAR file will be created.

· -p: This defines the relative path within the archive where the source files will be stored.

Thank you for Reading

If you like this post:

  • Please show your support by following and with a clap 👏 or several claps!

--

--