From: Robert Edmonds Date: Tue, 21 Apr 2026 21:22:32 +0000 (-0400) Subject: dnsdist: Add per-backend `max_udp_outstanding` YAML config setting X-Git-Tag: auth-5.1.0-beta1~12^2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=8e8a0e306054d2202c58eccffbd93b4a5d62701c;p=thirdparty%2Fpdns.git dnsdist: Add per-backend `max_udp_outstanding` YAML config setting This commit adds a new per-backend config setting `max_udp_outstanding` which overrides the global `tuning.udp.max_outstanding_per_backend` setting. If the per-backend `max_udp_outstanding` setting is omitted, the value of the global option `tuning.udp.max_outstanding_per_backend` will be used instead. This allows tuning the number of UDP states allocated on a per-backend basis in order to tune the amount of memory consumed by dnsdist. Low-latency backends may only need a small number of UDP states, while high-latency backends may need a higher number of UDP states. The `tuning.udp.max_outstanding_per_backend` setting and the new per-backend `max_udp_outstanding` setting directly control the sizes of the vectors of `IDState` objects that are preallocated at startup. The size of the `IDState` object can vary depending on compile time options, but in my local build it is currently 496 bytes. This means that a backend with the maximum number of UDP states (65535) will require allocating at least (496 * 65535 / 1048576) = 31 MB. Similarly, a backend with 8192 UDP states will require allocating 3.9 MB, and a backend with 256 UDP states only requires 124 KB. Signed-off-by: Robert Edmonds --- diff --git a/pdns/dnsdistdist/dnsdist-backend.cc b/pdns/dnsdistdist/dnsdist-backend.cc index bb90467dd5..38bf194da9 100644 --- a/pdns/dnsdistdist/dnsdist-backend.cc +++ b/pdns/dnsdistdist/dnsdist-backend.cc @@ -380,7 +380,8 @@ void DownstreamState::connectUDPSockets() idStates.clear(); } else { - idStates.resize(config.d_maxUDPOutstanding); + const auto maxUDPOutstanding = d_config.d_maxUDPOutstanding > 0 ? d_config.d_maxUDPOutstanding : config.d_maxUDPOutstanding; + idStates.resize(maxUDPOutstanding); } sockets.resize(d_config.d_numberOfSockets); diff --git a/pdns/dnsdistdist/dnsdist-configuration-yaml.cc b/pdns/dnsdistdist/dnsdist-configuration-yaml.cc index 412a07b5bb..518cf87270 100644 --- a/pdns/dnsdistdist/dnsdist-configuration-yaml.cc +++ b/pdns/dnsdistdist/dnsdist-configuration-yaml.cc @@ -460,6 +460,7 @@ static std::shared_ptr createBackendFromConfiguration(const Con backendConfig.order = config.order; backendConfig.d_weight = config.weight; backendConfig.d_maxInFlightQueriesPerConn = config.max_in_flight; + backendConfig.d_maxUDPOutstanding = config.max_udp_outstanding; backendConfig.d_tcpConcurrentConnectionsLimit = config.max_concurrent_tcp_connections; backendConfig.name = std::string(config.name); if (!config.id.empty()) { diff --git a/pdns/dnsdistdist/dnsdist-settings-definitions.yml b/pdns/dnsdistdist/dnsdist-settings-definitions.yml index 2919f524dc..922ef214f9 100644 --- a/pdns/dnsdistdist/dnsdist-settings-definitions.yml +++ b/pdns/dnsdistdist/dnsdist-settings-definitions.yml @@ -1458,6 +1458,10 @@ backend: type: "u32" default: "1" description: "Maximum number of in-flight queries. The default is 0, which disables out-of-order processing. It should only be enabled if the backend does support out-of-order processing. Out-of-order processing needs to be enabled on the frontend as well" + - name: "max_udp_outstanding" + type: "u32" + default: "0" + description: "Maximum number of outstanding UDP queries for this backend. If not set, defaults to ``tuning.udp.max_outstanding_per_backend``." - name: "tcp_only" type: "bool" default: "false" diff --git a/pdns/dnsdistdist/dnsdist.hh b/pdns/dnsdistdist/dnsdist.hh index 766e602bd5..34834803f1 100644 --- a/pdns/dnsdistdist/dnsdist.hh +++ b/pdns/dnsdistdist/dnsdist.hh @@ -599,6 +599,7 @@ struct DownstreamState : public std::enable_shared_from_this #endif /* HAVE_XSK */ size_t d_numberOfSockets{1}; size_t d_maxInFlightQueriesPerConn{1}; + size_t d_maxUDPOutstanding{0}; size_t d_tcpConcurrentConnectionsLimit{0}; int order{1}; int d_weight{1};