From: Remi Gacogne Date: Fri, 25 Apr 2025 11:53:11 +0000 (+0200) Subject: dnsdist: Reduce memory usage with fast-changing dynamic backends X-Git-Tag: dnsdist-2.0.0-alpha2~12^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=100c826a03fb9b27730117ee0bc8042a1645f70f;p=thirdparty%2Fpdns.git dnsdist: Reduce memory usage with fast-changing dynamic backends The Lua code in `dnsdist-resolver.lua` periodically check whether the IP addresses associated with configured backend names have changed, and if they have it does potentially remove backends whose IP addresses are no longer present, and adds backends for new IP addresses. Each backend configured in DNSdist uses a fair amount of memory because of the states we pre-allocate for UDP queries, and unfortunately it looks like Lua holds to removed backends for quite a while by default, causing the removed backends to actually co-exist in memory with the new ones for a long time, leading to a higher than necessary memory consumption. This is particularly problematic when you realize that the memory allocator usually hold onto memory even when the program releases it. So in environments where IP addresses are updated very often, DNSdist can consume several times the memory it actually needs, which is not nice. This commit forces Lua to do a garbage collection cycle after refreshing servers, thus releasing removed servers much more quickly. This is far from ideal, but I don't have a better idea yet. --- diff --git a/dockerdata/dnsdist-resolver.lua b/dockerdata/dnsdist-resolver.lua index f9bf8d1c3c..16c82fc9d4 100644 --- a/dockerdata/dnsdist-resolver.lua +++ b/dockerdata/dnsdist-resolver.lua @@ -145,6 +145,8 @@ function _M.maintenance() end end end + collectgarbage() + collectgarbage() end return _M