AnchorHash: A Scalable Consistent Hash

Gal Mendelson, Shay Vargaftik, Katherine Barabash, Dean H. Lorenz, Isaac Keslassy, Ariel Orda

TL;DR

AnchorHash is a novel consistent hashing algorithm that achieves both full consistency (minimal disruption and balance) and high scalability in terms of lookup rate and memory footprint. It overcomes limitations of existing methods by leveraging state information, enabling efficient handling of millions of resources with minimal overhead.

What Problem Does This Paper Address?

Consistent hashing (CH) is a fundamental technique used in many networking applications, like load balancing and distributed hash tables, to map keys (e.g., network flows) to a set of resources (e.g., servers). The primary goals of CH are minimal disruption (few keys change their mapping when resources are added or removed) and balance (keys are evenly spread across resources). However, existing CH solutions often struggle to achieve both goals simultaneously, especially at scale. Many sacrifice full consistency for better scalability, leading to arbitrary changes in key mappings or requiring significant memory footprints and slow update times. This paper addresses the need for a consistent hashing algorithm that is both highly scalable and guarantees full consistency under dynamic changes to the set of resources.

Methods

The core innovation of AnchorHash lies in its approach to maintaining consistency while achieving scalability. It uses an indirection mechanism: keys are first mapped to buckets, and then buckets are mapped to resources. This allows for more flexibility in managing resource changes.

Key techniques include:

  • Stateful History: Unlike stateless CH algorithms, AnchorHash maintains a history of removed buckets. This history is crucial for ensuring minimal disruption when resources are added or removed.
  • LIFO Queue for Removed Buckets: Removed buckets are stored in a Last-In, First-Out (LIFO) queue. This allows for efficient restoration of previous states when a resource is added back.
  • Iterative Rehashing: When a key lookup encounters a removed bucket, AnchorHash iteratively rehashes the key into successively smaller sets of buckets until a working bucket is found. The theoretical analysis shows that the number of rehashes is bounded and depends on the fraction of removed resources, not their absolute number.
  • Optimized Implementations: The paper presents three implementations of AnchorHash, progressively reducing memory footprint:
  • Naive: Stores the full set of buckets for each removed resource.
  • Reduced-Memory: Stores only the "non-fixed points" (differences) between bucket sets.
  • Minimal-Memory: Uses a single array to represent the "Anchor" and successors, achieving a constant memory footprint per resource. This implementation is highly efficient but slightly increases the expected number of memory accesses per lookup.

Datasets

Not discussed in the paper. The evaluation uses synthetic workloads and a CAIDA trace for network traffic.

Key Insights and Ideas

  • State is Key to Consistency at Scale: The paper demonstrates that by intelligently using state (the history of removed buckets), it's possible to achieve full consistency even with millions of resources, a feat difficult for stateless methods.
  • Indirection as a Scalability Enabler: The two-step mapping (key-to-bucket, then bucket-to-resource) provides a flexible layer for managing dynamic resource changes without directly impacting key mappings.
  • Bounded Rehashing: The theoretical analysis showing that the number of rehashes per lookup is bounded by a function of the fraction of removed resources, not the total number, is a critical insight for achieving high lookup rates at scale.
  • Memory Footprint Optimization: The progression from naive to minimal-memory implementations highlights a clever trade-off between memory usage and lookup complexity, ultimately achieving a very low memory footprint per resource.

Key Results

  • Scalability: AnchorHash scales to 100 million resources on a single core, achieving lookup rates of over 15 million keys per second.
  • Consistency: AnchorHash guarantees minimal disruption and balance, outperforming MaglevHash which sacrifices consistency.
  • Memory Footprint: The minimal-memory implementation requires only 16 Bytes per resource, significantly less than MaglevHash (which needs at least 400 MB for 10^6 resources to achieve reasonable balance).
  • Update Time: Resource additions/removals take nanoseconds, independent of system size, far superior to Ring and MaglevHash which scale poorly with system size.
  • Lookup Rate: AnchorHash maintains a high lookup rate even with a large number of resources and high removal rates (e.g., 50% or 90% removed). For instance, with 1 million buckets, it achieves tens of millions of keys per second.
  • Hash Operations: The number of hash operations per lookup is very low, with over 90% of keys requiring 6 or fewer operations in typical scenarios.

Limitations and Future Work

  • Distributed Consistency: In a distributed environment where multiple dispatchers run AnchorHash in parallel, consistency relies on agreement on the removal order of buckets. The authors suggest studying extensions to maintain full consistency even when dispatchers don't necessarily agree on this order.
  • Theoretical vs. Practical Trade-offs: While the minimal-memory implementation is highly efficient, it slightly increases the upper bound on the expected number of memory accesses per lookup compared to the naive or reduced-memory versions.

Summary updated

BibTeX
@inproceedings{mendelson2020anchorhash,
  author = {Gal Mendelson and Shay Vargaftik and Katherine Barabash and Dean H. Lorenz and Isaac Keslassy and Ariel Orda},
  title = {{AnchorHash: A Scalable Consistent Hash}},
  booktitle = {IEEE/ACM},
  year = {2020},
  doi = {10.1109/tnet.2020.3039547},
}
Figure