~ knotless Search/
↑↓ move↵ open⇧↵ all results

zat.dev/zds

atproto pds · mirror of https://tangled.org/zat.dev/zds

0
0
205 lines · 12.7 KB Raw History

personal PDS CPU throttling after a configuration restart

Investigated November 15, 2026. The affected service was zds.zzstoatzz.io, Fly app zds-zzstoatzz-io, machine 2863542fd20d28: one shared CPU and 1 GiB RAM. It ran ZDS v0.14.13, image git-c4c5cd392fc6, throughout. pds.zat.dev was a separate, unaffected deployment.

finding

Fly CPU quota exhaustion accompanied severe throttling and request timeouts. The configuration restart coincided with the machine's CPU burst balance falling from 401.61 seconds to 49.88 seconds. Continued traffic exhausted the remaining reserve within five minutes. This is a measured connection between the operational change and the incident, although the reason Fly reduced the balance at restart was not independently established.

The only configuration difference in the previous agent's before/after snapshots was ZDS_BLOB_UPLOAD_LIMIT: 100000000 to 200000000. The image, machine size and volume were unchanged. A second, explicit restart was attempted for recovery; it did not immediately end throttling.

resolution

The half-close spin reproduced below was fixed in v0.14.17 (November 18): the http.zig fork stops watching a socket while its handler runs (91063ca). v0.14.20 then closes a connection whose response write makes no progress for 60 seconds (3d07641). The repro recipes still pin the v0.14.13 image they measured, so they reproduce the original failure; point image at a current digest to check the fix.

timeline

All times below are UTC on November 15; subtract six hours for Chicago time. Balance values are fly_instance_cpu_balance / 100. Throttle percentages are rate(fly_instance_cpu_throttle[1m]): the underlying counter is in centiseconds. Metrics were queried from Fly's authenticated Prometheus API.

timeevidence
20:19–20:21Workload already elevated: 657, 311 and 284 completed sync requests per minute in ZDS telemetry.
20:21:59–20:22:01Configuration update stops and starts the same image; startup completes.
20:22:00Last pre-reset metric sample: 401.61 seconds of CPU burst balance.
20:22:15First post-reset sample: 49.88 seconds.
20:23:46Blob metadata records a successful 158,760,078-byte upload.
20:26:00Burst balance is down to 7.63 seconds.
20:26:54 onwardDatabase mutex contention appears across repo reads, sync, uploads, homepage and background work.
20:27–20:31Balance stays near zero. At 20:28 and 20:29, throttling is 93.34% and 91.43%. A one-post read times out after 12 seconds in the original investigation.
20:29:38–20:29:43Recovery restart, followed by continued throttling.
20:32–20:33Throttling subsides as demand falls; burst balance begins recovering.
20:41Last-minute throttling is zero; balance is only 10.52 seconds. Health responds in 74 ms; a recent one-post read took 74 ms.

interpretation and limits

Fly's CPU documentation describes a 6.25% baseline for one shared CPU, with accrued burst capacity. CPU steal can also indicate host contention, but the separate quota-throttle metric establishes quota exhaustion in this incident. It was not justified to infer a noisy neighbor from steal time alone.

The deployed source streams blob uploads through a 64 KiB buffer and hashes them before taking the database mutex to insert metadata: blobstore, store. Raising the limit does not itself allocate 200 MB. The larger upload, ongoing writes, and relay traffic could consume CPU; no CPU profile was captured that apportions their costs. Sync traffic remained substantial after restart: 521 requests in 20:22 and 555 in 20:25.

The contention messages describe ZDS's shared database mutex, not proof of SQLite corruption or an external SQLite lock. Severe scheduler delays can extend otherwise short critical sections. There was no evidence of memory exhaustion in the captured samples, but no database integrity scan was performed. Health and public record reads do not verify every client workflow or authenticated writes.

The 200 MB setting remained in place when service recovered. Rolling it back would require another restart and would not directly address CPU quota. These measurements do not establish a need for a performance CPU. The initial recommendation to upgrade was premature: it addressed the throttling mechanism without explaining the CPU cost. No production change was applied in this investigation. The small recovered reserve means that fast responses alone do not establish durable recovery.

follow-up: baseline and expensive requests

Five-minute average user-plus-system CPU was 0.11%, 0.13%, and 0.40% at 19:30, 19:35, and 19:40 UTC, respectively. At 20:25 it was 21.74%. The service was not continuously CPU-bound before the incident.

The 20:00 UTC hour's telemetry, read again around 20:45, contained 3,981 getBlocks requests and 355 getRepo requests. The request-duration histograms distinguish them: 3,796 getBlocks requests completed in under 8.192 ms, while 253 getRepo requests took between 524 ms and 4.194 seconds, and another 12 took longer. These are wall durations, including I/O and response transmission, not per-route CPU measurements. Hourly aggregates also cannot distinguish the pre-throttle and throttled periods.

Full exports traverse reachable blocks and query SQLite for each block. Incremental exports use an indexed query whose observed plan constrains the index by DID but not revision for the repo_rev IS NULL OR repo_rev > ? predicate. The database held 66,476 repo blocks totaling about 34.5 MB. These are profiling candidates, not proven causes. The retained telemetry does not distinguish full from incremental getRepo requests or identify their callers, so it cannot establish a retry loop or assign CPU costs. Investigating repeated exports and their implementation is warranted before prescribing larger hardware for this single-resident PDS.

minimal reproduction: one half-closed export

One export connection is sufficient to make the deployed HTTP event loop consume a full CPU and stall unrelated record reads. Run just bench export-half-close to provision the pinned image and synthetic resident, execute the controls below, capture results and delete the app. This recipe requires authenticated flyctl, jq and Zig. All export traffic stays on the disposable Fly machines.

The small client opens a loopback TCP connection with a 4 KiB receive buffer, requests com.atproto.sync.getRepo, stops reading, and calls shutdown(fd, SHUT_WR). It leaves the receive side open for 75 seconds, then closes the socket. The paired control performs the same request without shutdown for 20 seconds. No homepage, uploads, concurrent exports or proxy are needed for this trigger.

Measured on November 15, 2026, using the same 50,000-record fixture:

phase (UTC)ZDS process CPU and request behavior
21:19:10–21:19:30, unread export without half-closeInitial export construction consumes about one CPU-second, then 0–0.2% CPU in five-second samples.
21:19:40–21:20:55, one unread half-closed export99.6–99.8% CPU until the reserve runs out; four unrelated one-record reads hit the 12-second socket timeout.
After closing that socket at 21:20:55CPU returns to 0–0.2%; the outstanding read finishes and later reads succeed. No restart or size change is needed.

This run's health requests remained responsive (110 successes, maximum 151 ms), while record reads stalled. The broader four-export reproduction below also stalled health checks. A successful health check therefore misses the failure.

The mechanism is visible in the tested HTTP dependency httpz-0.0.0-PNVzrIybCQDv1ZMj9sPAWoQYDc7d_peS_kGV-LaBP69N: worker.zig:1523 registers level-triggered EPOLL.IN | EPOLL.RDHUP; worker.zig:662 skips events for active/handover HTTP connections without removing that registration. A half-close leaves RDHUP continuously ready. Meanwhile HTTPConn.writeAll switches to a blocking socket on WouldBlock (worker.zig:1998). An unread export can therefore retain its worker while the event loop repeatedly receives and ignores the readiness event.

A stack capture from the earlier four-export reproduction showed three handlers blocked in write → HTTPConn.writeAll → ConnWriter.drain → EphemeralCar.write, with the CPU-heavy thread in the epoll event loop. Other pool threads were idle. The single-connection control isolates the half-close as the CPU trigger; per-worker job queues also allow unrelated requests to wait behind a blocked export. No production caller or half-close was captured, so this is a verified software failure reproducing the incident symptoms, not proof of the exact historical request that triggered production.

Raw JSONL requests, process CPU samples, Fly metrics and thread stacks are saved locally under bench/results/export-repro-20261115/. The minimal socket client was cross-compiled with zig cc -target x86_64-linux-musl -O2 -Wall -Wextra -Werror and executed on the disposable target. Shell syntax, Python parsing, production-host refusal and git diff --check were also verified. No server implementation change or deployment was made.

Evidence also includes the original Find Chimera video handoff task's machine snapshots and logs under /Users/nate/Documents/Codex/2026-11-14/can-x20/work/zds-limit, plus bounded, read-only queries of telemetry_minutes, telemetry_hours, and blobs on the affected machine. No production mutation or code change was made in this investigation.

isolated reproduction

The deployed image was reproduced on a disposable Fly app in ord, with one shared CPU, 1 GiB RAM, one synthetic resident and 50,000 records. These produced 65,492 repo blocks and a 33,273,888-byte full CAR. The blob limit stayed at 100,000,000 bytes; there were no blob uploads or external relay subscriptions. The driver ran on a separate Fly machine. Export bodies stayed in Fly and were discarded after reading. No load was sent to production.

The executable recipe is just bench export-pressure. It creates and removes the disposable app, seeds records, runs controls and overlapping exports, and saves JSONL results under bench/results/. It pins the tested server image by digest. The Python driver refuses production hostnames. The recipe uses the driver, the fixture, and the lifecycle script.

experimentmeasured result
One full export every 10 seconds, eight minutes48 exports; 960 one-record reads and 480 health requests without failures. Read p95 31 ms, health p95 31 ms. CPU approximately 6.7%, no quota throttling.
Four concurrent export clients, each every 10 seconds, six minutes; homepage every 30 secondsBurst reserve depleted after approximately 3 minutes 20 seconds. One-record reads and health each timed out 11 times with a 12-second socket timeout. Homepage also timed out.
Resource measurements during failureTarget quota throttling reached approximately 93%; the four-CPU driver had zero quota throttling and an increasing reserve.
Database mutex evidenceowner=root held_ms=1515 waiter=background and owner=root held_ms=638 waiter=repo_list_records.
Sixty-second recovery control, starting approximately three minutes after exports stoppedFive record-read timeouts and four health timeouts. A completed health request took 10.29 seconds. No restart or machine resize occurred between pressure and recovery.

The failing run issued 144 export attempts; 62 failed, including timeouts and HTTP 429 after all four full-export slots remained occupied. Completed reads also took up to 4.26 seconds. Percentiles in the driver summaries describe completed HTTP responses, excluding socket exceptions; failure counts must be read alongside them. Each lane catches up to its scheduled cadence after delays.

This reproduces the request-stall and quota-exhaustion failure with one resident and the original upload limit. It does not establish that production received this exact traffic: its retained telemetry lacks caller and since parameters, and the failing synthetic rate exceeds the hourly production average. The single-export control disproved the earlier suggestion that six full exports per minute alone would necessarily reproduce the failure.