Skip to content

Keep instantiated OffsetMapCodecManager so that metrics will not be recreated every commit #859#892

Merged
John Byrne (johnbyrnejb) merged 4 commits intoconfluentinc:masterfrom
priesus:patch-1
Oct 27, 2025
Merged

Keep instantiated OffsetMapCodecManager so that metrics will not be recreated every commit #859#892
John Byrne (johnbyrnejb) merged 4 commits intoconfluentinc:masterfrom
priesus:patch-1

Conversation

@priesus
Copy link
Copy Markdown
Contributor

@priesus Stefan Pries (priesus) commented Oct 8, 2025

We can see the OffsetMapCodecManager being instantiated every second or so, which creates 3 new Meters (Timer, Gauge, Counter) every time.

Because they are referenced from the registeredMeters list in PCMetrics, the duplicate Meters and Tags won't be cleaned up by garbage collection. This creates a significant memory leak over time (issue #859).

This is my first open source contribution, please let me know if this change doesn't make sense or what contribution guidelines I have missed!

Checklist

  • Documentation (if applicable)
  • Changelog

…ecreated every commit confluentinc#859

We can see the OffsetMapCodecManager being instantiated every second or so, which creates 3 new Meters (Timer, Gauge, Counter) every time.

Because they are references from the registeredMeters array in PCMetrics, this creates a significant memory leak over time.
@priesus Stefan Pries (priesus) requested a review from a team as a code owner October 8, 2025 12:15
@priesus
Copy link
Copy Markdown
Contributor Author

To provide additional context:
In our production environment we see that per 24 hours roughly 1 million Meter.Id objects created that are not being garbage-collected. This seems independent of consumer throughput.
image

The problem is that OffsetMapCodecManager gets instantiated a lot and each time the same 3 metrics are created once more.

@priesus
Copy link
Copy Markdown
Contributor Author

Nacho Muñoz Gómez (@nachomdo) or Roman Kolesnev (@rkolesnev) Are you maybe part of the reviewer group and can have a look at this PR?

@priesus
Copy link
Copy Markdown
Contributor Author

Stephen Hegarty (@stephenheg) John Byrne (@johnbyrnejb) Would any of you be available to review this fix? I was hoping to get the memory leak fixed before black friday :-)

@priesus
Copy link
Copy Markdown
Contributor Author

Martyn Ye (@sangreal) Are you part of the reviewer group and can help out here with a review?

@sangreal
Copy link
Copy Markdown
Contributor

sorry, I am not a official Confluent reviewer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT.

Stefan Pries (@priesus) - Changelog / readme needs to be updated please as well - you can see how its updated in other PRs - its the CHANGELOG.adoc file and then once its updated - regenerate readme to take in the changes - mvn asciidoc-template:build .

John Byrne (@johnbyrnejb) - could you please do formal approval / merge to master once docs are updated?

@rkolesnev
Copy link
Copy Markdown
Contributor

Roman Kolesnev (rkolesnev) commented Oct 26, 2025

Nacho Muñoz Gómez (@nachomdo) or Roman Kolesnev (@rkolesnev) Are you maybe part of the reviewer group and can have a look at this PR?

Hey Stefan Pries (@priesus) - i dont work for Confluent anymore and dont use Parallel Consumer in my current day to day - but i try to keep an eye on it when i have a bit of time...

@priesus
Copy link
Copy Markdown
Contributor Author

Roman Kolesnev (@rkolesnev) Thanks so much for the feedback! I've updated the changelog & readme.
John Byrne (@johnbyrnejb) Let me know if this looks good to you as well!

@johnbyrnejb John Byrne (johnbyrnejb) merged commit 4569fd1 into confluentinc:master Oct 27, 2025
1 check passed
@priesus Stefan Pries (priesus) deleted the patch-1 branch October 28, 2025 08:14
@priesus
Copy link
Copy Markdown
Contributor Author

John Byrne (@johnbyrnejb) I believe my changes broke the master branch build. I'm unable to see the build logs and I'm also unable to run the tests myself because our company policy doesn't let us use the maven repositories required by this project.
Could you help me figure out what broke?
Sorry for the troubles :-(

@priesus
Copy link
Copy Markdown
Contributor Author

Just to clarify: To verify my changes I had to copy the /src/main/java into one of our projects and I was able to fix the memory leak with the changes from this PR.

So I assume the build issue is related to a test. Let me see if I can troubleshoot this somehow.

@priesus
Copy link
Copy Markdown
Contributor Author

John Byrne (@johnbyrnejb) So far I am still unable to get the tests to run locally, because I am unable to fetch the io.stubbs.truth dependencies. Would you be able to help check what's broken in the current build?

@astubbs
Copy link
Copy Markdown
Contributor

John Byrne (John Byrne (@johnbyrnejb)) So far I am still unable to get the tests to run locally, because I am unable to fetch the io.stubbs.truth dependencies. Would you be able to help check what's broken in the current build?

it wouldn't have bene broken, but the truth def is on githubs maven distribution system. I'm going to publish it to maven central soon to avoid this problem.

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.

5 participants