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

Automatically manage known-common DB connections #135

Open
nevans opened this issue Oct 8, 2015 · 1 comment
Open

Automatically manage known-common DB connections #135

nevans opened this issue Oct 8, 2015 · 1 comment

Comments

@nevans
Copy link
Collaborator

nevans commented Oct 8, 2015

Specifically, check for defined? ActiveRecord::Base and Resque.redis. Then we can remove those bits from the necessary config for probably 95% of users (and remove one of the most common misconfigurations). Any other connections will still need to be managed manually (and we will still need to document this in the README).

We should do a quick search for open TCP sockets and issue a warning if any of them were shared from the master. e.g.

# helper
def open_tcp_sockets
  return [] if configured_to_ignore_open_socket_warnings?
  ObjectSpace.each_object(TCPSocket).each_with_object({}) do |f,h|
    fd = f.fileno rescue nil  
    h[fd] = f if fd && (!f.closed? rescue nil)
end

# immediately after fork
tcp_from_master = open_tcp_sockets

# after running the after fork hooks
current_open_tcp_fds = open_tcp_socket_fds.keys
(tcp_from_master.keys & current_open_tcp_fds).each do |fd|
  socket = tcp_from_master[fd]
  unless configured_to_ignore_warning_for?(socket)
    print_warning_for(socket)
  end
end

We could also extend this to open File, IO, UDPSocket, etc, but those are more likely to be legitimately shared between master/worker.

nevans added a commit that referenced this issue Oct 28, 2015
Intended to be wrapped by `Throttled` config loader.

n.b. if you use this, you will need to reset the redis configuration in your
`after_prefork` hook. (Until #135 handles it automatically.)
nevans added a commit that referenced this issue Oct 28, 2015
Intended to be wrapped by `Throttled` config loader.

n.b. if you use this, you will need to reset the redis configuration in your
`after_prefork` hook. (Until #135 handles it automatically.)
@codyrobbins
Copy link

This would be an awesome addition.

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