Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix PcpMmvWriter memory leak #121

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

pwinckles
Copy link
Contributor

@pwinckles pwinckles commented Jul 29, 2024

The perMetricsByteBuffers map leaks in PcpMmvWriter as follows:

  1. A new metric is added.
  2. Skipping some plumbing, PcpMmvWriter.stop() is called, which clears PcpMmvWriter.metricData, which is a map of PcpValueInfo objects that describe all of the metrics.
  3. All of the metrics are re-added with calls to PcpMmvWriter.addMetricInfo(), which creates new PcpValueInfo instances to repoplulate PcpMmvWriter.metricData.
  4. PcpMmvWriter.start() is called, which creates a new ByteBuffer, and populates slices of the buffer into
    PcpMmvWriter.perMetricByteBuffers. This map is keyed off the new PcpValueInfo instances, and this is where it's leaking.

This fixes the leak by clearing the map when PcpMmvWriter.reset() is called. This is safe because that method also clears PcpMmvWriter.metricData, which is assumed to be insync with perMetricByteBuffers. Clearing the map allows the old PcpValueInfo objects to be GC'd as well as the backing DirectByteBuffer.

@pwinckles
Copy link
Contributor Author

An alternative, simpler, solution would be to just call perMetricByteBuffers.clear() in PcpMmvWriter.reset(), though I have not run this solution.

@natoscott
Copy link
Member

@pwinckles I haven't heard from any of the Parfait developers recently, but let's give them a little more time. If we don't get a response though would you be interested in becoming a direct contributor to this git repo?

@pwinckles
Copy link
Contributor Author

@natoscott

If we don't get a response though would you be interested in becoming a direct contributor to this git repo?

What does that entail?

I tested the alternative solution that simply clears perMetricByteBuffers, and it works. I'll update the PR later.

@natoscott
Copy link
Member

@pwinckles I'll send you an invite to join the pcp github org - should be an email arriving shortly. There's a #parfait team on PCP slack channel I encourage you to join - see https://pcp.io/community.html - it's very quiet but some of the original Parfait developers may still be lurking there if you have further questions.

The `perMetricsByteBuffers` map leaks in `PcpMmvWriter` as follows:

1. A new metric is added.
2. Skipping some plumbing, `PcpMmvWriter.stop()` is called, which
clears `PcpMmvWriter.metricData`, which is a map of `PcpValueInfo`
objects that describe all of the metrics.
3. All of the metrics are re-added with calls to
`PcpMmvWriter.addMetricInfo()`, which creates new `PcpValueInfo`
instances to repoplulate `PcpMmvWriter.metricData`.
4. `PcpMmvWriter.start()` is called, which creates a new `ByteBuffer`,
and populates slices of the buffer into
`PcpMmvWriter.perMetricByteBuffers`. This map is keyed off the new
`PcpValueInfo` instances, and this is where it's leaking.

This fixes the leak by clearing the map when `PcpMmvWriter.reset()` is
called. This is safe because that method also clears
`PcpMmvWriter.metricData`, which is assumed to be insync with
`perMetricByteBuffers`. Clearing the map allows the old `PcpValueInfo`
objects to be GC'd as well as the backing `DirectByteBuffer`.
@pwinckles pwinckles changed the title fix memory leak fix PcpMmvWriter memory leak Aug 6, 2024
@pwinckles
Copy link
Contributor Author

Thanks!

I did a force push on this branch to change it to the clear() solution.

@pwinckles
Copy link
Contributor Author

@natoscott I'm not in a particular rush or anything, as we're already using a forked version, but, since you added me to the github group, I'm uncertain as to what your process expectations are here. Shall I just ping the slack and wait and see for a few more weeks?

@natoscott
Copy link
Member

@pwinckles I think since noone's commented by now, go ahead and merge.

@pwinckles pwinckles merged commit a4cd2d6 into performancecopilot:main Aug 21, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants