]> granicus.if.org Git - pgbouncer/commitdiff
Introduce a new configuration setting: query_wait_timeout
authorMarko Kreen <markokr@gmail.com>
Fri, 12 Feb 2010 19:05:04 +0000 (19:05 +0000)
committerMarko Kreen <markokr@gmail.com>
Fri, 12 Feb 2010 19:05:04 +0000 (19:05 +0000)
If a query spends more than query_wait_timeout seconds waiting
it is disconnected. This prevents unresponsive servers from
wasting resources.

Patch by Martin Pihlak

doc/config.txt
etc/pgbouncer.ini
include/bouncer.h
src/janitor.c
src/main.c

index 927aa53e10988a6c81a2003f2e08d5e165e3864d..f6aee6bff9dbba102396879d9a4f5b75d6e03dc5 100644 (file)
@@ -315,6 +315,14 @@ problems. [seconds]
 
 Default: 0 (disabled)
 
+==== query_wait_timeout ====
+
+Maximum time queries are allowed to spend waiting for execution. If the query
+is not assigned to a server during that time, the client is disconnected. This
+is used to prevent unresponsive servers from grabbing up connections. [seconds]
+
+Default: 0 (disabled)
+
 ==== client_idle_timeout ====
 
 Client connections idling longer than this many seconds are closed. This should 
index e282069610c3333d10d961fac8522e31ab572b16..685f1cf61c38f4f1cffc861e4428b1314a5d8c02 100644 (file)
@@ -138,6 +138,11 @@ log_pooler_errors = 1
 ;; _not_ as statement_timeout. (default: 0)
 ;query_timeout = 0
 
+;; Dangerous.  Client connection is closed if the query is not assigned
+;; to a server in this time.  Should be used to limit the number of queued
+;; queries in case of a database or network failure. (default: 0)
+;query_wait_timeout = 0
+
 ;; Dangerous.  Client connection is closed if no activity in this time.
 ;; Should be used to survive network problems. (default: 0)
 ;client_idle_timeout = 0
index 7a874d414cb8b6b076294c63e8787523875d1c0e..fdeaa1188111f4f18c7dd9cbe51c885f132660f9 100644 (file)
@@ -328,6 +328,7 @@ extern usec_t cf_server_check_delay;
 extern usec_t cf_server_connect_timeout;
 extern usec_t cf_server_login_retry;
 extern usec_t cf_query_timeout;
+extern usec_t cf_query_wait_timeout;
 extern usec_t cf_client_idle_timeout;
 extern usec_t cf_client_login_timeout;
 extern int cf_server_round_robin;
index 5da7e6834297c3b8c292f5a2079bc0fa3741dda1..842ff980b73b496598f5d9db78b7c7e0d036671d 100644 (file)
@@ -324,8 +324,8 @@ static void pool_client_maint(PgPool *pool)
                }
        }
 
-       /* force client_query_timeout */
-       if (cf_query_timeout > 0) {
+       /* force timeouts for waiting queries */
+       if (cf_query_timeout > 0 || cf_query_wait_timeout > 0) {
                statlist_for_each_safe(item, &pool->waiting_client_list, tmp) {
                        client = container_of(item, PgSocket, head);
                        Assert(client->state == CL_WAITING);
@@ -334,8 +334,11 @@ static void pool_client_maint(PgPool *pool)
                                //log_warning("query_start==0");
                        } else
                                age = now - client->query_start;
-                       if (age > cf_query_timeout)
+
+                       if (cf_query_timeout > 0 && age > cf_query_timeout)
                                disconnect_client(client, true, "query_timeout");
+                       else if (cf_query_wait_timeout > 0 && age > cf_query_wait_timeout)
+                               disconnect_client(client, true, "query_wait_timeout");
                }
        }
 
index fa20c2d4e1d220b4aa5bbfbeca29b8f7a300e94a..33668bc145fce99375207122a2191530ffb3228e 100644 (file)
@@ -110,6 +110,7 @@ usec_t cf_server_idle_timeout = 10*60*USEC;
 usec_t cf_server_connect_timeout = 15*USEC;
 usec_t cf_server_login_retry = 15*USEC;
 usec_t cf_query_timeout = 0*USEC;
+usec_t cf_query_wait_timeout = 0*USEC;
 usec_t cf_client_idle_timeout = 0*USEC;
 usec_t cf_client_login_timeout = 60*USEC;
 usec_t cf_suspend_timeout = 10*USEC;
@@ -163,6 +164,7 @@ ConfElem bouncer_params[] = {
 {"server_check_query", true, CF_STR, &cf_server_check_query},
 {"server_check_delay", true, CF_TIME, &cf_server_check_delay},
 {"query_timeout",      true, CF_TIME, &cf_query_timeout},
+{"query_wait_timeout", true, CF_TIME, &cf_query_wait_timeout},
 {"client_idle_timeout",        true, CF_TIME, &cf_client_idle_timeout},
 {"client_login_timeout",true, CF_TIME, &cf_client_login_timeout},
 {"server_lifetime",    true, CF_TIME, &cf_server_lifetime},