在 Rails 中禁用连接池以使用 PgBouncer

编程入门 行业动态 更新时间:2024-10-25 16:21:30
本文介绍了在 Rails 中禁用连接池以使用 PgBouncer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们有一个访问大型 PostgreSQL 数据库的 Ruby on Rails 4.2.8 项目.我们将使用 PgBouncer 添加一个用于连接池的新服务器.

We have a Ruby on Rails 4.2.8 project that accesses a large PostgreSQL database. We are going to add a new server for connection pooling using PgBouncer.

既然 PgBouncer 会处理 db 连接池,我们是否需要关闭 Rails 自动连接池?我们的 database.yml 中没有配置任何内容,因此我认为使用的是默认值(池)5.

Since PgBouncer will handle the db connection pooling, would we need to turn off Rails automatic connection pooling? We do not have anything configured in our database.yml, so I would think that the default (Pool) of 5 is being used.

  • 添加 PgBouncer 是否意味着我们应该关闭 Rails连接池?
  • 如果是这样,它是如何工作的,我们是否只需设置 Pool到 database.yml 中的 0?
  • 谢谢

    推荐答案

    TLDR;不要改变任何东西

    TLDR; don't change anything

    rails 中的池化与 PGBouncer 中的池化不同.rails 连接池是该进程中任何线程可用的一组连接,通常只有 1 个. rails 池中的每个连接都将连接到您的 postgres 数据库或 PGBouncer,如果它位于 postgres 前面.在大型 rails 应用程序中,您将在每台服务器上运行多个 rails 进程,并在负载均衡器后面运行多个服务器.像这样:

    The pooling in rails is different than the pooling in PGBouncer. The rails connection pool is a group of connections available to any thread within that process, usually just 1. Each connection in your rails pool will have a connection to your postgres database, or PGBouncer if that's sitting in front of postgres. In a large rails app, you'll run multiple rails processes on every server and multiple servers behind a load balancer. Something like this:

    如果没有 PGBouncer,与 postgres 的每个连接都会创建一个新的 postgres 进程.在规模上,您需要限制运行的 postgres 进程的数量,这样您就不会最大化 CPU 和内存.PGBouncer 汇集来自所有进程和所有服务器的所有 rails 池的连接,并在它们之间高效切换.

    Without PGBouncer, every connection to postgres creates a new postgres process. At scale you'll want to limit the number of postgres processes that run so you don't max out CPU and memory. PGBouncer pools connections from all of your rails pools across all processes and all servers, and efficiently switches between them.

    更多推荐

    在 Rails 中禁用连接池以使用 PgBouncer

    本文发布于:2023-10-17 10:23:03,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1500636.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:连接池   Rails   PgBouncer

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!