Optimization and analysis of large scale data sorting algorithm based on Hadoop

Zhuo Wang, Longlong Tian, Dianjie Guo, Xiaoming Jiang

Abstract

Sorting massive datasets efficiently is a cornerstone of big data processing. While Apache Hadoop provides a built-in shuffle and sort phase, it often suffers from low efficiency and significant load imbalance when handling skewed data distributions. This paper presents an optimized multi-round MapReduce algorithm designed to address these bottlenecks. By incorporating an initial sampling phase to determine data distribution, the algorithm partitions data uniformly, enabling high-speed in-memory sorting. Experimental results demonstrate that this optimized approach consistently outperforms the standard Hadoop shuffle-sort mechanism, particularly as data scales beyond the limits of traditional memory management.

1. Introduction

In the ecosystem of big data, sorting is a fundamental operation required for various analytical tasks. Hadoop's MapReduce framework is the industry standard for distributed processing, yet its default "shuffle and sort" phase has inherent limitations. The primary challenge is load imbalance: standard partitioning often results in a skewed distribution where specific reducers are overwhelmed with data while others remain underutilized. This skew forces the system to spill data to disk, a process significantly slower than in-memory operations. To overcome this, we propose a strategy that prioritizes load balancing through predictive sampling.

2. Proposed Methodology: Multi-Round MapReduce

The core of our optimization lies in a multi-round MapReduce architecture. Rather than a single pass, the algorithm utilizes two distinct stages to ensure data is handled efficiently.

Workflow of the proposed multi-round MapReduce sorting algorithm.

2.1 Round 1: Sampling and Load Balancing

The first stage involves a lightweight MapReduce job that performs random sampling across the input dataset. By taking small samples (e.g., 4KB per site), the system constructs a statistical profile of the data distribution. This profile is used to calculate "division sites" or partition points that aim to divide the total data into roughly equal segments.

2.2 Round 2: Clustering and In-Memory Sorting

In the second stage, the data is routed according to the partition points established in Round 1.

  • In-Memory Processing: If a data segment fits within the allocated RAM of a reducer, it is sorted instantly using a priority queue.
  • Recursive Refinement: If a segment remains too large for memory (designated as a "Big File"), the algorithm triggers a recursive loop, returning the segment to Round 1 for further subdivision. This ensures that no single reducer is ever forced into inefficient disk-heavy sorting.

3. Sampling and Partitioning Logic

The effectiveness of the algorithm hinges on the accuracy of the division points. By utilizing a HashMap and priority queue during the sampling phase, the system identifies the frequency of data values.

Logic for determining division points based on sample statistics and memory constraints.

As shown in the figure above, the DivisionCount is calculated by factoring the assigned memory against the total data size and sample counts. This mathematical approach ensures that each partition is optimized for the hardware's specific memory constraints, maximizing the use of RAM over disk I/O.

4. Experimental Evaluation

The algorithm was tested in a pseudo-distributed Hadoop environment using randomly generated datasets ranging from 30MB to 180MB.

4.1 Performance and Scalability

At lower data volumes (30MB-40MB), the overhead of the sampling round resulted in performance comparable to the baseline. However, as the dataset size increased, the benefits of load balancing became clear. For a 150MB dataset, the optimized algorithm completed the task in 100 seconds, a 10.7% improvement over the baseline's 112 seconds.

4.2 Robustness Under Heavy Load

The most critical finding occurred at the 180MB threshold. In our test environment, the standard Hadoop shuffle-sort failed to complete the job, likely due to memory exhaustion caused by data skew. In contrast, the optimized algorithm successfully finished in 140 seconds. The sampling was sufficiently accurate that the recursive "Big File" processing step was rarely invoked, confirming the efficacy of simple random sampling for balancing large-scale workloads.

5. Conclusion and Future Work

This study demonstrates that a sampling-based, multi-round MapReduce approach significantly improves the efficiency and reliability of large-scale data sorting in Hadoop. By avoiding disk spills and ensuring uniform reducer load, the algorithm provides a scalable solution for massive datasets. Future research should focus on validating these results in full-scale distributed clusters and adapting these sampling strategies for modern, memory-centric frameworks like Apache Spark.

Summary updated

Abstract

When dealing with massive data sorting, we usually use Hadoop which is a framework that allows for the distributed processing of large data sets across clusters of computers using simple programming models. A common approach in implement of big data sorting is to use shuffle and sort phase in MapReduce based on Hadoop. However, if we use it directly, the efficiency could be very low and the load imbalance can be a big problem. In this paper we carry out an experimental study of an optimization and analysis of large scale data sorting algorithm based on hadoop. In order to reach optimization, we use more than 2 rounds MapReduce. In the first round, we use a MapReduce to take sample randomly. Then we use another MapReduce to order the data uniformly, according to the results of the first round. If the data is also too big, it will turn back to the first round and keep on. The experiments show that, it is better to use the optimized algorithm than shuffle of MapReduce to sort large scale data.
BibTeX
@misc{wang2015optimization,
  author = {Zhuo Wang and Longlong Tian and Dianjie Guo and Xiaoming Jiang},
  title = {{Optimization and analysis of large scale data sorting algorithm based on Hadoop}},
  year = {2015},
  eprint = {1506.00449},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1506.00449},
}
Figure