]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
engine: throttle outbound queries only when busy
authorMarek Vavrusa <marek@vavrusa.com>
Mon, 18 Apr 2016 00:29:41 +0000 (17:29 -0700)
committerMarek Vavrusa <marek@vavrusa.com>
Mon, 18 Apr 2016 00:29:41 +0000 (17:29 -0700)
resolver will always attempt to contact upstreams
known to be bad if it's not busy.
this fixes a problem on low-volume resolvers
where a short connection outage could make
resolvers deny resolving queries even after the
connection is restored

daemon/engine.h
daemon/worker.c

index 5e8e12e95e3259955e55a6d33df9aa17713d24cd..7c9379939ae562d49985b20ef3894198783c0411 100644 (file)
@@ -29,6 +29,9 @@
 #ifndef RECVMMSG_BATCH
 #define RECVMMSG_BATCH 4
 #endif
+#ifndef QUERY_RATE_THRESHOLD
+#define QUERY_RATE_THRESHOLD (2 * MP_FREELIST_SIZE) /**< Nr of parallel queries considered as high rate */
+#endif
 
 /*
  * @internal These are forward decls to allow building modules with engine but without Lua.
index 736338d56ec206ad8eee5fd023da477195cb78ec..5bdd7c2a6eae84174b510458d3fb42d3f35dcfee 100644 (file)
@@ -287,6 +287,10 @@ static struct qr_task *qr_task_create(struct worker_ctx *worker, uv_handle_t *ha
        kr_resolve_begin(&task->req, &engine->resolver, answer);
        worker->stats.concurrent += 1;
        worker->stats.queries += 1;
+       /* Throttle outbound queries only when high pressure */
+       if (worker->stats.concurrent < QUERY_RATE_THRESHOLD) {
+               task->req.options |= QUERY_NO_THROTTLE;
+       }
        return task;
 }