Skip to content

Remote cache: measured across a network; compressed and pipelined (#18) - #78

Open
ambroise-leclerc wants to merge 11 commits into
17-tlsfrom
18-uploads
Open

ambroise-leclerc wants to merge 11 commits into
17-tlsfrom
18-uploads

Conversation

@ambroise-leclerc

@ambroise-leclerc ambroise-leclerc commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

Measures the remote cache on MduX against bazel-remote, then acts on what the measurements show. Second part of epic #38, stacked on #77.

Measurements (full table and method in docs/measurements.md, "Remote cache across a network"): MduX 57a7d1d, GCC 16.1, 336 units, 24 cores, bazel-remote on the same machine, over https. The network is modelled by tools/latency_proxy.py (new): a delay each way, the TCP handshake included, and a shared bandwidth. Median of 3 rounds.

Link Clean build, empty caches: before → after Empty local cache, populated remote: before → after
same machine 55.2 s → 54.0 s 6.6 s → 6.5 s
20 ms round trip, 100 Mbit/s 56.1 s → 55.0 s 11.7 s → 8.2 s
60 ms round trip, 50 Mbit/s 61.6 s → 56.2 s 19.9 s → 12.3 s

(About 53–54 s without any cache, 6 s from a populated local cache.)

Decisions, the options #18 lists:

  • Compression: done. Bandwidth is what limits a build served by the remote cache: MduX's results weigh 71 MB, 13.5 MB with zstd. Content blobs are now always asked for with Accept-Encoding: zstd (bazel-remote stores them compressed anyway), and CPPMCACHE_REMOTE_COMPRESSION=zstd compresses uploads too. Uploads stay uncompressed by default because a server that ignores Content-Encoding would store the compressed bytes, which clients then refuse as not matching their digest. zstd v1.5.7 comes through CPM, linked statically.
  • Batching: done, as HTTP/1.1 pipelining. A miss made nine requests one after the other, and now publishes in four round trips (the manifest entry is sent last, once what it points to is stored). cppmcache's own upload time fell by 30–40 %, but a parallel build already hid most of it.
  • Skipping the HEAD of small blobs: not done. The HEADs now share a round trip with the GET of the manifest, so skipping them would save nothing.
  • Background uploads: not done. Uploads add 1–2 s to a 54 s build even at 60 ms, and a CI job could end before a background upload does.
  • A local daemon keeping connections open: not now. It would save the TCP and TLS handshakes, about 120 ms per call at 60 ms, roughly 2 s of the 12.3 s above. That is less than the cost of a process to start, find and stop on three platforms.
  • Found on the way: each request over https waited 40 ms, because TLS wrote it in two records and Nagle's algorithm held the second back until the server's delayed acknowledgement. TCP_NODELAY brings a call on the same machine from 53 ms to 15 ms.
  • compare_caches.py --profile had reported no phases since 0.4, whose log lines start with the time. This PR fixes it.

Closes #18

Verification

  • GCC 16.1: configure, build and ctest: 103/103 passed
  • Clang 21 with libc++: configure, build and ctest: 103/103 passed; clang-tidy clean on the files touched
  • MSVC: CI only
  • clang-format --dry-run -Werror on the files touched
  • tools/check_attribution.py
  • Other: integration.remote.plain against a local bazel-remote, directly, through the latency proxy, and with CPPMCACHE_REMOTE_COMPRESSION=zstd; the measurements above (run on this machine; the network is a model, not a real link: no loss, no congestion control).

Not verified here: pipelining against servers other than bazel-remote and the Python test server, and anything on Windows and macOS (CI).

Effect on cache keys

None.

- tools/latency_proxy.py: a TCP proxy that adds a delay each way, the TCP
  handshake included, and a bandwidth shared by all connections.
- compare_caches.py: the remote scenarios can run against a bazel-remote
  started with Docker, over https, through the proxy, with compressed uploads.
- compare_caches.py: read the log of 0.4 and later, whose lines start with the
  time; the table of phases was empty since then.
Requests go in batches written without waiting for each answer (HTTP/1.1
pipelining). A miss publishes in three round trips instead of nine requests one
after the other: what the server lacks and its manifest; the missing blobs; the
ActionResult and the merged manifest. A hit fetches the outputs it lacks in one
batch. What a closed connection leaves unanswered is sent again on a new one.
- zstd v1.5.7, fetched by CPM and linked statically: content blobs are asked
  for compressed (Accept-Encoding: zstd), which bazel-remote serves from what it
  stores compressed; CPPMCACHE_REMOTE_COMPRESSION=zstd compresses uploads too
  (Content-Encoding: zstd, X-Digest-SizeBytes).
- TCP_NODELAY: TLS wrote a request in two records, and Nagle's algorithm held
  the second until the server's delayed acknowledgement, 40 ms per request.
- docs/measurements.md: MduX against bazel-remote, on the same machine and
  through the proxy at 20 ms and 60 ms; why neither background uploads nor a
  daemon are worth it now.
Copilot AI balanced review requested due to automatic review settings December 1, 2026 00:40
@ambroise-leclerc ambroise-leclerc added the performance Speed of a hit, a miss or the remote cache label Dec 1, 2026
An entry stored while the manifest blob or the ActionResult failed would hide
the entries the server held. One more round trip for a miss.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Moderate-severity issues remain unaddressed, including avoidable high peak memory usage from batching request bodies in exchange() and missing validation that allows negative delay/bandwidth values in latency_proxy.py, so the change needs fixes before approval.

2 open issues
What changed in this PR

Improves cppmcache remote-cache performance over higher-latency / lower-bandwidth links by adding a network latency/bandwidth proxy for measurement and implementing pipelined HTTP plus zstd compression support.

Changes:

  • Add an asyncio latency/bandwidth proxy and extend benchmarking to cover TLS, bazel-remote, and proxying scenarios.
  • Implement HTTP/1.1 pipelining/batching and zstd handling (compressed downloads by default; optional compressed uploads via CPPMCACHE_REMOTE_COMPRESSION=zstd).
  • Update transport/socket behavior, tests, docs, build configuration, and CI to cover the new remote-cache behaviors.
File Description
tools/​latency_proxy.py Adds an asyncio TCP proxy that models one-way delay and shared bandwidth to emulate network conditions for remote-cache measurements.
tools/​compare_caches.py Extends the benchmarking tool with remote/TLS/proxy/compression options and fixes profiling parsing for newer log formats.
tests/​spec/​HttpSpec.cpp Adds coverage to ensure the HTTP response reader handles pipelined responses correctly via remainder handling.
src/​cppmcache/​Store.cppm Introduces configuration parsing for CPPMCACHE_REMOTE_COMPRESSION=zstd to control upload compression behavior.
src/​cppmcache/​RemoteTransportDisabled.cpp Adds stubbed compression/remote-transport behavior for builds with remote support disabled.
src/​cppmcache/​RemoteTransport.cpp Updates the transport socket setup to reduce latency (including disabling Nagle via TCP_NODELAY).
src/​cppmcache/​Remote.cppm Reworks remote-cache request execution to use batched HTTP/1.1 pipelining and adds zstd download/optional upload compression logic.
src/​cppmcache/​Http.cppm Enhances HTTP request/response handling with additional headers, Content-Encoding parsing, and support for pipelined response remainders.
src/​cppmcache/​Compression.hpp Adds a compression API boundary header to expose zstd functionality without leaking third-party headers into module interfaces.
src/​cppmcache/​Compression.cpp Implements zstd compression/decompression wrappers used by the remote-cache client.
src/​cppmcache/​Cache.cppm Refactors remote cache fetch/publish flows to batch operations and reduce round trips when interacting with the remote CAS/manifest.
README.md Documents remote compression configuration and expected behavior for downloads and optional uploads.
docs/​usage.md Updates usage documentation to describe pipelining requirements and zstd download/upload semantics and caveats.
docs/​measurements.md Adds methodology and results for remote-cache performance measured across modelled network links.
CMakeLists.txt Integrates zstd via CPM (static linking) and wires it into the build when remote-cache support is enabled.
.github/​workflows/​ci.yml Updates CI to run remote integration tests with both default and zstd-compressed upload configurations.

Review effort: Balanced
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

Comment thread src/cppmcache/Remote.cppm Resolved
Comment thread tools/latency_proxy.py Resolved
The size that bounds it comes from the server: allocating it at once let a
remote entry exhaust memory and fail the compilation. A failed allocation is
now a failed download.
The responses that arrived before a failed send still count, and what they
leave unanswered is sent again. A batch that fails on a fresh connection before
any answer makes the client send one request at a time for the rest of the
process. Test: a server that closes the connection after every response.
A static OpenSSL lists -lzstd among its dependencies, which resolved
cppmcache's zstd calls to the system's shared library: the released Linux binary
then needed libzstd.so.1.
…ive proxy settings (#18)

- exchange() wrote a copy of the whole batch, blobs included: each message is
  now sent in turn, still without waiting for the answers.
- The local copy of the server's manifest is checked against its digest before
  it is merged: a damaged file would have replaced the server's manifest.
- latency_proxy.py refuses a negative delay or bandwidth.
Added as a subproject, zstd also installed its library, headers and package
files with cppmcache, and into the prefix of a project that imports it. Only
its sources are fetched now, compiled into a static library of cppmcache's own
that has no install rule (without the decoder's assembly, one thread).
The answers to a pipelined batch are small writes in a row, which Nagle's
algorithm held back until the client's delayed acknowledgement: 82 ms per miss
instead of 1 ms in the remote tests, and in the CI benchmark. bazel-remote and
nginx disable it by default; docs/usage.md says that a server should.
socketserver listens with a backlog of 5. A parallel build opens dozens of
connections at once, and Windows refuses those beyond the backlog and retries
them later: the likely cause of the 230 ms per compilation that the remote
scenarios of the Windows benchmark spend connecting.
@ambroise-leclerc

Copy link
Copy Markdown
Owner Author

Benchmark run on the last commit: with TCP_NODELAY in the test server, the upload phase of the remote scenarios is back to 0.3 s for 43 misses on Linux (it was 2.5 s).

On Windows the remote phase still takes 9.6 s for 43 misses (about 220 ms per compilation) against the test server, and 2.4 s on a populated remote cache. The larger backlog of the last commit did not change it, so the hypothesis in its message was wrong. The cause is still unknown: it shows only against the Python test server on a Windows runner, and I could not investigate it without a Windows machine. The backlog stays, as harmless.

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

Labels

performance Speed of a hit, a miss or the remote cache

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants