本文へスキップ
製品デスクトップツールTASTECAD図面の確認TASTEFILESファイル管理TASTEFTPファイル転送TASTESSHリモートワークスペースTASTEZIP圧縮と展開TASTEWINMファイル管理開発ツールTASTECODERust 統合開発環境TASTESTUDIO統合開発・テスト環境TASTEETLデータ統合(ETL)サーバーTASTEREMOTEリモートデスクトップサーバーTASTEGEO空間情報サーバーTASTEMAILメールワークスペース投資TASTESTOCK株式自動売買デスクトップアプリはじめるダウンロードドキュメント購入すべての製品
マーケットプレイス
ニュース
技術ニュース今日の開発ニュース開発ドキュメントプログラミング言語RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWebフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngularサーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Expressアプリ・デスクトップ フレームワークTauriFlutterReact NativeElectronアルゴリズムアルゴリズムの基礎主要アルゴリズム発展アルゴリズム実務のアルゴリズム
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケースコミュニティガイド
協業技術移転ウェブサイト構築デスクトップアプリ構築リリース・決済パイプライン販売パートナーお問い合わせ
サービスリモートデスクトップインストールパッケージのカスタマイズ
TASTEDEV
製品

デスクトップツール

TASTECAD複雑な図面を、軽やかにひらくTASTEFILES必要なファイルだけを、最速でTASTEFTPファイルが行き交う、いちばん端正な道TASTESSHサーバーとあなたを、より確かにつなぐTASTEZIPより速くまとめ、より安全にひらくTASTEWINM2つの画面で整理する、キーボード中心のファイルマネージャー

開発ツール

TASTECODERust アプリの編集・ビルド・デバッグ・テストまでひとつのウィンドウでTASTESTUDIO編集からリモートテスト、承認した AI 修正までTASTEETL値を見ながら、データを運ぶ

サーバー

TASTEREMOTE自社サーバーで運用するリモートデスクトップTASTEGEOGeoServer 互換の空間情報サーバーを Rust で作り直しますTASTEMAILメールの主導権を、もう一度自分の手に

投資

TASTESTOCKいつ・何を。自分で決めたルールどおりに動く株式自動売買

はじめる

ダウンロード全製品の最新版ドキュメント各製品の使い方購入サブスクリプション・永久ライセンスすべての製品全製品を一覧で
すべての製品
マーケットプレイスニュース
技術

ニュース

今日の開発ニュース言語・フレームワーク・GitHub・AI の公式発表開発ドキュメント言語・フレームワーク・アルゴリズムのガイド

プログラミング言語

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

フレームワーク

Webフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngular
サーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
アプリ・デスクトップ フレームワークTauriFlutterReact NativeElectron

アルゴリズム

アルゴリズムの基礎計算量解析 · ソート · 探索 · 基本データ構造 · 木構造とヒープ主要アルゴリズムグラフ探索 · 最短経路と最小全域木 · 動的計画法 · 貪欲法 · 分割統治法 · バックトラッキング発展アルゴリズム文字列アルゴリズム · 数学と整数論 · ビット演算 · セグメント木 · Union-Find実務のアルゴリズムコーディング面接対策 · LRUキャッシュ · レート制限 · コンシステントハッシュ法
開発ドキュメントをすべて見る
コミュニティ
プロジェクトビルダーと作品を探す開発ログ決定と試行錯誤プロンプト再利用できる指示AIツールの問題Claude・Codex・Gemini の問題と回避策ショーケース完成した成果コミュニティガイドオープンにつくる方法
協業
技術移転Rust・egui でネイティブアプリを作るウェブサイト構築10言語、アカウント、ドキュメントとダウンロードデスクトップアプリ構築Rust・egui、WebView なしリリース・決済パイプライン署名・MSI・deb・rpm・AppImage・ハッシュ販売パートナー紹介して決済額の30%お問い合わせ構築・提携・投資のご相談
サービス
リモートデスクトップブラウザから自分のパソコンへインストールパッケージのカスタマイズ必要な機能だけ、設定は事前に
購入
JA
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
ログイン
ログイン
TASTEDEV

小さなツールから、より良い開発へ。

support@tastedev.netTASTEDEVを支援
製品製品ラインナップ購入ドキュメントダウンロードマーケットプレイスサポート
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケース
ポリシー会社概要プライバシーポリシー利用規約サブスクリプション規約返金ポリシーコミュニティガイドライン
アカウントログイン新規登録
訪問者
今日
昨日
累計閲覧
商号
GXSOFT
代表者
CHOI YOUNG GU
事業者登録番号
853-44-00368
所在地
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
メール
whitecalvin@tastedev.net
個人情報保護責任者
CHOI YOUNG GU

© 2026 TASTEDEV製品情報は検証済みの開発ソースに基づいています。リリース・改善中

コンシステントハッシュ法 ドキュメント
コンシステントハッシュ法
Consistent hashing conceptsHow it worksImplementationComplexityPractice problemsReal-world use
ディスカッション

コンシステントハッシュ法 ガイド · 5/6

Practice problems

この章は現在、英語でのみ提供しています。

Every problem below reuses hash64 and HashRing from the implementation chapter (sorted points plus the owner map from position to node). Try each one yourself before reading the solution.

Problem 1. Each node's share of the ring

Given a ring, compute what fraction of the full 2^64 space each node owns. Vary the vnode count over 1, 10, 100 and 1000 and see how far the largest and smallest shares drift from the average.

Approach: each point owns everything after the previous point up to itself. Walk the sorted points and add (p - previous) mod 2^64 to the owner's total. The predecessor of index 0 is the last point, and Python's pts[-1] handles that wrap for free. A ring with a single point gives a difference of 0, so treat it separately.

RING_SIZE = 1 << 64

def ownership(ring: HashRing) -> dict[str, float]:
    pts = ring.points
    if len(pts) == 1:
        return {ring.owner[pts[0]]: 1.0}
    share: dict[str, int] = {}
    for i, p in enumerate(pts):
        arc = (p - pts[i - 1]) % RING_SIZE   # i == 0 wraps to the last point
        node = ring.owner[p]
        share[node] = share.get(node, 0) + arc
    return {node: s / RING_SIZE for node, s in share.items()}

for v in (1, 10, 100, 1000):
    r = HashRing(vnodes=v)
    for n in range(10):
        r.add(f"node-{n}")
    s = ownership(r)
    print(v, round(max(s.values()) * 10, 2), round(min(s.values()) * 10, 2))

Multiplying by the node count normalizes the average to 1. As vnodes increase, both extremes approach 1.

Problem 2. Replicas in distinct zones

Each node belongs to an availability zone. Pick R replicas for a key that are distinct physical nodes in distinct zones. If not enough qualify, return as many as you found.

Approach: walk clockwise from the key one point at a time, skipping nodes already chosen and zones already used. Stop after one full lap.

import bisect

def zone_replicas(ring: HashRing, zone_of: dict[str, str], key: str, n: int) -> list[str]:
    pts = ring.points
    start = bisect.bisect_left(pts, hash64(key))
    chosen: list[str] = []
    zones: set[str] = set()
    for step in range(len(pts)):
        node = ring.owner[pts[(start + step) % len(pts)]]
        if node in chosen or zone_of[node] in zones:
            continue
        chosen.append(node)
        zones.add(zone_of[node])
        if len(chosen) == n:
            break
    return chosen

zone_of = {"a1": "az-1", "a2": "az-1", "b1": "az-2", "b2": "az-2", "c1": "az-3"}
ring = HashRing(vnodes=50)
for node in zone_of:
    ring.add(node)
print(zone_replicas(ring, zone_of, "order:1001", 3))  # one node from each zone

Problem 3. A migration plan for a new node

Before adding a node, list which hash ranges it takes over and from which existing node. Return tuples where each range excludes start and includes end.

この章について質問がありますか?
前の章Complexity次の章Real-world use
(start, end, previous_owner)

Approach: in the ring after the addition, each point p of the new node takes over the range from its predecessor up to p. The previous owner is whoever owned p in the ring before the addition. The rule still holds when several new points sit next to each other.

def migration_plan(ring: HashRing, new_node: str) -> list[tuple[int, int, str]]:
    old_points = list(ring.points)
    old_owner = dict(ring.owner)
    ring.add(new_node)
    pts = ring.points
    plan = []
    for i, p in enumerate(pts):
        if ring.owner[p] != new_node:
            continue
        j = bisect.bisect_left(old_points, p) % len(old_points)
        plan.append((pts[i - 1], p, old_owner[old_points[j]]))
    return plan

def in_range(h: int, start: int, end: int) -> bool:
    if start < end:
        return start < h <= end
    return h > start or h <= end   # the range wraps past 0

To verify, look up a few thousand keys before and after the change and check that every key that changed owner falls inside a planned range with the matching previous owner, and that no other key moved.

Problem 4. Weighted rendezvous hashing

Nodes have capacity weights. Build a rendezvous hash that assigns keys in proportion to weight and moves only the removed node's keys when one node leaves.

Approach: for each node, turn a hash of node and key into a uniform number u between 0 and 1, and pick the node with the largest score -w / ln(u). That score wins with probability proportional to w. Using the top 53 bits plus 0.5 keeps u strictly between 0 and 1.

import math
from collections import Counter

def hrw(key: str, weights: dict[str, float]) -> str:
    best, best_score = "", -math.inf
    for node, w in weights.items():
        u = ((hash64(f"{node}:{key}") >> 11) + 0.5) / (1 << 53)   # 0 < u < 1
        score = -w / math.log(u)
        if score > best_score:
            best, best_score = node, score
    return best

weights = {"small": 1.0, "medium": 2.0, "large": 4.0}
keys = [f"obj:{i}" for i in range(70_000)]
first = {k: hrw(k, weights) for k in keys}
print(Counter(first.values()))   # roughly 10000 / 20000 / 40000
del weights["medium"]
moved = [k for k in keys if hrw(k, weights) != first[k]]
print(all(first[k] == "medium" for k in moved))  # True

Summary

  • A node's share is the sum of the gaps in front of its points.
  • Replica selection walks clockwise and skips points that break the rules.
  • A migration plan pairs each new point's preceding range with its old owner.
  • The -w / ln(u) score gives weighted rendezvous hashing with minimal movement.

コメント 0件

人気のコメント順新しい順

ログイン · ログインするとコメントできます。