From: Wouter Wijngaards Date: Tue, 31 Jul 2018 07:20:15 +0000 (+0000) Subject: - Implement progressive backoff of TCP idle/keepalive timeout. X-Git-Tag: release-1.8.0rc1~76 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3f08cb2a2efa433c814dc7aafb401e617637ccb;p=thirdparty%2Funbound.git - Implement progressive backoff of TCP idle/keepalive timeout. git-svn-id: file:///svn/unbound/trunk@4806 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/doc/unbound.conf.5.in b/doc/unbound.conf.5.in index 550171b78..d09b7bd35 100644 --- a/doc/unbound.conf.5.in +++ b/doc/unbound.conf.5.in @@ -392,10 +392,14 @@ negotiation between Unbound and other servers. .B tcp-idle-timeout: \fI\fR The period Unbound will wait for a query on a TCP connection. If this timeout expires Unbound closes the connection. -This option defaults to 30000 milliseconds. A mimum timeout of -200 milliseconds is observed regardless of the configured timeout. +This option defaults to 30000 milliseconds. When the number of free incoming TCP buffers falls below 50% of the -total number configured, the timeout is reduced to the minimum. +total number configured, the option value used is progressively +reduced, first to 1% of the configured value, then to 0.2% of the +configured value if the number of free buffers falls below 35% of the +total number configured, and finally to 0 if the number of free buffers +falls below 20% of the total number configured. A minimum timeout of +200 milliseconds is observed regardless of the option value used. .TP .B edns-tcp-keepalive: \fI\fR Enable or disable EDNS TCP Keepalive. Default is no. @@ -408,7 +412,11 @@ Unbound sends the timeout value to the client to encourage it to close the connection before the server times out. This option defaults to 120000 milliseconds. When the number of free incoming TCP buffers falls below 50% of -the total number configured, the advertised timeout is reduced to 0. +the total number configured, the advertised timeout is progressively +reduced to 1% of the configured value, then to 0.2% of the configured +value if the number of free buffers falls below 35% of the total number +configured, and finally to 0 if the number of free buffers falls below +20% of the total number configured. A minimum actual timeout of 200 milliseconds is observed regardless of the advertised timeout. .TP diff --git a/util/netevent.c b/util/netevent.c index d5ed0dfc8..fac3b8c4f 100644 --- a/util/netevent.c +++ b/util/netevent.c @@ -730,6 +730,7 @@ comm_point_udp_callback(int fd, short event, void* arg) static void setup_tcp_handler(struct comm_point* c, int fd, int cur, int max) { + int handler_usage; log_assert(c->type == comm_tcp); log_assert(c->fd == -1); sldns_buffer_clear(c->buffer); @@ -742,7 +743,12 @@ setup_tcp_handler(struct comm_point* c, int fd, int cur, int max) /* if more than half the tcp handlers are in use, use a shorter * timeout for this TCP connection, we need to make space for * other connections to be able to get attention */ - if(cur > max/2) + handler_usage = (cur * 100) / max; + if(handler_usage > 50 && handler_usage <= 65) + c->tcp_timeout_msec /= 100; + else if (handler_usage > 65 && handler_usage <= 80) + c->tcp_timeout_msec /= 500; + else if (handler_usage > 80) c->tcp_timeout_msec = 0; comm_point_start_listening(c, fd, c->tcp_timeout_msec < TCP_QUERY_TIMEOUT_MINIMUM