リトライ予算、指数バックオフとジッター
Agent支援エンジニアリングチェック
前提条件
第76〜77日のリトライカウンタ機構。基礎的な確率。
学習目標
厳格な試行予算・指数バックオフ・フルジッターを備えたリトライポリシーを設計し、無制限で同期したリトライが部分障害を連鎖障害へ増幅する仕組みを説明する。
手順
1. プロジェクトのポリシーは意図的に最小限です: ok=false の観測ごとに retries が増加し、retries > max_retries=2 で実行が失敗します。遅延なしの即時再発行です。
2. 本番ポリシー(AWS Builder's Library): delay = random_between(0, min(cap, base * 2**attempt))。フルジッターはクライアント同士の相関を断ち、競合時の総仕事量を最小化します。
3. 連鎖障害モデル(Google SRE 第22章): リトライは依存先が劣化している時こそ負荷を倍加させます。リトライ予算+ジッター付きバックオフがその増幅に上限を与えます。
4. リトライするのは一過性障害のみ。永続障害(invalid_arguments, not_found)は訂正が必要です。アダプタが引数を直して再発行したからこそ、そのリトライは有効でした。
演習と予測記録
retry_with_backoff(fn, attempts=3, base=0.05, cap=0.5) を実装し、各試行間にフルジッター間隔でスリープし、枯渇後は再送出してください。2回失敗後に成功する不安定スタブと、予算を全消費する永続失敗の両方で駆動します。
sleep = random.uniform(0, min(cap, base * 2attempt))。決定的な 2attempt スリープは禁止です。
import random, time
def retry_with_backoff(fn, attempts=3, base=0.05, cap=0.5):
for i in range(attempts):
try:
return fn()
except Exception:
if i == attempts - 1:
raise
time.sleep(random.uniform(0, min(cap, base * 2**i)))
ジッターの数式を使って、プロジェクトのリトライ予算(2)と本番のジッター付きバックオフがともに仕事量を制限する理由と、それぞれが防ぐ障害(予算枯渇 vs 相関リトライストーム)を挙げられる。
公式ソースリソースと権利証跡
Exponential Backoff And Jitter
該当セクション・タイムスタンプ: Adding Backoff; Adding Jitter (Full Jitter, Equal Jitter, Decorrelated Jitter)
検証バージョンと日付: AWS Architecture Blog 2015 (Verified: 2026-10-30)
Detailed practitioner reference proving that full jitter (sleep = random_between(0, min(cap, base*2**attempt))) prevents synchronized retry storms and reduces total work during contention.
Retries, timeouts, and basic probability of correlated load.
The backoff exercise is implemented in pure Python with a local flaky stub; the derivation of jitter benefits is fully reproduced in lesson instructions.
比較対象候補リソースと選定評価 (2)
Product-scoped truncated exponential backoff recipe; Brooker's analysis explains why jitter matters, not just what to configure.
Library implementation reference; the AWS article supplies the comparative evidence (with/without jitter) that anchors the lesson.
Site Reliability Engineering, Chapter 22: Addressing Cascading Failures
該当セクション・タイムスタンプ: Preventing Server Overload: Retries
検証バージョンと日付: O'Reilly 2016 free online edition (Verified: 2026-10-30)
Primary analysis of how unbounded retries amplify partial outages into cascading failures, motivating hard retry budgets and deadlines in agent runtimes.
Retries, queueing, and load-shedding basics.
The retry-amplification scenario and budget arithmetic are fully reproduced in the lesson's worked example.
比較対象候補リソースと選定評価 (2)
Broader stability-pattern catalog (circuit breakers, bulkheads); the SRE chapter is free and directly quantifies retry amplification.
Strong companion article; the SRE chapter frames the failure mode (cascading overload) that the retry budget defends against.