Domanda

I am currently having a problem with database connections after a Capistrano deploy. On the database server it seems like unicorn does not sever the previous connections and it just keeps adding on top of the old ones. I am doing a preload true, and I also have octopus gem installed as well if that matters. I am not too sure who is to blame for this. I have pasted my unicorn config for the part that matters. Any help is appreciated!

before_fork do |server, worker|
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.connection.disconnect!
  end
  old_pid = "/tmp/unicorn.my_app_name.pid.oldbin"
  if File.exists?(old_pid) && server.pid != old_pid
    begin
      Process.kill("QUIT", File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
    end
  end
end

after_fork do |server, worker|

  ActiveRecord::Base.connection_proxy.instance_variable_get(:@shards).each {|k,v| v.clear_reloadable_connections! }
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.establish_connection
  end

  if Process.ppid > 1 # Not the daemon
  child_pid = server.config[:pid].sub(".pid", ".#{worker.nr}.pid")
  File.open(child_pid, "wb") {|f| f << Process.pid }
  end
end

1 "ps aux"

È stato utile?

Soluzione

Your "New Theory" is correct. 2 workers with 5 connections will result in 10 total. Answer is here - Unicorn do not close DB connections

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top