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

ConnectionPool: idle_timeout of 0 causes 100% and busy looping #438

Closed
tisba opened this issue Aug 10, 2018 · 5 comments · Fixed by #448
Closed

ConnectionPool: idle_timeout of 0 causes 100% and busy looping #438

tisba opened this issue Aug 10, 2018 · 5 comments · Fixed by #448

Comments

@tisba
Copy link
Contributor

tisba commented Aug 10, 2018

I recently noticed that our sidekiq is running at 100% CPU (see sidekiq/sidekiq#3918). We are using sshkit in our sidekiq workers.

We were using:

SSHKit::Backend::Netssh.pool.idle_timeout = 0

Which causes a busy loop in ConnectionPool#run_eviction_loop as [idle_timeout, 5].min will be 0:

def run_eviction_loop
loop do
process_deferred_close
# Periodically sweep all Caches to evict stale connections
sleep([idle_timeout, 5].min)
caches.values.each(&:evict)
end
end

Also, according to ConnectionPools documentation, idle_timeout can also be false or nil which will actually cause an exception ([nil, 5].min will raise).

I'm happy to propose a fix, but I'd like to have guidance how. My proposal would be to impose a lower limit on run_eviction_loop loop frequency like at most once every 5 seconds. On the other hand I don't understand why the eviction loop is required at all if connection caching is disabled (idle_timeout = 0, ConnectionPool#cache_enabled? -> false).

As far as I can tell the code was heavily changed/rewritten with #328 by @mattbrictson. Maybe he can provide some guidance?

In any case, we can work with increasing the idle_timeout to >0 for now. I still like to have this problem fixed though.

@mikegee
Copy link

mikegee commented Aug 10, 2018

No help for the underlying issue, but I don't think you would have seen this problem if capistrano weren't loaded in the Sidekiq process. The docs say to use require: false in the Gemfile. https://github.com/capistrano/capistrano#install-the-capistrano-gem

@tisba
Copy link
Contributor Author

tisba commented Aug 10, 2018

To clarify things: We do not load capistrano in sidekiq, only sshkit. We use sshkit directly to manage servers.

@tisba
Copy link
Contributor Author

tisba commented Jan 28, 2019

-bump-

I'm happy to provide a patch to the problem (outlined in the description above). Is this a viable way to solve this issue?

@leehambley
Copy link
Member

Hi @tisba if you can provide a patch it would be most welcome. We are still actively maintaining this library when community patches are provided, but both @mattbrictson and myself are not spending a lot of time on bug fixes ourselves.

Please do submit a fix, if you can, and the doc issue:

Also, according to ConnectionPools documentation, idle_timeout can also be false or nil which will actually cause an exception ([nil, 5].min will raise).

would be well worth addressing as part of your submission. Thanks indeed.

ps. might I ask what's you need for disabling connection pooling all together? (have you deferred control to a controlmaster at the system level?

@tisba
Copy link
Contributor Author

tisba commented Jan 28, 2019

We are using sshkit via capistrano, but also stand-alone (mostly) inside sidekiq jobs. We talk to many hosts but most operations are one-off anyway, so there is no real need to pool connections. I don't recall exactly why we tried to disable connection pooling though; not sure if we had "a real issue", not only "we don't need it".

Anyway it caused a lot of searching to find out why we kept one core at 100% utilisation and it should be rather simple to fix. I'll try to come up with a patch and we'll see :)

💕 for maintaining sshkit. This gem was really helpful to us!

leehambley added a commit that referenced this issue Jan 30, 2019
Fix Disabling of Connection Pool
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 a pull request may close this issue.

3 participants