Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ jobs:
- name: Test
run: ctest --test-dir build --output-on-failure

# The same remote cache test, against a real server instead of the test one: over http, then
# over https with Basic authentication (the certificate of tests/integration/tls and an
# The same remote cache test, against a real server instead of the test one: over http,
# without and with compressed uploads, then over https with Basic authentication (the certificate of tests/integration/tls and an
# htpasswd file). The image is pinned by digest.
- name: Test the remote cache against bazel-remote
if: matrix.llvm == '21'
Expand All @@ -185,6 +185,10 @@ jobs:
docker run -d --rm --name bazel-remote -p 127.0.0.1:19090:8080 "$BAZEL_REMOTE_IMAGE" --max_size=1 --dir=/data
wait_for http://127.0.0.1:19090/status
CPPMCACHE_TEST_REMOTE=http://127.0.0.1:19090 ctest --test-dir build -R 'integration\.remote\.plain' --output-on-failure
# Again with zstd-compressed uploads, which bazel-remote decodes (and downloads are asked for
# compressed in both runs).
CPPMCACHE_REMOTE_COMPRESSION=zstd CPPMCACHE_TEST_REMOTE=http://127.0.0.1:19090 \
ctest --test-dir build -R 'integration\.remote\.plain' --output-on-failure
docker logs bazel-remote 2>&1 | grep -cE ' (GET|PUT|HEAD) ' | xargs echo "requests served by bazel-remote:"
docker rm -f bazel-remote

Expand Down
27 changes: 25 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,28 @@ if(CPPMCACHE_REMOTE)
endif()
set(cppmcache_tls_engine ${cppmcache_existing_engine})
endif()
set(cppmcache_transport src/cppmcache/RemoteTransport.cpp)
# zstd compresses the blobs exchanged with the remote cache. Only its sources are fetched: they
# are compiled here into a static library of cppmcache's own, so that zstd's install rules and
# package files never reach the tree, or the installation, of a project that imports cppmcache.
# Confined like stdnet to a classic translation unit (Compression.cpp).
CPMAddPackage(
NAME zstd
GITHUB_REPOSITORY facebook/zstd
# v1.5.7
GIT_TAG f8745da6ff1ad1e7bab384bd1f9d742439278e99
DOWNLOAD_ONLY YES
)
enable_language(C)
file(GLOB cppmcache_zstd_sources CONFIGURE_DEPENDS
"${zstd_SOURCE_DIR}/lib/common/*.c"
"${zstd_SOURCE_DIR}/lib/compress/*.c"
"${zstd_SOURCE_DIR}/lib/decompress/*.c")
add_library(cppmcache_zstd STATIC ${cppmcache_zstd_sources})
# The decoder's assembly needs no assembler set up when it is left out; one thread is enough.
target_compile_definitions(cppmcache_zstd PRIVATE ZSTD_DISABLE_ASM ZSTD_MULTITHREAD=0)
target_include_directories(cppmcache_zstd SYSTEM PUBLIC "${zstd_SOURCE_DIR}/lib")
set_target_properties(cppmcache_zstd PROPERTIES POSITION_INDEPENDENT_CODE ON)
set(cppmcache_transport src/cppmcache/RemoteTransport.cpp src/cppmcache/Compression.cpp)
else()
set(cppmcache_transport src/cppmcache/RemoteTransportDisabled.cpp)
endif()
Expand All @@ -147,7 +168,9 @@ endif()
target_sources(cppmcache_core PRIVATE ${cppmcache_transport} src/cppmcache/Sha256Blocks.cpp)
set_source_files_properties(${cppmcache_transport} src/cppmcache/Sha256Blocks.cpp PROPERTIES CXX_SCAN_FOR_MODULES OFF)
if(CPPMCACHE_REMOTE)
target_link_libraries(cppmcache_core PRIVATE stdnet::stdnet)
# zstd first: a static OpenSSL brings `-lzstd` among its own dependencies, which would otherwise
# resolve cppmcache's zstd calls to the system's shared library.
target_link_libraries(cppmcache_core PRIVATE cppmcache_zstd stdnet::stdnet)
if(NOT cppmcache_tls_engine STREQUAL "OFF")
set_property(SOURCE ${cppmcache_transport} APPEND PROPERTY COMPILE_DEFINITIONS CPPMCACHE_TLS=1)
endif()
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ come from the environment or from files, never from the URL. Details are in
| `CPPMCACHE_REMOTE_TOKEN` | bearer token sent to the remote cache (or `CPPMCACHE_REMOTE_TOKEN_FILE`, a file that holds it) |
| `CPPMCACHE_REMOTE_USER`, `CPPMCACHE_REMOTE_PASSWORD` | Basic authentication with the remote cache (or `CPPMCACHE_REMOTE_PASSWORD_FILE`) |
| `CPPMCACHE_REMOTE_CA_CERT` | PEM file of the only roots trusted over `https://` (default: the system's) |
| `CPPMCACHE_REMOTE_COMPRESSION` | `zstd`: upload blobs compressed, for bazel-remote (downloads are always asked for compressed) |
| `CPPMCACHE_REMOTE_READ_ONLY` | fetch from the remote cache but never publish to it |
| `CPPMCACHE_REMOTE_TIMEOUT_MS` | time allowed for one remote operation (default: 10000) |
| `CPPMCACHE_LOG` | file to which each call appends its outcome, the reason and the time of each phase ([format](docs/usage.md#reading-the-log)) |
Expand Down
54 changes: 54 additions & 0 deletions docs/measurements.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,60 @@ them. Each cell is a single run.

All 950 MduX tests pass on the build served entirely from the cache.

## Remote cache across a network

MduX at commit `57a7d1d`, GCC 16.1, Release, 336 units, built on one Linux machine with 24 cores
against a bazel-remote on the same machine (the image CI uses), measured on 2026-12-01 with

```sh
tools/compare_caches.py --source <MduX> --work <work> --cppmcache <cppmcache> \
--edit include/mdux/core/Units.cppm --cmake-arg=-DCMAKE_CXX_COMPILER=g++ --cmake-arg=-DENABLE_CACHE=OFF \
--skip none --skip ccache --skip-scenario edit --skip-scenario revert --skip-scenario relocated \
--remote-server bazel-remote --remote-tls [--remote-delay-ms D --remote-bandwidth-mbit B] [--remote-compression] \
--runs 3 --profile
```

The network is a model: `tools/latency_proxy.py` delays every byte by D milliseconds each way,
the TCP handshake included, and shares B Mbit/s each way between all connections. It has no
packet loss and no congestion control, so a real link of the same latency and bandwidth may do
worse. Each cell is the median of 3 rounds, with the lowest and highest in brackets. "Before" is
the client of 0.4 with TLS; "after" adds pipelined requests, zstd and `TCP_NODELAY`, with
`CPPMCACHE_REMOTE_COMPRESSION=zstd`.

| Link (round trip, bandwidth) | Clean build, empty local and remote caches | Clean build, empty local cache, populated remote cache |
|---|---:|---:|
| same machine, before | 55.2 s (54.2–55.4) | 6.6 s (6.6–6.7) |
| same machine, after | 54.0 s (54.0–54.9) | 6.5 s (6.4–6.5) |
| 20 ms, 100 Mbit/s, before | 56.1 s (55.2–57.2) | 11.7 s (11.6–12.0) |
| 20 ms, 100 Mbit/s, after | 55.0 s (55.0–55.5) | 8.2 s (8.0–8.4) |
| 60 ms, 50 Mbit/s, before | 61.6 s (61.5–63.4) | 19.9 s (19.8–20.1) |
| 60 ms, 50 Mbit/s, after | 56.2 s (55.4–57.6) | 12.3 s (12.0–12.6) |

For reference, the same build takes 53–54 s with an empty local cache and no remote one, and
6.0–6.2 s from a populated local cache. What the measurements showed, and what was done:

- **Uploads cost little wall-clock time.** A miss of the first build waits for its uploads, but
24 compilations run at once and the compiler dominates: the remote cache adds 1 to 2 s to a
build of about 54 s even at 60 ms. Uploading in the background, after the compilation has
returned, would save at most that, at the price of uploads that a CI job could end before they
are done; it was not done.
- **Bandwidth limits a build served by the remote cache.** The results of MduX weigh 71 MB, 13.5
MB once compressed with zstd: at 50 Mbit/s the transfer alone takes 11 s uncompressed. Content
blobs are now asked for compressed, which bazel-remote serves from what it stores compressed
anyway, and can be uploaded compressed.
- **Round trips.** Before, a miss made nine requests one after the other, a hit five. Requests now
go in pipelined batches: a miss publishes in four round trips. The time of cppmcache spent
uploading fell by 30 to 40 %, which a parallel build mostly hid already.
- **TLS cost 40 ms per request.** TLS wrote a request in two records, and Nagle's algorithm held
the second back until the server's delayed acknowledgement: 53 ms per call on the same machine,
15 ms with `TCP_NODELAY`.
- **A connection per compilation.** At 60 ms a hit still spends about 290 ms talking to the server:
the TCP and TLS handshakes, then the manifest, then the result, each one round trip, then the
outputs. A local daemon that kept connections open would save the two handshakes, about 120 ms
per call at 60 ms, which spread over 24 parallel compilations is about 2 s of the 12.3 s above.
That is worth less than its cost (a process to start, find and stop, on three platforms) for
now; HTTP/2 or gRPC (#19) does not change it, since each compilation is still its own process.

## Reading the tables

- **ccache and modules.** With GCC, ccache passes every unit that imports or provides a module
Expand Down
21 changes: 17 additions & 4 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ export CPPMCACHE_REMOTE=http://localhost:8080
- The server never fails a build. If it cannot be reached, or refuses the credentials, cppmcache
counts a remote error, leaves it alone for the rest of that compilation, and carries on with the
local cache.
- Requests are pipelined: a compilation sends its requests in a few batches without waiting for
each answer, and a miss publishes its result in four round trips. A server, or a proxy in front
of it, must therefore accept pipelined HTTP/1.1 requests, as bazel-remote and nginx do. It
should also disable Nagle's algorithm on its connections (`TCP_NODELAY`, the default of both):
otherwise each answer of a batch after the first waits for the client's delayed acknowledgement,
40 ms. A server that refuses pipelining altogether is detected, and then sent one request at a
time.
- Content blobs are asked for compressed (`Accept-Encoding: zstd`): bazel-remote stores them
compressed and sends them so, about five times smaller for object files and BMIs. With
`CPPMCACHE_REMOTE_COMPRESSION=zstd` they are uploaded compressed too (`Content-Encoding: zstd`
and `X-Digest-SizeBytes`, as bazel-remote takes them). Leave it unset with a server that does not
understand that encoding: it would store the compressed bytes, which every client would then
refuse as not matching their digest.

### TLS and credentials

Expand Down Expand Up @@ -575,8 +588,8 @@ only, and the configure step says so. `openssl` or `schannel` require one, and `
prints for `--version`, which is part of the key. A program of that name that only wraps a
compiler and adds options of its own, chosen by its environment, would not be seen: the key
would not follow those options. A script is always passed through.
- The remote cache has no compression, and it speaks HTTP, not the gRPC interface of the Remote
Execution API. Uploads are synchronous: a miss waits for them. Each compilation opens its own
connection, so over `https://` each one also makes a TLS handshake; revocation of the server's
certificate is not checked.
- The remote cache speaks HTTP, not the gRPC interface of the Remote Execution API. A miss waits
for its uploads, which a parallel build hides ([measurements](measurements.md#remote-cache-across-a-network)).
Each compilation opens its own connection, so over `https://` each one also makes a TLS
handshake; revocation of the server's certificate is not checked.
- A restored dependency file is rewritten, not copied: the same dependencies, laid out differently.
Loading
Loading