-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Memory leak when using with Solid Cable #59
Comments
Hi @fdaugs and thank you for spotting and reporting this! For that reason, I'm all for skipping I only have one question though: I believe |
Hi @iMacTia, thanks for your response! def valid?(event)
return false if event.payload[:name] == 'SCHEMA' || event.payload[:name].include?('SolidCable::')
# Only store SQL events if `event.duration` is greater than the configured +min_duration+
# No need to check if +min_duration+ is present before as it defaults to 0
return false if event.duration.to_f.round(2) < Lograge::Sql.min_duration_ms.to_f
true
end But this will lead to a tight coupling to the solid_cable gem. Maybe it would be better to make this an configurable option as array or even a lambda with "SolidCable::" included in the default options like so: def valid?(event)
return false if event.payload[:name] === Regexp.union(Rails.application.config.lograge_sql.invalid_query_names) # Default would be ['SCHEMA', 'SolidCable::']
# Only store SQL events if `event.duration` is greater than the configured +min_duration+
# No need to check if +min_duration+ is present before as it defaults to 0
return false if event.duration.to_f.round(2) < Lograge::Sql.min_duration_ms.to_f
true
end This on the other hand is not really transparent and potentially confusing, because in surfaces internal implementation details and there already is an option named |
Well, I just found out that Lograge officially added support for ActionCable, so I guess my suggestion to just disable I'd be inclined to go with your suggestion and add a configurable denylist for payload names. Then in |
We're using lograge version 0.14.0. Which is the current version. I'm a bit confused about your first sentence :D Just to clear things up:
I think in terms of a solution we were pretty close. I will open a PR and implement the array of regexp. We can discuss the details there. |
Ah I guess this is where I was getting confused:
What I originally understood was that solid cable queries where being stored in the thread-memory cache and never dumped, but that was surprising since Lograge supports ActionCable, meaning after a successful websocket message it should log and therefore empty the thread-memory cache. However based on your latest message I now suspect that works correctly, but the issue is that the constant polling causes queries to be stored and if you don't have a websocket request for a while these are never cleared? Anyway, happy to proceed as we discussed above, this was just my desire to get a better understanding of the problem 🙂 |
I'm also not 100% sure what happens here but I think that queries of solid cable even originate outside of the context of the methods lograge subscribes to. As of my understanding solid cable works like this: If you broadcast a message then lograge will log these (because |
Summary
If you use lograge-sql together with solid cable there is a memory leak, because the queries that solid cable makes are stored by lograge-sql, but never logged and thus retained in memory. Since solid will be the default action cable adapter from Rails 8 onwards, I think it would be best to filter these queries by default.
Details
After deploying solid cable wie noticed a constant memory increase:
Inspection of the heap showed that a significant amount of memory was being used by this gem:
The retained strings in the heap snapshot are actually all polling queries by solid cable. I think what happens is, that these queries are stored here, but never get cleared because they are outside of a request context.
Possible solutions
I'm happy to open a PR once we've agreed on how to proceed!
The text was updated successfully, but these errors were encountered: