router icon indicating copy to clipboard operation
router copied to clipboard

High increase of base memory usage by Router v1.46.0

Open juancarlosjr97 opened this issue 1 year ago • 1 comments

The latest Router version v1.46.0 appears to be requiring high memory compared to previous versions.

To Reproduce

Steps to reproduce the behavior:

Version 1.46.0 - High Memory Usage

Brach with reproduction: https://github.com/juancarlosjr97/apollo-graphql-federation-memory-leak/tree/router-1.46.0

Note: This has been noticed in a Router running with enterprise features enabled, but the reproduction is using the router configuration without enterprise features enabled

  1. Pull the branch https://github.com/juancarlosjr97/apollo-graphql-federation-memory-leak/tree/router-1.46.0
  2. Run docker compose up
  3. Run docker stats
  4. Notice the baseline for the Router running the version 1.46.0 is around 190 MiB and 200 MiB
CONTAINER ID   NAME       CPU %     MEM USAGE / LIMIT   MEM %     NET I/O         BLOCK I/O   PIDS
3122400d15e3   subgraph   0.00%     69.68MiB / 512MiB   13.61%    2.55kB / 656B   0B / 0B     11
e1c9c6fc3a15   router     0.08%     194.7MiB / 512MiB   38.02%    2.26kB / 656B   0B / 0B     17

In the enterprise features enabled, the Router containers are between 210 and 200 MiB and on start up goes up to 260 MiB and then goes down and stable between 210 and 200 MiB.

Version v1.45.1 - Lower memory usage

  1. Pull the branch https://github.com/juancarlosjr97/apollo-graphql-federation-memory-leak/tree/router-1.45.1
  2. Run docker compose up
  3. Run docker stats
  4. Notice the baseline for the Router running the version 1.45.1 is around 90 MiB and 110 MiB
CONTAINER ID   NAME       CPU %     MEM USAGE / LIMIT   MEM %     NET I/O         BLOCK I/O   PIDS
3122400d15e3   subgraph   0.00%     71.9MiB / 512MiB    14.04%    2.33kB / 656B   0B / 0B     11
79d672c50e55   router     0.00%     99.39MiB / 512MiB   19.41%    2.06kB / 726B   0B / 0B     17

There is a minor increase also between version 1.44.0 and 1.45.1 from 32% to 40% utilization without any change in consumer traffic.

In the enterprise features enabled, the Router containers are between 90 and 110 MiB.

Expected behavior

Unclear if version 1.46.0 requires a high memory base from the release notes https://github.com/apollographql/router/releases/tag/v1.46.0 but the 1.46.0...1.45.1 enables serde in the parking_lot dependency dependency the https://github.com/apollographql/router/blame/63e9fa287ba40c3dd94ea75dd5fdfe1795a75fd5/apollo-router/Cargo.toml#L246

Details of testing

  • Tested on Nomad Containers with enterprise features enabled
  • Tested locally with a Mac M1 running Docker
  • Versions affected: 1.46.0
  • Version Tested: 1.46.0, 1.45.1 and 1.44.0

juancarlosjr97 avatar May 14 '24 12:05 juancarlosjr97

Thanks for raising this issue. We also spotted that increase of base memory consumption and we already fixed it on dev https://github.com/apollographql/router/pull/5061 the fix will be available in the next release.

bnjjj avatar May 14 '24 12:05 bnjjj

The v1.47.0 not only fixed this issue but also decreased our steady memory usage by around 10% which is awesome! So, great job!

juancarlosjr97 avatar May 22 '24 12:05 juancarlosjr97