]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- If more than half of tcp connections are in use, a shorter timeout
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Wed, 15 Jun 2016 14:41:23 +0000 (14:41 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Wed, 15 Jun 2016 14:41:23 +0000 (14:41 +0000)
  is used (200 msec, vs 2 minutes) to pressure tcp for new connects.

git-svn-id: file:///svn/unbound/trunk@3794 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
util/netevent.c
util/netevent.h

index a46715a899b6a8249cfb0252a8fc97c3dd3210a7..135a92fe415d2164acba36a517b30bf9d25c077f 100644 (file)
@@ -1,5 +1,7 @@
 15 June 2016: Wouter
        - TCP_TIMEOUT is specified in milliseconds.
+       - If more than half of tcp connections are in use, a shorter timeout
+         is used (200 msec, vs 2 minutes) to pressure tcp for new connects.
 
 14 June 2016: Ralph
        - QNAME minimisation unit test for dropped QTYPE=A queries.
index 03a752db3ffeddbeaa9b2f7cbd03ab83ff243b75..f0918ecd6d63d2995fa2e32776b6bdf98b3c50a8 100644 (file)
@@ -82,6 +82,8 @@
 
 /** The TCP reading or writing query timeout in milliseconds */
 #define TCP_QUERY_TIMEOUT 120000
+/** The TCP timeout in msec for fast queries, above half are used */
+#define TCP_QUERY_TIMEOUT_FAST 200
 
 #ifndef NONBLOCKING_IS_BROKEN
 /** number of UDP reads to perform per read indication from select */
@@ -710,14 +712,20 @@ comm_point_udp_callback(int fd, short event, void* arg)
 
 /** Use a new tcp handler for new query fd, set to read query */
 static void
-setup_tcp_handler(struct comm_point* c, int fd) 
+setup_tcp_handler(struct comm_point* c, int fd, int cur, int max
 {
        log_assert(c->type == comm_tcp);
        log_assert(c->fd == -1);
        sldns_buffer_clear(c->buffer);
        c->tcp_is_reading = 1;
        c->tcp_byte_count = 0;
-       comm_point_start_listening(c, fd, TCP_QUERY_TIMEOUT);
+       c->tcp_timeout_msec = TCP_QUERY_TIMEOUT;
+       /* 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)
+               c->tcp_timeout_msec = TCP_QUERY_TIMEOUT_FAST;
+       comm_point_start_listening(c, fd, c->tcp_timeout_msec);
 }
 
 void comm_base_handle_slow_accept(int ATTR_UNUSED(fd),
@@ -886,7 +894,7 @@ comm_point_tcp_accept_callback(int fd, short event, void* arg)
                /* stop accepting incoming queries for now. */
                comm_point_stop_listening(c);
        }
-       setup_tcp_handler(c_hdl, new_fd);
+       setup_tcp_handler(c_hdl, new_fd, c->cur_tcp_count, c->max_tcp_count);
 }
 
 /** Make tcp handler free for next assignment */
@@ -940,7 +948,7 @@ tcp_callback_reader(struct comm_point* c)
                comm_point_stop_listening(c);
        fptr_ok(fptr_whitelist_comm_point(c->callback));
        if( (*c->callback)(c, c->cb_arg, NETEVENT_NOERROR, &c->repinfo) ) {
-               comm_point_start_listening(c, -1, TCP_QUERY_TIMEOUT);
+               comm_point_start_listening(c, -1, c->tcp_timeout_msec);
        }
 }
 
@@ -1983,7 +1991,8 @@ comm_point_send_reply(struct comm_reply *repinfo)
                        dt_msg_send_client_response(repinfo->c->tcp_parent->dtenv,
                        &repinfo->addr, repinfo->c->type, repinfo->c->buffer);
 #endif
-               comm_point_start_listening(repinfo->c, -1, TCP_QUERY_TIMEOUT);
+               comm_point_start_listening(repinfo->c, -1,
+                       repinfo->c->tcp_timeout_msec);
        }
 }
 
index b902ab3be2058b41daf6b0c0c802e895b6a1e019..60121fe77e9de0e0aa65b620ddda66904d862680 100644 (file)
@@ -225,6 +225,9 @@ struct comm_point {
            So that when that is done the callback is called. */
        int tcp_do_toggle_rw;
 
+       /** timeout in msec for TCP wait times for this connection */
+       int tcp_timeout_msec;
+
        /** if set, checks for pending error from nonblocking connect() call.*/
        int tcp_check_nb_connect;