← Back to Pull requests

perf(install): cap tarball downloads at 128 and reuse their connections #2037

Closed
unknown closed this pull request without merging on Dec 03, 2026 23:26 UTC
View on GitHub
unknown unknown commented on Dec 03, 2026 21:57 UTC
Author

Problem

aube downloads tarballs over HTTP/1.1, so every tarball in flight holds its own TCP + TLS connection. Two settings made a cold install open far more connections than it needed:

  • The tarball limiter could grow to 256 downloads at once.

  • The tarball client's idle pool kept only 64 connections (maxsockets default). When a download finished while more than 64 connections were idle, hyper closed that connection. When demand rose again, aube opened new ones.
  • On a cold install of the vlt benchmarks' babylon fixture against registry.npmjs.org, aube opened about 400 TCP + TLS connections (172–669 across runs) and typically left 200–490 sockets in TIME_WAIT. While debugging aubepkg/aube#2031 we saw all of aube's pooled connections to the npm CDN go silent at once while new connections still worked. Opening fewer connections lowers aube's footprint on the CDN and on any middlebox in between.

    Change

  • Tarball downloads are capped at 128 at once (TARBALL_MAX_CONCURRENCY), down from 256. 128 is also the top of the default networkConcurrency seed (workers × 3, clamped to 16–128), so the limiter still starts where it did. Below the cap it adapts as before.

  • The tarball client's idle pool now holds 128 connections, so every connection the limiter can use is kept for reuse instead of being closed and reopened.

  • An explicit networkConcurrency above 128 still raises the tarball ceiling, as before. maxsockets, when set, still sizes both pools.

  • Metadata (packument) fetches are unchanged. They use HTTP/2, a 64-connection idle pool and their own limiter.

  • Corrected the maxsockets and networkConcurrency setting docs (the maxsockets default was documented as networkConcurrency x 3; it was 64) and a comment that still assumed tarballs were multiplexed over HTTP/2.
  • Results

    Real registry (babylon, cold, no lockfile)

    Each run is a fresh HOME, store and cache, using aube install --ignore-scripts against registry.npmjs.org from one Linux machine (Ryzen 9 7950X3D, 32 threads, home connection). Connections are connect() calls to port 443 recorded with strace -f --seccomp-bpf -e trace=connect. Only IPv4 is counted: this host has no IPv6 route, so its IPv6 attempts fail at once. "Peak open" is the most established :443 sockets the aube process held, sampled every 50 ms with ss.

    The final build against main, 6 interleaved runs each (no stalls in this window):

    | | new connections (median, range) | peak open | TIME_WAIT left | time (median) |
    |---|---|---|---|---|
    | main | 390 (281–420) | 72–113 | 200–370 | 8.3s |
    | this PR | 198 (122–202) | 55–134 | ≈0 | 8.6s |

    Peak open is now bounded by the cap, at about 131 including metadata connections. On main it varies with how the limiter grows. In other runs it reached 155–179.

    Choosing the cap: I tried pool and cap variants through temporary env knobs, built on aubepkg/aube#2031 (now merged; this branch is rebased on it). Without #2031 some runs hang for minutes on a stalled download, which swamps the timings. With it, a stall costs about 10s and shows up as a logged retry. This made it possible to count stalls. Here are 8 interleaved runs per variant in one network window, when the CDN was stalling often:

    | variant | new connections | peak open (max) | runs with stalls | stall retries | time (median) |
    |---|---|---|---|---|---|
    | main (cap 256, pool 64) | 420 | 155 | 8/8 | 66 | 21.8s |
    | pool 256 only | 197 | 259 | 6/8 | 28 | 19.1s |
    | cap 128, pool 128 | 198 | 133 | 6/8 | 16 | 16.0s |
    | cap 96, pool 96 | 173 | 108 | 8/8 | 20 | 15.3s |

    Real-registry timings vary a lot from run to run and from hour to hour, so treat the time column as a direction, not a measurement. A cap of 64 opened the fewest connections (138) but was clearly slower on the hermetic bench (below).

    Hermetic bench (gvs-cold, 500 Mbit/s, 50 ms)

    benchmarks/bench.sh with the mise run bench settings (BENCH_HERMETIC=1, BENCH_BANDWIDTH=500mbit, BENCH_LATENCY=50ms), aube only, gvs-cold scenario, 10 timed runs per bench, variants interleaved by round. Each row pools two rounds: the env-knob build and this PR's build, 60 samples each.

    | | median | mean | samples over 1.5s |
    |---|---|---|---|
    | main | 1.145s | 1.196s | 3 |
    | this PR | 1.160s | 1.221s | 6 |

    Without the samples over 1.5s, the means are 1.156s and 1.159s. The slow samples come in bursts within single benches, and the machine's load average was 18–22 from other work during the final round. Other variants: cap 96 had a median 2.7% above main (1.169s against 1.138s in the same round), and cap 64 was about 20% slower (fastest runs 1.29–1.31s against 1.04–1.09s).

    Limitations

  • All measurements are from one Linux machine on one home connection. CDN stall frequency changed a lot between windows, so the stall counts suggest fewer stalls with fewer connections but don't prove it.

  • Nothing here explains why pooled connections go silent. aubepkg/aube#2031 handles a stall once it happens; this PR only lowers how many connections aube opens and keeps open.
  • 🤖 Generated with Claude Code

    AI-assisted — Tool: Claude Code; model: anthropic/claude-opus-5-5; version: unavailable.

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    Performance
    Tarball downloads adapt from 4 up to 128 concurrent requests by default; configured network concurrency can raise the limit above 128.
    Metadata requests retain their separate adaptive concurrency range, starting at 4 and reaching at least 256.
    Default idle connection pools are 64 for metadata and 128 for tarballs. Higher network concurrency does not increase the tarball pool; a custom connection limit applies to both.
    Documentation
    Updated settings guidance to explain the separate connection-pool defaults and adaptive concurrency limits.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: jdx Review duration: 88m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #2037"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%
    Repository