]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Implement progressive backoff of TCP idle/keepalive timeout.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 31 Jul 2018 07:20:15 +0000 (07:20 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 31 Jul 2018 07:20:15 +0000 (07:20 +0000)
git-svn-id: file:///svn/unbound/trunk@4806 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/unbound.conf.5.in
util/netevent.c

index 550171b78a2cf8a709e3826e10a07d313b0ae696..d09b7bd353ddb417a9e43e847cee90d506d70b69 100644 (file)
@@ -392,10 +392,14 @@ negotiation between Unbound and other servers.
 .B tcp-idle-timeout: \fI<msec>\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<yes or no>\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
index d5ed0dfc8d57e1e9683408c428b95524eb8516e5..fac3b8c4f1d12979a9a156b735b99ce5f2c19ba9 100644 (file)
@@ -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