From: Vadim Fedorenko Date: Mon, 17 Apr 2023 14:02:13 +0000 (-0700) Subject: stats: add counter for timed out queries X-Git-Tag: release-1.18.0rc1~24^2~51^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e577ab105e9741d861669827b743c3fbb854c5d2;p=thirdparty%2Funbound.git stats: add counter for timed out queries Add counter `num_queries_timed_out` meaning queries that were sitting in the socket queue and waiting to being processed too long. There is no reason to process such queries, so let's drop it in the very beginning of the pipeline. Signed-off-by: Vadim Fedorenko --- diff --git a/daemon/remote.c b/daemon/remote.c index 1d0a58714..d8a3a6caf 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -679,6 +679,8 @@ print_stats(RES* ssl, const char* nm, struct ub_stats_info* s) (unsigned long)s->svr.num_queries_missed_cache)) return 0; if(!ssl_printf(ssl, "%s.num.prefetch"SQ"%lu\n", nm, (unsigned long)s->svr.num_queries_prefetch)) return 0; + if(!ssl_printf(ssl, "%s.num.queries_timed_out"SQ"%lu\n", nm, + (unsigned long)s->svr.num_queries_timed_out)) return 0; if(!ssl_printf(ssl, "%s.num.expired"SQ"%lu\n", nm, (unsigned long)s->svr.ans_expired)) return 0; if(!ssl_printf(ssl, "%s.num.recursivereplies"SQ"%lu\n", nm, diff --git a/daemon/stats.c b/daemon/stats.c index 4c7fcbe5a..38f4597b3 100644 --- a/daemon/stats.c +++ b/daemon/stats.c @@ -432,6 +432,7 @@ void server_stats_add(struct ub_stats_info* total, struct ub_stats_info* a) total->svr.num_queries_ip_ratelimited += a->svr.num_queries_ip_ratelimited; total->svr.num_queries_missed_cache += a->svr.num_queries_missed_cache; total->svr.num_queries_prefetch += a->svr.num_queries_prefetch; + total->svr.num_queries_timed_out += a->svr.num_queries_timed_out; total->svr.sum_query_list_size += a->svr.sum_query_list_size; total->svr.ans_expired += a->svr.ans_expired; #ifdef USE_DNSCRYPT diff --git a/daemon/worker.c b/daemon/worker.c index 85709af6e..63b8678e3 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -1296,6 +1296,16 @@ worker_handle_request(struct comm_point* c, void* arg, int error, verbose(VERB_ALGO, "handle request called with err=%d", error); return 0; } + + if (worker->env.cfg->sock_queue_timeout && timeval_isset(c->recv_tv)) { + c->recv_tv.tv_sec += worker->env.cfg->sock_queue_timeout; + if (timeval_smaller(c->recv_tv, worker->env.now_tv)) { + /* count and drop queries that were sitting in the socket queue too long */ + worker->stats.num_queries_timed_out++; + return 0; + } + } + #ifdef USE_DNSCRYPT repinfo->max_udp_size = worker->daemon->cfg->max_udp_size; if(!dnsc_handle_curved_request(worker->daemon->dnscenv, repinfo)) { diff --git a/libunbound/unbound.h b/libunbound/unbound.h index f65cc2c58..f83a38f8f 100644 --- a/libunbound/unbound.h +++ b/libunbound/unbound.h @@ -699,6 +699,8 @@ struct ub_server_stats { long long num_queries_missed_cache; /** number of prefetch queries - cachehits with prefetch */ long long num_queries_prefetch; + /** number of queries which are too late to process */ + long long num_queries_timed_out; /** * Sum of the querylistsize of the worker for diff --git a/smallapp/unbound-control.c b/smallapp/unbound-control.c index 89cb16b96..d5f124b49 100644 --- a/smallapp/unbound-control.c +++ b/smallapp/unbound-control.c @@ -208,6 +208,7 @@ static void pr_stats(const char* nm, struct ub_stats_info* s) s->svr.num_queries - s->svr.num_queries_missed_cache); PR_UL_NM("num.cachemiss", s->svr.num_queries_missed_cache); PR_UL_NM("num.prefetch", s->svr.num_queries_prefetch); + PR_UL_NM("num.queries_timed_out", s->svr.num_queries_timed_out); PR_UL_NM("num.expired", s->svr.ans_expired); PR_UL_NM("num.recursivereplies", s->mesh_replies_sent); #ifdef USE_DNSCRYPT