Skip to content

Memory leak when Pyroscope is enabled #28

@nwalters512

Description

@nwalters512

When we enable Pyroscope on our application, we observe a steady increase in memory consumption. I've annotated a AWS CloudWatch graph of Node RSS memory:

Untitled drawing

Some commentary about what we saw:

  • After enabling Pyroscope, we saw memory usage increase pretty much linearly.
  • After a while, the EC2 instance as a whole became completely unresponsive. At that point I couldn't even SSH in to the instance to poke around, so I'm unable to even guess why that might be. Rebooting the entire VM "fixed" things (until they broke again).
    • You can identify the "unresponsive" periods as the ones that are missing data.
  • This was on our staging environment, so the app wasn't serving any real requests and was under basically zero load.
  • After disabling Pyroscope and making no other changes, we stopped leaking memory.
  • The graph lines that spike past 3.0GB/1.5GB are for an instance with a single copy of the app running on it. The other 4 lines are 4 copies of an app running on the same instance. I'm unsure why the two types of hosts behave differently. My best guess is that the OS starts doing a ton of swapping, or runs out of memory entirely (we're on an EC2 t3.medium instance that has 4GB of RAM, so 4 processes x 1GB each would definitely exhaust the available RAM).
  • Pyroscope itself doesn't reflect that the Node process is using anywhere close to 1GB of memory (per inuse_space, it maxed out at ~350MB of mem).

These lines of code are the only difference between "leaking memory" and "not leaking memory":

          const Pyroscope = require('@pyroscope/nodejs');
          Pyroscope.init({
            appName: 'prairielearn',
            // Assume `config` contains sensible values.
            serverAddress: config.pyroscopeServerAddress,
            authToken: config.pyroscopeAuthToken,
            tags: {
              instanceId: config.instanceId,
              ...(config.pyroscopeTags ?? {}),
            },
          });
          Pyroscope.start();

I recognize this isn't a ton of information to go off, so I'd be happy to provide anything else that might help get to the bottom of this. We'd love to use Pyroscope, but our experience so far is an obvious dealbreaker.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions