Unicorn do not close DB connections

人走茶凉 提交于 2020-01-13 00:52:08

问题


I am using rails 3.2 + unicorn + postgres DB and i have a question - how does unicorn handle DB connections ?

How I understand:

  1. unicorn master process forks X child process.
  2. each child process setup DB connection– close in before_fork, establish connection in after_fork.
  3. we use connection per process(if we use rails DB connection pooling, we create Y(from database.yml) DB connections per process) - i.e. If process is working(It always works until we not kill it) we keep connection opened and every web request use the same connection(that was opened in after_fork).
  4. opened connections will be shown in postgres(or any other DB) as idle or active.

Is it correct or I missed something ?


回答1:


Yes you are right. If you set "worker_processes 5" in unicorn.conf, and "pool: 4" in database.yml, will be create d 20 connections to database.




回答2:


i wrote to Eric Wong he is founder of unicorn gem, he confirmed that it's correct.



来源:https://stackoverflow.com/questions/15661482/unicorn-do-not-close-db-connections

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!