Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ jobs:
ls -l /tmp/aisix-shipped
test "$(nm /tmp/aisix-shipped | grep -c ' [tT] ')" -gt 1000
readelf -S /tmp/aisix-shipped | grep -E '\.symtab|\.eh_frame'
# jemalloc must actually be linked (prefixed _rjem_ symbols):
# if the cfg gates in aisix-server drift, the binary silently
# falls back to glibc malloc with no other signal.
nm /tmp/aisix-shipped | grep -q ' [tT] _rjem_' \
|| { echo "::error::jemalloc symbols missing from shipped binary"; exit 1; }

- name: Install cosign
if: github.event_name != 'pull_request'
Expand Down
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ tempfile = "3.13"
# CARGO_PROFILE_RELEASE_STRIP=none cargo build --release
# See issue #847.
[profile.release]
lto = "thin"
# Fat LTO over thin: cross-crate inlining across the whole graph is a
# measured per-request win on the saturation grid, paid for once per
# release build in link time. Numbers in the PR that flipped it.
lto = "fat"
codegen-units = 1
strip = "debuginfo"

Expand Down
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ COPY schemas ./schemas
# `--locked` forces the build to use the exact versions in Cargo.lock —
# fails fast if the lockfile is stale rather than silently resolving
# fresh deps in CI.
#
# If this ever builds for linux/arm64: jemalloc bakes the build host's
# page size into the binary, and QEMU reports 4K — set
# JEMALLOC_SYS_WITH_LG_PAGE=16 here or the image aborts at startup on
# 64K-page kernels (see crates/aisix-server/src/main.rs).
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/src/target \
cargo build --locked --release --bin aisix \
Expand Down
7 changes: 7 additions & 0 deletions crates/aisix-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ socket2 = { version = "0.5", features = ["all"] }
# axum-server itself depends on, so the builder types unify.
hyper-util = { version = "0.1", features = ["server-auto", "tokio"] }

# jemalloc as the global allocator, only on the targets we ship and
# bench (Linux glibc — the Docker image and both supported production
# arches). Other targets (macOS dev builds, musl) keep the system
# allocator rather than carry an allocator we never run in production.
[target.'cfg(all(target_os = "linux", target_env = "gnu"))'.dependencies]
tikv-jemallocator = "0.6"

[dev-dependencies]
tempfile = "3"
wiremock = "0.6"
Expand Down
12 changes: 12 additions & 0 deletions crates/aisix-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ use std::error::Error as StdError;
use std::path::{Path, PathBuf};
use std::sync::Arc;

// jemalloc as the global allocator on the shipped/benched targets
// (Linux glibc): under the thread-per-core saturation load, allocator
// time drops from ~15% of request CPU (glibc malloc) to ~6%. Other
// targets keep the system allocator. One deploy caveat: jemalloc bakes
// the build host's page size into the binary, so an aarch64 binary
// built on a 4K-page host aborts at startup on a 64K-page kernel —
// cross-building for such kernels needs JEMALLOC_SYS_WITH_LG_PAGE=16,
// which runs on both page sizes.
#[cfg(all(target_os = "linux", target_env = "gnu"))]
#[global_allocator]
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

mod cert_bundle;
mod export;
mod heartbeat;
Expand Down