From 20a15836619be6c195402a26cb04dda974c4e565 Mon Sep 17 00:00:00 2001 From: Alessio Podda Date: Sat, 30 Aug 2025 09:21:20 +0200 Subject: [PATCH] Lazily allocate fetch counter The counter in ns_client_t is used to track the maximum number of recursions in the resolver, but it is created unconditionally when starting the client and deallocated when resetting it. This commit defers the allocation of the counter till recursion needs to actually happen, speeding up authoritative workloads in perflab by 1.5~2%. --- lib/ns/query.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/ns/query.c b/lib/ns/query.c index 60e748174dc..f3b68d2498d 100644 --- a/lib/ns/query.c +++ b/lib/ns/query.c @@ -863,6 +863,18 @@ query_cleanup(ns_client_t *client) { query_reset(client, false); } +static void +maybe_init_fetch_counter(ns_client_t *client) { + if (client->query.qc == NULL) { + /* + * Start global outgoing query count. + */ + isc_counter_create(client->manager->mctx, + client->inner.view->max_queries, + &client->query.qc); + } +} + void ns_query_free(ns_client_t *client) { REQUIRE(NS_CLIENT_VALID(client)); @@ -2795,6 +2807,7 @@ fetch_and_forget(ns_client_t *client, dns_name_t *qname, dns_rdatatype_t qtype, fetchp = &client->query.recursions[recursion_type].fetch; isc_nmhandle_attach(client->inner.handle, handlep); + maybe_init_fetch_counter(client); result = dns_resolver_createfetch( client->inner.view->resolver, qname, qtype, NULL, NULL, NULL, peeraddr, client->message->id, options, 0, NULL, @@ -6292,6 +6305,7 @@ ns_query_recurse(ns_client_t *client, dns_rdatatype_t qtype, dns_name_t *qname, isc_nmhandle_attach(client->inner.handle, &HANDLE_RECTYPE_NORMAL(client)); + maybe_init_fetch_counter(client); result = dns_resolver_createfetch( client->inner.view->resolver, qname, qtype, qdomain, nameservers, NULL, peeraddr, client->message->id, @@ -11796,10 +11810,10 @@ ns_query_start(ns_client_t *client, isc_nmhandle_t *handle) { } /* - * Start global outgoing query count. + * Query counter will be started lazily, as it is unneeded for auth + * queries. */ - isc_counter_create(client->manager->mctx, - client->inner.view->max_queries, &client->query.qc); + client->query.qc = NULL; query_setup(client, qtype); } -- 2.47.3