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
    
  • 相关阅读:
    poj3294 Life Forms(后缀数组)
    1628. White Streaks(STL)
    1523. K-inversions(K逆序对)
    1890. Money out of Thin Air(线段树 dfs转换区间)
    1350. Canteen(map)
    1521. War Games 2(线段树解约瑟夫)
    1003. Parity(并查集)
    1470. UFOs(三维树状数组)
    1471. Tree(LCA)
    1494. Monobilliards(栈)
  • 原文地址:https://www.cnblogs.com/lottu/p/14297868.html
Copyright © 2011-2022 走看看