-
Notifications
You must be signed in to change notification settings - Fork 600
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
Memory/retention problem with thread tracing and very-long-lived threads #2418
Comments
Hi @bensheldon! Thank you for sharing such a thorough report with your findings and thoughts. It really helps us get started! First a few questions:
You mentioned seeing a lot of Based on the thought that the agent is continuously adding datastore segments in your case while the transaction is open, here are some options to manage memory:
Additional note:
Whether in documentation or code, there seems to be an opportunity to improve how New Relic handles long-running threads. So thank you again for bringing this to our attention! |
Hello @hannahramadan Thanks a lot for your detailed answer. I was with @bensheldon when we looked at this issue on one of our app. We disabled thread tracing on the app and saw no improvement. Then we disabled NewRelic for the specific impacted containers and saw no changes. I think the issue can be closed for the moment. I will re-download some heap dump without NewRelic and Segment and check again what we have. I would love to answer to all of your questions, but I think the issue is somewhere else. :) |
Thanks for the followup @benoittgt! I'll close this for now, but please reopen should this turn out to be relevant. Best of luck on the issue search ◡̈ |
Description
I'm debugging a memory retention problem in a Rails application. This is half a question, and half a hypothesis: it seems like
instrumentation.thread.tracing
can lead to memory growth when it is inserted into a very long lived thread; does that seem possible?This was debugged on
v9.7.0
version of this gem.Expected Behavior
I am imagining that the
NewRelic::Agent::Transaction
should have some mechanism to purge/flush/remove old members ofNewRelic::Agent::Transaction::DatastoreSegment
on a regular basis if the transaction is held open indefinitely while work happens within it.Troubleshooting
I used the Sheap gem to explore the application's heap. When diffing 2 heap dumps, these are the top 10 sources of retained objects:
That top object type is a
NewRelic::Agent::Transaction::DatastoreSegment
. Inspecting one of those objects below, the GC has marked itold
and thus more likely to be retained over time:This is the path back to the root of the heap showing why it's being retained:
Details of all those objects
Just to summarize what you're seeing:
at_exit
handler, meaning that Thread object will stick around for the lifetime of the application: https://github.com/segmentio/analytics-ruby/blob/9b1dc2ff4c176b526d7fbe17328db501104cb2a3/lib/segment/analytics/client.rb#L29-L33Thread#initialize
to attach instrumentation to all threads: Improved async support and Thread instrumentation by tannalynn · Pull Request #1080 · newrelic/newrelic-ruby-agentAdditional context
It looks like there was a maybe related leak reported and fixed earlier: #1936
I'm sorry about all the heap dump verbosity ❤️
For Maintainers Only or Hero Triaging this bug
Suggested Priority (P1,P2,P3,P4,P5):
Suggested T-Shirt size (S, M, L, XL, Unknown):
The text was updated successfully, but these errors were encountered: