diff --git a/.changesets/feat_zelda_enable_jemalloc_on_macos.md b/.changesets/feat_zelda_enable_jemalloc_on_macos.md new file mode 100644 index 0000000000..3605d162bc --- /dev/null +++ b/.changesets/feat_zelda_enable_jemalloc_on_macos.md @@ -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. diff --git a/apollo-router/Cargo.toml b/apollo-router/Cargo.toml index 3c9601af47..ee0cb29657 100644 --- a/apollo-router/Cargo.toml +++ b/apollo-router/Cargo.toml @@ -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"] @@ -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"] } diff --git a/apollo-router/src/axum_factory/axum_http_server_factory.rs b/apollo-router/src/axum_factory/axum_http_server_factory.rs index e21a3a51a5..1825d747b3 100644 --- a/apollo-router/src/axum_factory/axum_http_server_factory.rs +++ b/apollo-router/src/axum_factory/axum_http_server_factory.rs @@ -81,11 +81,7 @@ fn session_count_instrument() -> ObservableGauge { .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>) { use crate::axum_factory::metrics::jemalloc; @@ -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 })); diff --git a/apollo-router/src/axum_factory/metrics.rs b/apollo-router/src/axum_factory/metrics.rs index 1e97b78c5b..9f2d3ced3e 100644 --- a/apollo-router/src/axum_factory/metrics.rs +++ b/apollo-router/src/axum_factory/metrics.rs @@ -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; diff --git a/apollo-router/src/executable.rs b/apollo-router/src/executable.rs index b50f6a65d3..b9a37e3265 100644 --- a/apollo-router/src/executable.rs +++ b/apollo-router/src/executable.rs @@ -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; diff --git a/apollo-router/tests/integration/metrics.rs b/apollo-router/tests/integration/metrics.rs index b15be00a90..2a27665f66 100644 --- a/apollo-router/tests/integration/metrics.rs +++ b/apollo-router/tests/integration/metrics.rs @@ -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;