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
3 changes: 3 additions & 0 deletions .changesets/feat_zelda_enable_jemalloc_on_macos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Enable jemalloc on MacOS ([PR #8046](https://github.com/apollographql/router/pull/8046))

This PR enables the jemalloc allocator on MacOS by default. Previously, this was only done for Linux. We're making this change because it will make memory profiling easier than it currently is.
11 changes: 3 additions & 8 deletions apollo-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ default = ["global-allocator"]
# [dependencies]
# apollo-router = {version = "1.20", default-features = false}
# ```
global-allocator = ["dep:tikv-jemallocator", "tikv-jemalloc-ctl/stats"]
global-allocator = ["tikv-jemallocator/profiling", "tikv-jemalloc-ctl/stats", "tikv-jemalloc-ctl/profiling"]

# if you are doing heap profiling
dhat-heap = ["dhat"]
Expand Down Expand Up @@ -286,18 +286,13 @@ log = "0.4.22"
scopeguard = "1.2.0"
chrono = "0.4.41"

[target.'cfg(macos)'.dependencies]
uname = "0.1.1"

[target.'cfg(unix)'.dependencies]
uname = "0.1.1"
hyperlocal = { version = "0.9.1", default-features = false, features = [
"client",
] }

[target.'cfg(target_os = "linux")'.dependencies]
tikv-jemallocator = { version = "0.6.0", optional = true }
tikv-jemalloc-ctl = { version = "0.6.0", features = ["stats"], optional = true }
tikv-jemallocator = { version = "0.6.0", features = ["profiling"], optional = true }
tikv-jemalloc-ctl = { version = "0.6.0", features = ["stats", "profiling"], optional = true }

[dev-dependencies]
axum = { version = "0.8.1", features = ["http2", "ws"] }
Expand Down
18 changes: 3 additions & 15 deletions apollo-router/src/axum_factory/axum_http_server_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ fn session_count_instrument() -> ObservableGauge<u64> {
.init()
}

#[cfg(all(
feature = "global-allocator",
not(feature = "dhat-heap"),
target_os = "linux"
))]
#[cfg(all(feature = "global-allocator", not(feature = "dhat-heap"), unix))]
fn jemalloc_metrics_instruments() -> (tokio::task::JoinHandle<()>, Vec<ObservableGauge<u64>>) {
use crate::axum_factory::metrics::jemalloc;

Expand Down Expand Up @@ -503,21 +499,13 @@ where
experimental_log_on_broken_pipe: configuration.supergraph.experimental_log_on_broken_pipe,
}));
let session_count_instrument = session_count_instrument();
#[cfg(all(
feature = "global-allocator",
not(feature = "dhat-heap"),
target_os = "linux"
))]
#[cfg(all(feature = "global-allocator", not(feature = "dhat-heap"), unix))]
let (_epoch_advance_loop, jemalloc_instrument) = jemalloc_metrics_instruments();
// Tie the lifetime of the various instruments to the lifetime of the router
// by referencing them in a no-op layer.
router = router.layer(layer_fn(move |service| {
let _session_count_instrument = &session_count_instrument;
#[cfg(all(
feature = "global-allocator",
not(feature = "dhat-heap"),
target_os = "linux"
))]
#[cfg(all(feature = "global-allocator", not(feature = "dhat-heap"), unix))]
let _jemalloc_instrument = &jemalloc_instrument;
service
}));
Expand Down
6 changes: 1 addition & 5 deletions apollo-router/src/axum_factory/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#[cfg(all(
feature = "global-allocator",
not(feature = "dhat-heap"),
target_os = "linux"
))]
#[cfg(all(feature = "global-allocator", not(feature = "dhat-heap"), unix))]
pub(crate) mod jemalloc {
use std::time::Duration;

Expand Down
6 changes: 1 addition & 5 deletions apollo-router/src/executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ use crate::router::ShutdownSource;
use crate::uplink::Endpoints;
use crate::uplink::UplinkConfig;

#[cfg(all(
feature = "global-allocator",
not(feature = "dhat-heap"),
target_os = "linux"
))]
#[cfg(all(feature = "global-allocator", not(feature = "dhat-heap"), unix))]
#[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

Expand Down
6 changes: 1 addition & 5 deletions apollo-router/tests/integration/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#[cfg(all(
feature = "global-allocator",
not(feature = "dhat-heap"),
target_os = "linux"
))]
#[cfg(all(feature = "global-allocator", not(feature = "dhat-heap"), unix))]
#[tokio::test(flavor = "multi_thread")]
async fn test_jemalloc_metrics_are_emitted() {
use super::common::IntegrationTest;
Expand Down