Abstract
Estimating the Number of Distinct Values (NDV) is critical for database optimization and network security. Traditional methods face a trade-off between high I/O costs (scanning-based) and high communication overhead (sampling-based) in distributed environments. This paper introduces a novel distributed framework that leverages a mathematical relationship between unique values and set unions to calculate the "frequency of frequency" ($f_1$) using mergeable sketches. This approach reduces communication costs by orders of magnitude and provides a 10x speedup over standard MapReduce implementations while maintaining high estimation accuracy.
Introduction
In large-scale distributed systems, estimating cardinality (NDV) is a fundamental challenge. Scanning-based methods like HyperLogLog (HLL) are accurate but suffer from massive I/O as data grows. Conversely, sampling-based methods are fast on single machines but fail in distributed settings because the master node requires the global count of items that appear exactly once ($f_1$). Traditionally, obtaining $f_1$ requires every worker to send its entire frequency dictionary, creating a "communication wall" that limits scalability.
Methodology: Sketch-based Distributed Sampling
The proposed framework overcomes the communication bottleneck by expressing $f_1$ using $\ell_0$ norms (distinct counts). For two samples $X$ and $Y$, the global $f_1$ is derived as: $$f_1(X + Y) = \|X_{=1} + Y\|_0 - \|X\|_0 + \|X + Y_{=1}\|_0 - \|Y\|_0$$
Since $\| \cdot \|_0$ can be estimated efficiently using mergeable sketches like HyperLogLog, workers only need to transmit small sketches (kilobytes) instead of full dictionaries (gigabytes).
Computation Framework
- Local Sampling: Each machine samples its local data partition.
- Pre-Merged Sketches: A binary tree structure is used to build intermediate merged sketches, avoiding $O(k^2)$ complexity.
- Global Estimation: The master node solves for $f_1$ using the received sketches and applies classic statistical estimators such as GEE, Shlosser, or Chao Lee.
Experimental Evaluation
The framework was evaluated using synthetic Poisson and Zipfian datasets (up to $10^{12}$ elements) and the Star Schema Benchmark (SSB) with 900 million rows.
Key Results
- Communication Savings: On the SSB
revenuedataset, communication costs were reduced from over 1200 MB to just a few megabytes. - Computational Speedup: Spark-based experiments demonstrated that the method is nearly 10x faster than standard MapReduce implementations.
- Scalability: The I/O cost remains flat as data scales, unlike traditional methods that see linear increases in shuffle I/O.
- Accuracy: By using HLL with a parameter $b \ge 12$, the framework achieves high precision in $f_1$ estimation, leading to NDV results nearly identical to full-data access methods.
Conclusion
By repurposing sketches to estimate specific frequency counts, this framework enables mathematically sound sampling estimators to scale efficiently in distributed environments. While the method assumes $f_1$ is not infinitesimally small, this holds for most real-world distributions. Future work will explore extending this "sketch-of-sample" approach to other statistical properties like entropy.
Summary updated