diff --git a/.changesets/fix_simon_rayonless_sysinfo.md b/.changesets/fix_simon_rayonless_sysinfo.md new file mode 100644 index 0000000000..a2b7e06a4b --- /dev/null +++ b/.changesets/fix_simon_rayonless_sysinfo.md @@ -0,0 +1,12 @@ +### Fix increased memory usage in `sysinfo` since Router 1.59.0 ([PR #6634](https://github.com/apollographql/router/pull/6634)) + +In version 1.59.0, Apollo Router started using the `sysinfo` crate to gather metrics about available CPUs and RAM. By default, that crate uses `rayon` internally to parallelize its handling of system processes. In turn, rayon creates a pool of long-lived threads. + +In a particular benchmark on a 32-core Linux server, this caused resident memory use to increase by about 150 MB. This is likely a combination of stack space (which only gets freed when the thread terminates) and per-thread space reserved by the heap allocator to reduce cross-thread synchronization cost. + +This regression is now fixed by: + +* Disabling `sysinfo`’s use of `rayon`, so the thread pool is not created and system processes information is gathered in a sequential loop. +* Making `sysinfo` not gather that information in the first place since Router does not use it. + +By [@SimonSapin](https://github.com/SimonSapin) in https://github.com/apollographql/router/pull/6634 diff --git a/Cargo.lock b/Cargo.lock index 8d3c937d52..ca935d03d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6603,7 +6603,6 @@ dependencies = [ "libc", "memchr", "ntapi", - "rayon", "windows 0.57.0", ] diff --git a/apollo-router/Cargo.toml b/apollo-router/Cargo.toml index 7bbbae06c5..9c11d9d060 100644 --- a/apollo-router/Cargo.toml +++ b/apollo-router/Cargo.toml @@ -212,7 +212,7 @@ serde_yaml = "0.8.26" static_assertions = "1.1.0" strum_macros = "0.26.0" sys-info = "0.9.1" -sysinfo = { version = "0.32.0", features = ["windows"] } +sysinfo = { version = "0.32.0", features = ["system", "windows"], default_features = false } thiserror = "1.0.61" tokio.workspace = true tokio-stream = { version = "0.1.15", features = ["sync", "net"] } diff --git a/apollo-router/src/plugins/fleet_detector.rs b/apollo-router/src/plugins/fleet_detector.rs index 46fadedd55..f3a9e945c3 100644 --- a/apollo-router/src/plugins/fleet_detector.rs +++ b/apollo-router/src/plugins/fleet_detector.rs @@ -44,7 +44,8 @@ struct SystemGetter { impl SystemGetter { fn new() -> Self { let mut system = System::new(); - system.refresh_all(); + system.refresh_cpu_all(); + system.refresh_memory(); Self { system, start: Instant::now(),