Repository navigation
Remote cache: measured across a network; compressed and pipelined (#18) - #78
ambroise-leclerc wants to merge 11 commits into
Conversation
- 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.
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.
There was a problem hiding this comment.
🟡 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.
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.
|
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 |

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"): MduX57a7d1d, GCC 16.1, 336 units, 24 cores, bazel-remote on the same machine, over https. The network is modelled bytools/latency_proxy.py(new): a delay each way, the TCP handshake included, and a shared bandwidth. Median of 3 rounds.(About 53–54 s without any cache, 6 s from a populated local cache.)
Decisions, the options #18 lists:
Accept-Encoding: zstd(bazel-remote stores them compressed anyway), andCPPMCACHE_REMOTE_COMPRESSION=zstdcompresses uploads too. Uploads stay uncompressed by default because a server that ignoresContent-Encodingwould store the compressed bytes, which clients then refuse as not matching their digest. zstd v1.5.7 comes through CPM, linked statically.TCP_NODELAYbrings a call on the same machine from 53 ms to 15 ms.compare_caches.py --profilehad reported no phases since 0.4, whose log lines start with the time. This PR fixes it.Closes #18
Verification
ctest: 103/103 passedctest: 103/103 passed; clang-tidy clean on the files touchedclang-format --dry-run -Werroron the files touchedtools/check_attribution.pyintegration.remote.plainagainst a local bazel-remote, directly, through the latency proxy, and withCPPMCACHE_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.