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
6 changes: 4 additions & 2 deletions apollo-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ sysinfo = { version = "0.35.0", features = [
"windows",
], default-features = false }
thiserror = "2.0.0"
tikv-jemallocator = { version = "0.6.0", optional = true }
tikv-jemalloc-ctl = { version = "0.6.0", features = ["stats"], optional = true }
tokio.workspace = true
tokio-stream = { version = "0.1.15", features = ["sync", "net"] }
tokio-util = { version = "0.7.11", features = ["net", "codec", "time"] }
Expand Down Expand Up @@ -292,6 +290,10 @@ 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 }

[dev-dependencies]
axum = { version = "0.8.1", features = ["http2", "ws"] }
axum-server = "0.7.1"
Expand Down
15 changes: 11 additions & 4 deletions apollo-router/src/axum_factory/axum_http_server_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,16 +502,23 @@ where
early_cancel: configuration.supergraph.early_cancel,
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"
))]
let (_epoch_advance_loop, jemalloc_instrument) = jemalloc_metrics_instruments();
// Tie the lifetime of the various instruments to the lifetime of the router
// by creating them in a no-op layer.
router = router.layer(layer_fn(|service| {
let _session_count_instrument = session_count_instrument();
// 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"
))]
let (_epoch_advance_loop, _je_malloc_instrument) = jemalloc_metrics_instruments();
let _jemalloc_instrument = &jemalloc_instrument;
service
}));

Expand Down
4 changes: 2 additions & 2 deletions apollo-router/src/axum_factory/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ pub(crate) mod jemalloc {

use crate::metrics::meter_provider;

fn start_epoch_advance_loop() -> tokio::task::JoinHandle<()> {
pub(crate) fn start_epoch_advance_loop() -> tokio::task::JoinHandle<()> {
tokio::spawn(async move {
loop {
tokio::time::sleep(Duration::from_millis(500)).await;
if let Err(e) = tikv_jemalloc_ctl::epoch::advance() {
tracing::warn!("Failed to advance jemalloc epoch: {}", e);
}
tokio::time::sleep(Duration::from_millis(500)).await;
}
})
}
Expand Down