Skip to content

Consistent-hash ring with weighted virtual nodes and zone-aware replica placement

Exact prompt

# Consistent-hash ring with weights and zone-aware replicas `ring.py` places cache keys on storage nodes. The draft uses the wrong hash, ignores weights and zones, and is slow. Rewrite it (Python 3 stdlib only) so that `Ring(nodes, vnodes=64)`, `Ring.owner(key)`, `Ring.replicas(key, n)` and `moves(old_ring, new_ring, keys)` behave exactly as below. ## Hashing 1. `H(s)` = the first 8 bytes of SHA-256 of the UTF-8 encoding of `s`, read as a big-endian unsigned integer. 2. `nodes` maps a node name to a dict with optional `weight` (number, default 1) and `zone` (string, default = the node's own name). `vnodes` must be an int >= 1, else `ValueError`; a negative weight is a `ValueError`. 3. A node gets `k = floor(vnodes * weight + 0.5)` virtual points, but at least 1 if weight > 0. A node with weight 0 gets none and does not exist for the ring. Point i (0 <= i < k) of node `name` is at position `H(f"{name}#{i}")`. 4. The ring is all points sorted by (position, node name, i). ## Lookups 5. `owner(key)`: the node of the first point whose position is **>= H(key)**; if none, wrap around to the first point. An empty ring raises `LookupError`. 6. `replicas(key, n)`: start at the point `owner` would use and walk the ring clockwise (wrapping) over every point once. Look at each **distinct** node the first time it is met: if its zone is not yet used by a chosen node, choose it; otherwise remember it as skipped. Stop as soon as n nodes are chosen. If the walk ends with fewer than n chosen, append skipped nodes in the order they were first met until there are n (or none are left). `n < 1` gives `[]`. The owner is always first. 7. `moves(old, new, keys)`: for every key in `keys` whose owner differs, count the pair `(old_owner, new_owner)`; return a dict of these counts with keys in sorted order. 8. **Speed:** with 60 nodes at vnodes=128, building the ring, 60,000 `owner` calls and 10,000 `replicas(key, 3)` calls must take under 10 seconds in total on our shared test box. ## Scoring Hidden check groups (partial credit = fraction passed; all must pass): `hash_and_points` (1, 3, 4: owners for 2,000 keys on small rings), `weights_rounding` (3: e.g. weight 0.5/0.0078/0, exact owners), `wraparound_and_errors` (2, 5), `replicas_zones` (6), `replicas_fallback` (6: fewer zones than n, n larger than node count), `moves_counts` (7: adding, removing, reweighting a node), `speed` (8).

Exact owners for thousands of keys require the stated hash, point naming, rounding of weights (minimum one point) and >= with wraparound; the replica walk with zone skipping and ordered fallback, plus a speed check that rules out linear scans. Original benchmark task written for usecaserank.com (not based on a specific public post). Headless, offline run on a reproducible fixture. Each run's notes say how its cost was measured (estimates are marked).

Success criteria: 1. hash_and_points 2. weights_rounding 3. wraparound_and_errors 4. replicas_zones 5. replicas_fallback 6. moves_counts 7. speed (< 10 s)

Best model for this task so far: Claude Haiku 5.5 (effort default (no --effort flag) · thinking on) (success, $0.0081, 52m).

Run this on another model

All runs (4)

100% pass rate across 4 eligible runs: 4 pass, 0 partial, 0 fail. Partial and failed runs are listed below with everything else.ⓘ

Runs for this use case
ModelCostTimeStep-insⓘAutonomyOutcomeTrustⓘDateCompare
OGPT-6.1 Soldefault · thinking on$0.071m0Fully autonomouspassTrust 80%2026-10-22
AClaude Haiku 5.5default · thinking on$0.008152m0Fully autonomouspassTrust 75%2026-10-20
AClaude Opus 5.5default · thinking on$0.1734s0Fully autonomouspassTrust 80%2026-10-20
AClaude Sonnet 5.5default · thinking on$0.0719s0Fully autonomouspassTrust 80%2026-10-20

Embed this result

A live badge for this use case. It links back here and updates as new runs are published.

UseCaseRank badge for Consistent-hash ring with weighted virtual nodes and zone-aware replica placement

Get new runs and ranking changes weekly

Which models got better or cheaper on real tasks like this one.