From: Marko Kreen Date: Mon, 3 Oct 2011 19:59:49 +0000 (+0300) Subject: min_pool_size (draft) X-Git-Tag: pgbouncer_1_5_rc1~52 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5098a63d677792216927b8ff18068662196459f4;p=pgbouncer min_pool_size (draft) --- diff --git a/doc/config.txt b/doc/config.txt index 2093428..381e13b 100644 --- a/doc/config.txt +++ b/doc/config.txt @@ -145,6 +145,13 @@ the per-database configuration. Default: 20 +==== min_pool_size ==== + +Minimal pool size. PgBouncer will open this many connections to backend database +after first client connect. Optional, not recommended in most normal setups. + +Default: 0 (disabled) + ==== reserve_pool_size ==== How many additional connections to allow to a pool. 0 disables. @@ -292,7 +299,8 @@ Default: 3600 ==== server_idle_timeout ==== If a server connection has been idle more than this many seconds, and there are -too many connections in the pool, this one can be dropped. [seconds] +too many connections in the pool, this one can be dropped. +If 0 then timeout is disabled. [seconds] Default: 600 diff --git a/include/bouncer.h b/include/bouncer.h index 2773fc8..3ef0fa2 100644 --- a/include/bouncer.h +++ b/include/bouncer.h @@ -342,6 +342,7 @@ extern int cf_listen_backlog; extern int cf_pool_mode; extern int cf_max_client_conn; extern int cf_default_pool_size; +extern int cf_min_pool_size; extern int cf_res_pool_size; extern usec_t cf_res_pool_timeout; diff --git a/src/janitor.c b/src/janitor.c index 327e392..9a7baee 100644 --- a/src/janitor.c +++ b/src/janitor.c @@ -430,6 +430,18 @@ static void check_pool_size(PgPool *pool) break; disconnect_server(server, true, "too many servers in the pool"); many--; + cur--; + } + + /* launch extra connections to satisfy min_pool_size */ + if (cur < cf_min_pool_size && + cur < pool->db->pool_size && + cf_pause_mode == P_NONE && + cf_reboot == 0 && + pool_client_count(pool) > 0) + { + log_debug("Launching new connection to satisfy min_pool_size"); + launch_new_connection(pool); } } diff --git a/src/main.c b/src/main.c index a372e43..25847cd 100644 --- a/src/main.c +++ b/src/main.c @@ -87,6 +87,7 @@ char *cf_auth_file; int cf_max_client_conn; int cf_default_pool_size; +int cf_min_pool_size; int cf_res_pool_size; usec_t cf_res_pool_timeout; @@ -170,6 +171,7 @@ CF_ABS("auth_file", CF_STR, cf_auth_file, 0, "unconfigured_file"), CF_ABS("pool_mode", CF_LOOKUP(pool_mode_map), cf_pool_mode, 0, "session"), CF_ABS("max_client_conn", CF_INT, cf_max_client_conn, 0, "100"), CF_ABS("default_pool_size", CF_INT, cf_default_pool_size, 0, "20"), +CF_ABS("min_pool_size", CF_INT, cf_min_pool_size, 0, "0"), CF_ABS("reserve_pool_size", CF_INT, cf_res_pool_size, 0, "0"), CF_ABS("reserve_pool_timeout", CF_INT, cf_res_pool_timeout, 0, "5"), CF_ABS("syslog", CF_INT, cf_syslog, 0, "0"),