zoukankan      html  css  js  c++  java
  • 为什么你的pgbouncer连接这么慢

    在PostgreSQL中;说得连接池,立马想到pgbouncer。pgbouncer 的目标是降低因为新建到 PostgreSQL/Greenplum 的连接而导致的性能损失。

    在项目中;DBA会劝开发人员使用连接池。这样可以控制连接数。也避免反复建立连接带来的性能消耗。对连接池的优点。这篇文章讲解比较好。

    但是在开发人员在使用连接池的过程中,一般开发人员那边也有自己的jdbc的连接池。在启动项目的过程;于是出现下面这段对话

    开发人员:这项目启动好慢;原因是连接数据库好慢。

    DBA:这项目启动时申请多少数据库连接。

    开发人员:没多少;也就50。峰值不会超过400。

    DBA:直连数据库会慢吗?

    开发人员:不会,启动很快。

    连接池pgbouncer是一个针对PostgreSQL数据库的轻量级连接池。但是单线程的。我观察在启动的过程中;连接数是一条一条增加的。并不是你需要多少就给多少

    [postgres@bogon pgbouncer]$ ps -ef | grep postgres | grep 127 |wc -l
    44
    [postgres@bogon pgbouncer]$ ps -ef | grep postgres | grep 127 |wc -l
    45
    [postgres@bogon pgbouncer]$ ps -ef | grep postgres | grep 127 |wc -l
    46
    [postgres@bogon pgbouncer]$ ps -ef | grep postgres | grep 127 |wc -l
    47
    [postgres@bogon pgbouncer]$ ps -ef | grep postgres | grep 127 |wc -l
    47
    [postgres@bogon pgbouncer]$ ps -ef | grep postgres | grep 127 |wc -l
    49
    [postgres@bogon pgbouncer]$ ps -ef | grep postgres | grep 127 |wc -l
    49
    [postgres@bogon pgbouncer]$ ps -ef | grep postgres | grep 127 |wc -l
    49
    [postgres@bogon pgbouncer]$ ps -ef | grep postgres | grep 127 |wc -l
    49
    [postgres@bogon pgbouncer]$ ps -ef | grep postgres | grep 127 |wc -l
    50
    

    若是这样的话;那我们知道为什么项目通过pgbouncer启动很慢了。
    若我们提前申请一批连接资源做为idle。等项目启动的时候直接可以用不久解决了,说干就干。

    在pgbouncer的配置文件中设置

    min_pool_size = 50
    
  • 相关阅读:
    【分区】使用 MBR 分区表分区并格式化
    微信小程序公司开发前必读
    Delphi 经典书籍
    sybase 通过select into创建新表
    sybase 创建触发器
    delphi 判断exe重复执行
    git 的诞生
    git 常用命令
    mvn spring-boot:run运行不了的解决办法
    git 提交代码
  • 原文地址:https://www.cnblogs.com/lottu/p/14297868.html
Copyright © 2011-2022 走看看