]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Lazily allocate fetch counter
authorAlessio Podda <alessio@isc.org>
Sat, 30 Aug 2025 07:21:20 +0000 (09:21 +0200)
committerAlessio Podda <alessio@isc.org>
Tue, 2 Sep 2025 09:22:28 +0000 (11:22 +0200)
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

index 60e748174dcd086db869c805a433c3476ebf3e5d..f3b68d2498df43719c2356f9e34992a4aca6b214 100644 (file)
@@ -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);
 }