独角兽不会关闭数据库连接 [英] Unicorn do not close DB connections

查看:96
本文介绍了独角兽不会关闭数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails 3.2 + unicorn + postgres DB,我有一个问题-unicorn如何处理DB连接?

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

我的理解:


  1. unicorn主进程派生X子进程。

  2. 每个子进程设置数据库连接–在before_fork中关闭,在after_fork中建立连接。

  3. 我们在每个进程中使用连接(如果我们使用Rails DB连接池化后,我们为每个进程创建Y(来自database.yml)数据库连接)-即,如果进程正常运行(直到我们不杀死它,它总是起作用),我们保持连接打开,并且每个Web请求都使用相同的连接(在after_fork中打开) )。

  4. 打开的连接将在postgres(或任何其他数据库)中显示为空闲或活动。

  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 ?

推荐答案

是的,您是对的。
如果在unicorn.conf中设置 worker_processes 5,并在database.yml中设置 pool:4,则将创建d 20与数据库的连接。

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.

这篇关于独角兽不会关闭数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆