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

InfluxDB::Client is never garbage collected #259

Open
dgutov opened this issue May 20, 2022 · 5 comments
Open

InfluxDB::Client is never garbage collected #259

dgutov opened this issue May 20, 2022 · 5 comments

Comments

@dgutov
Copy link

dgutov commented May 20, 2022

I'm guessing that happens (or doesn't happen) because of the at_exit block inside its constructor.

I think it should either be reworked to use just one global at_exit somewhere on the module level, or the docs should clarify somewhere that one should create one client instance globally. That is, to avoid creating instances dynamically per request (in a web app).

I also haven't managed to find any info as to whether the client is thread-safe, or we should use it through a connection pool.

@dgutov
Copy link
Author

dgutov commented May 20, 2022

For some evidence:

require 'influxdb'
require 'memory_profiler'
MemoryProfiler.report { InfluxDB::Client.new }.pretty_print

=>

...
retained memory by class
-----------------------------------
       232  InfluxDB::Config
        80  Proc
        76  Thread::Queue
        40  Hash
        40  InfluxDB::Client

retained objects by gem
-----------------------------------
         3  influxdb-0.8.1
         2  other

retained objects by file
-----------------------------------
         2  (irb)
         2  /home/dgutov/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/influxdb-0.8.1/lib/influxdb/client.rb
         1  /home/dgutov/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/influxdb-0.8.1/lib/influxdb/config.rb

retained objects by location
-----------------------------------
         2  (irb):5
         1  /home/dgutov/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/influxdb-0.8.1/lib/influxdb/client.rb:54
         1  /home/dgutov/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/influxdb-0.8.1/lib/influxdb/client.rb:58
         1  /home/dgutov/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/influxdb-0.8.1/lib/influxdb/config.rb:130

retained objects by class
-----------------------------------
         1  Hash
         1  InfluxDB::Client
         1  InfluxDB::Config
         1  Proc
         1  Thread::Queue

@hogaur
Copy link
Contributor

hogaur commented Dec 21, 2022

Thanks for reporting this issue. Have you looked into it further? I assume it is a hot issue and lies on the critical path.

@dgutov
Copy link
Author

dgutov commented Dec 22, 2022

It wasn't that hot, but if the client is instantiated again and again, that did contribute to unbounded memory growth.

We ultimately went with either with a pool or with a global client instance. I can't remember which of these two, sorry.

@hogaur
Copy link
Contributor

hogaur commented Dec 22, 2022

Hot or not, it doesn't matter if it doesn't occur now. Thanks.

@dgutov
Copy link
Author

dgutov commented Dec 22, 2022

It does occur. Be careful not to instantiate a new instance of InfluxDb::Client in your web request handlers.

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

No branches or pull requests

2 participants