Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux: replace default allocator with jemalloc #2882

Merged
merged 14 commits into from
Apr 18, 2023
5 changes: 5 additions & 0 deletions .changesets/maint_garypen_jemalloc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### use jemalloc on linux

Performance testing and flamegraph analysis suggests that jemalloc on linux is about 35% faster than the default allocator.

By [@garypen](https://github.com/garypen) in https://github.com/apollographql/router/pull/2882
21 changes: 21 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ dependencies = [
"test-log",
"test-span",
"thiserror",
"tikv-jemallocator",
"tokio",
"tokio-rustls",
"tokio-stream",
Expand Down Expand Up @@ -5872,6 +5873,26 @@ dependencies = [
"tower",
]

[[package]]
name = "tikv-jemalloc-sys"
version = "0.5.3+5.3.0-patched"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a678df20055b43e57ef8cddde41cdfda9a3c1a060b67f4c5836dfb1d78543ba8"
dependencies = [
"cc",
"libc",
]

[[package]]
name = "tikv-jemallocator"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20612db8a13a6c06d57ec83953694185a367e16945f66565e8028d2c0bd76979"
dependencies = [
"libc",
"tikv-jemalloc-sys",
]

[[package]]
name = "time"
version = "0.3.20"
Expand Down
2 changes: 2 additions & 0 deletions apollo-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ uname = "0.1.1"

[target.'cfg(unix)'.dependencies]
uname = "0.1.1"
tikv-jemallocator = "0.5"

[dev-dependencies]
ecdsa = { version = "0.15.1", features = ["signing", "pem", "pkcs8"] }
Expand Down Expand Up @@ -257,3 +258,4 @@ tonic-build = "0.8.4"
[[test]]
name = "integration_tests"
path = "tests/integration_tests.rs"

10 changes: 10 additions & 0 deletions apollo-router/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
//! Main entry point for CLI command to start server.
// Note: We want to use jemalloc on unix, but we don't enable it if dhat-heap is in use because we
// can only have one global allocator
#[cfg(target = "unix")]
#[cfg(not(feature = "dhat-heap"))]
use tikv_jemallocator::Jemalloc;

#[cfg(target = "unix")]
#[cfg(not(feature = "dhat-heap"))]
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;

fn main() {
match apollo_router::main() {
Expand Down