main
1// The batched rate limiter's numbers (docs/rate-limit.md). Every one is named here and nowhere else.
3/** How long an isolate's open batch collects hits before one flush RPC. Ivar's design: "only write every 200ms". */
4export const LINGER_MS = 200;
5/**
6 * One flush attempt races this timer: about 2x the apply RPC's p99.9 (722 ms on ae21dee2, run lat2, 5649 flushes). At
7 * 1000 ms, colos far from the counter (MRS: 436-984 ms) timed out and replayed healthy attempts.
8 */
9export const ATTEMPT_TIMEOUT_MS = 1_500;
10/** A batch is retried with the same id until acked or this long after its first attempt, then dropped. */
11export const FLUSH_DEADLINE_MS = 5_000;
12/** First retry backoff; doubles per attempt, capped by what is left of the deadline. */
13export const RETRY_BACKOFF_MS = 50;
14/** A batch with this many distinct keys is flushed at once instead of lingering. */
15export const MAX_BATCH_KEYS = 2_048;
16/** Batches flushing (lingering or retrying) at once per isolate. A batch beyond this is dropped and recorded. */
17export const MAX_INFLIGHT = 64;
18/**
19 * Distinct client keys held per isolate across the open batch and every batch still flushing. Without it the bound is
20 * MAX_INFLIGHT × MAX_BATCH_KEYS = 131,072 Map entries while the counter is slow (5 s of retries). A hit for a NEW key
21 * past this is dropped and recorded (`rate.batch.dropped=budget`); a key already in the open batch still counts.
22 */
23export const MAX_KEYS_HELD = 16_384;
25export const SLOT_MS = 10_000;
26export const WINDOW_MS = 60_000;
27/** Idempotency keys are kept this long: 120× the client deadline. */
28export const DEDUPE_RETENTION_MS = 600_000;
29export const PRUNE_EVERY_MS = 5_000;
30/**
31 * One prune deletes at most this many rows per table (rate_hits, rate_batches, rate_blocked). On 78ddd5c3 one apply
32 * wrote 12,892 rows: an unbounded retention prune after an idle spell. A full batch leaves a backlog, and the next apply
33 * prunes again instead of waiting PRUNE_EVERY_MS, so the backlog drains a bounded slice per apply.
34 */
35export const PRUNE_BATCH_ROWS = 128;
36/** The blocked document holds at most this many entries (newest `until` first). */
37export const MAX_DOC_ENTRIES = 4_096;
38/**
39 * The reader's bound on the document (defence against a bad or oversized one): bytes read and entries indexed. A full
40 * document is MAX_DOC_ENTRIES × ~52 bytes ≈ 213 KB; a bigger body is not read, and the isolate keeps its last document.
41 */
42export const MAX_DOC_BYTES = 512 * 1024;
44/** The read side's Cache-Control: fresh for 1 s, then served stale for up to 30 s while one request revalidates. */
45export const DOC_MAX_AGE_S = 1;
46export const DOC_SWR_S = 30;
47export const DOC_URL = 'https://rate.internal/blocked/v1';
48export const DOC_PATH = '/blocked/v1';
49export const DOC_TAG = 'rate-blocked';
50/**
51 * The request waits this long for the cached document. Warm HIT and stale (SWR) reads on lat2: p99 12 ms, max 46 ms
52 * (5,669); a MISS is a synchronous DO read (403-481 ms). Past this the request uses the isolate's last document.
53 */
54export const READ_BUDGET_MS = 25;
55/** After a failed read, the isolate's last good document is used for this long; then the request fails open. */
56export const MEMO_FALLBACK_MS = 300_000;
57/**
58 * Memo mode (no fetch on the request path): a request whose isolate memo is at least this old still decides from it,
59 * and starts one single-flight refresh of the cached document in ctx.waitUntil. Adds ≤ this much (plus the refresh's
60 * own read and the isolate's gap between requests) to the enforcement lag.
61 */
62export const MEMO_REFRESH_MS = 500;
63/** A refresh still unsettled after this long is abandoned (a hung loopback must not pin the single flight forever). */
64export const MEMO_REFRESH_ABANDON_MS = 10_000;
66/** The one RateCounter object. */
67export const COUNTER_NAME = 'global-v1';
68/** Hex characters of the client hash sent, stored and cached (64 bits). */
69export const KEY_HEX = 16;
71export const BUCKET_PAGE = 0;
72export const BUCKET_PACK = 1;
73export type BucketId = typeof BUCKET_PAGE | typeof BUCKET_PACK;
Diagnostics4 git calls · 286 ms
CallStatusSizeTime0286 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200145 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=145 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=145 git.pkt.payload.max=76 git.ls_refs.count=2 git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020040 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=41349 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=526b305930b8ef382f2d7a1f9c0238730a585921 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=6 git.pkt.data=4 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=41349 git.pkt.payload.max=41254 git.sideband.band1.bytes=41253 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=61 git.pack.bytes=41253 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c git.pack.full=61Open pack map
fetch2001.9 KiB280 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=280 git.response.bytes=1950 git.response.cache=MISS git.response.duration_ms=280 git.fetch.wants=2e20f45e6f6d42fc5b9f079dffe5abcd260489f5 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1950 git.pkt.payload.max=1929 git.sideband.band1.bytes=1928 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply-web.git
- Ref
- refs/heads/main
- Commit
- 526b305930b8ef382f2d7a1f9c0238730a585921
- cf-ray
- a5e33ac9e933f162
- Request
- 0d72ec7a…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format