Skip to content

s3 improvements: client cache and batch transfers - #112

Open
karank2512 wants to merge 4 commits into
thaw-ai:mainfrom
karank2512:s3-improvements
Open

karank2512 wants to merge 4 commits into
thaw-ai:mainfrom
karank2512:s3-improvements

Conversation

@karank2512

Copy link
Copy Markdown
Member

Continues #93 (same change, moved to a feature branch so the fork's main stays clean). Addresses the review there.

What it does

  • Caches the boto3 S3 client per process, keyed by (pid, pool_size).
  • Adds resolve_snapshots / upload_snapshots: bounded cross-file concurrency, input order preserved, duplicate URIs deduplicated before fan-out.
  • Benchmark benchmarks/bench_s3_batch.py and receipt site/receipts/2026-06-24_s3_batch.json, tests in tests/test_cloud.py.

Review feedback addressed

  • README and cloud.py no longer say N keys "give" ~N x 135 MB/s. They say throughput should scale toward it, projected from the single-key ceiling and not yet measured end to end.
  • The local path is removed from the receipt, and the bench no longer writes json_out into new receipts.
  • Also removed claims nothing measures: warm connections / one fewer handshake, "hundreds of ms cold", per-prefix throttling, and the connection pool described as a hard bound on in-flight requests. The receipt measures client construction only (moto opens no sockets); the batch speedups there come from a synthetic sleep, so they show latency hiding, not bandwidth.
  • Merged current main; the README S3 section is reconciled with the shortened version there.

Checks

python tools/thaw_lint.py clean; ruff (F,E9) clean on changed files; pytest tests/ 293 passed with CI's dependencies.

Known, not fixed here

  • Two processes writing the same cache file use a fixed .part name and there is no size check, so a corrupt snapshot is possible (pre-existing, more likely with batching).
  • After a first error, queued downloads still run.
  • The shared pool (36) is smaller than files x per-file concurrency (8 x 32); sizing it fits the shard-at-freeze work.
  • docs/ARCHITECTURE.md cites legacy-site/receipts/2026-04-23_ec2_s3_download.json for the 135 MB/s figure, and that file is not in the tree at present.

karank2512 and others added 4 commits June 24, 2026 11:55
…h transfers

The S3 layer (thaw_common.cloud) rebuilt a fresh boto3 client on every
download and every upload, and had no API for moving many objects at once.
Building a client is ~3 ms warm / ~hundreds of ms cold (credential chain +
S3 service-model load) and — the part that bites on a real network — starts
with an empty connection pool, so each operation paid a fresh TCP+TLS
handshake instead of reusing a warm keep-alive connection. And per
docs/ARCHITECTURE.md a single S3 key is server-throttled to ~135 MB/s flat
regardless of ranged concurrency; the documented unlock is fanning out
across N keys (N×135 MB/s) — which there was no primitive for.

Changes (all additive; existing public APIs and behavior unchanged):

* Shared, thread-safe, process-cached boto3 client keyed by (pid, pool_size).
  - pid key: botocore clients are not fork-safe; vLLM forks/spawns TP
    workers, so re-keying on os.getpid() rebuilds transparently per process.
  - pool_size key: callers needing a bigger HTTP pool get a distinct client.
  - Lazy, double-checked build under a lock (boto3.client() construction is
    itself not thread-safe; the instance is). reset_s3_client_cache() hook
    for test isolation / operator recovery.
* resolve_snapshots(uris, ...) / upload_snapshots(pairs, ...): bounded
  cross-file fan-out (THAW_S3_FILE_CONCURRENCY, default 8) reusing the shared
  client. Order-preserving, first-error-surfacing, atomic .part rename per
  file preserved. resolve_snapshots de-duplicates identical URIs so two
  positions can't race the same cache file's rename.
* Honest docstring: replace the unreceipted ">800 MB/s" claim with the
  receipted ~135 MB/s single-key wall + the many-key fan-out lever.

Tests: +20 unit tests (client reuse, fork rebuild, reset, batch ordering,
concurrency, bounds, error propagation, dedup) + 3 moto end-to-end batch
tests. Full non-GPU suite: 273 passed. Benchmark (benchmarks/bench_s3_batch.py,
receipt in site/receipts/): client construction 2.83 ms->0.025 ms per op;
256 objects @ 40 ms -> 31.6x with 32-way file concurrency.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
perf(cloud): cache the boto3 S3 client + add bounded-concurrency batc…
… MB/s claim, scrub local path from receipt, drop unmeasured connection-warmth and hard-bound claims)
@vercel

vercel Bot commented Oct 20, 2026

Copy link
Copy Markdown

@karank2512 is attempting to deploy a commit to the Nils 's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Oct 20, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 271206a5-8794-4440-96b5-2c59d353648d
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@karank2512 karank2512 mentioned this pull request Oct 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant