Skip to content

feat(proxy): allocator trial builds, jemalloc gauges and rig support (CIP-5738, CIP-5739, CIP-5740) - #535

Draft
tobyhede wants to merge 6 commits into
mainfrom
claude/project-thread-esbn3x
Draft

tobyhede wants to merge 6 commits into
mainfrom
claude/project-thread-esbn3x

Conversation

@tobyhede

@tobyhede tobyhede commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Requested by User · project thread

This adds the builds and measurement support for the allocator trial: CIP-5738, CIP-5739 and CIP-5740.
Default builds and released images stay on glibc and gain no dependency.

What changes

  • Allocator features (CIP-5738, CIP-5739). Three Cargo features, all off by default and Linux-only, swap the Rust global allocator:
    • jemalloc uses prefixed jemalloc, so C libraries such as aws-lc-sys keep using glibc.
    • jemalloc-unprefixed makes jemalloc replace C malloc too, with background_thread:true.
    • mimalloc uses mimalloc.
  • Startup log. Every build logs msg="Memory allocator" with allocator, c_malloc (the allocator behind C malloc), the jemalloc version, and the variable that holds runtime settings (_RJEM_MALLOC_CONF for prefixed jemalloc).
  • Rig images. mise run burn-in:image --allocator <glibc|jemalloc|jemalloc-unprefixed|mimalloc> [--target …] [--base …] builds Proxy and copies only the binary into a release image (default cipherstash/proxy:3.1.0). It prints the tag to pass to the rig's --image.
    • build:binary now takes --features and can cross-compile between Linux architectures.
    • aarch64 builds set JEMALLOC_SYS_WITH_LG_PAGE=16.
  • Prometheus gauges (CIP-5740). jemalloc builds export cipherstash_proxy_jemalloc_{allocated,active,resident,retained}_bytes, read after advancing jemalloc's stats epoch on each scrape.
    • To read at scrape time, these builds serve the metrics endpoint themselves with hyper. It matches the exporter's own listener: /health answers OK, every other path serves the metrics, and upkeep runs every 5 seconds.
    • Other builds are unchanged.
  • RSS rig.
    • The report records the allocator Proxy logged.
    • Scraped runs log the jemalloc gauges in scraper.log and summarise them in the report.
    • pooled-queries binds the salary as int4 or int8, whichever Proxy describes. The EQL v3 example schema makes the salary eql_v3_bigint_ord, which Proxy describes as INT8. Binding an i32 there would fail every insert.
  • CI. A new job builds the release binary with each allocator feature on both Linux targets, and runs the allocator and metrics tests.
  • Docs. The burn-in README lists the five trial variants and how to run each, including MALLOC_ARENA_MAX=2. The metrics reference lists the new gauges.

Checks

  • The workspace unit tests pass (cargo test --workspace --exclude cipherstash-proxy-integration).
  • Clippy passes with --all-features -D warnings.
  • The allocator and Prometheus tests pass with each feature.
    • The jemalloc tests show that a 64 MiB Rust allocation moves jemalloc's allocated count.
    • The unprefixed test shows that a 64 MiB C malloc moves it too.
  • I ran the binary locally with each feature and checked the startup log line in the text and structured formats.

Not done here

These need ZeroKMS credentials, which the session that wrote this PR did not have:

  • the 10-minute rig runs for each variant;
  • the pooled-queries run against a 3.x image.

The salary fix is based on how Proxy describes eql_v3_bigint_ord parameters. No rig run has tested it yet.

Acknowledgment

By submitting this pull request, I confirm that CipherStash can use, modify, copy, and redistribute this contribution, under the terms of CipherStash's choice.


Generated by Claude Code

Add off-by-default Cargo features that swap Proxy's Rust global
allocator on Linux for the allocator trial (CIP-5738, CIP-5739):
`jemalloc` (prefixed), `jemalloc-unprefixed` (also replaces C malloc,
with background threads) and `mimalloc`. Default builds keep glibc and
gain no dependency. Proxy logs the allocator it uses at startup.

`mise run burn-in:image` builds a variant for a Linux target and copies
only the binary into a release image for the RSS rig. `build:binary`
takes `--features`, can cross-compile between Linux architectures, and
gives jemalloc 64 KiB pages on aarch64. CI builds and tests each
allocator feature on both Linux targets.

The rig's pooled-queries workload binds the salary at the width Proxy
describes, since the EQL v3 example schema makes it bigint.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013Q6HAPvwBTmnJX6YikJ9N8
jemalloc builds with Prometheus on export jemalloc's allocated, active,
resident and retained bytes, read after advancing the stats epoch on
each scrape (CIP-5740). These builds serve the metrics endpoint
themselves so the read happens at scrape time; other builds keep the
exporter's own listener and export no new gauges.

The RSS rig records the allocator Proxy logged at startup, and in
scraped runs logs the jemalloc gauges per scrape and summarises them in
the report. The burn-in README lists the five trial variants and how to
run each one, and the metrics reference lists the new gauges.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013Q6HAPvwBTmnJX6YikJ9N8
@tobyhede tobyhede self-assigned this Dec 2, 2026
jemalloc's counts are process-wide, and `cargo test` runs tests on
parallel threads. The scrape test's 64 MiB allocation could be freed
between another test's two reads, so its count went down while it held
64 MiB. The three tests that assert on how the counts change now hold
one lock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013Q6HAPvwBTmnJX6YikJ9N8
Adds a manually started workflow that builds each allocator variant's
rig image, runs the RSS rig per variant, workload and host, runs pgbench
through each variant, and summarises both trials.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013Q6HAPvwBTmnJX6YikJ9N8
The trial runs from the allocator-trial branch, so its workflow and
scripts stay out of this pull request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013Q6HAPvwBTmnJX6YikJ9N8

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.

2 participants