]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add `setCacheCleaningPercentage()` 4748/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 3 Nov 2016 17:05:47 +0000 (18:05 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 3 Nov 2016 17:05:47 +0000 (18:05 +0100)
pdns/README-dnsdist.md
pdns/dnsdist-lua.cc
pdns/dnsdist.cc
pdns/dnsdist.hh

index 43ae7bbd6764bc6cd4884df62b3305974a9bce7e..44cc1ed3b93bcc9a1cdc24de310a277646836988 100644 (file)
@@ -880,7 +880,7 @@ getPool("poolname"):getCache():printStats()
 ```
 
 Expired cached entries can be removed from a cache using the `purgeExpired(n)`
-method, which will remove expired entries from the cache until at least `n`
+method, which will remove expired entries from the cache until at most `n`
 entries remain in the cache. For example, to remove all expired entries:
 
 ```
@@ -1488,6 +1488,7 @@ instantiate a server with additional parameters
     * `setMaxTCPQueuedConnections(n)`: set the maximum number of TCP connections queued (waiting to be picked up by a client thread), defaults to 1000. 0 means unlimited
     * `setMaxUDPOutstanding(n)`: set the maximum number of outstanding UDP queries to a given backend server. This can only be set at configuration time and defaults to 10240
     * `setCacheCleaningDelay(n)`: set the interval in seconds between two runs of the cache cleaning algorithm, removing expired entries
+    * `setCacheCleaningPercentage(n)`: set the percentage of the cache that the cache cleaning algorithm will try to free by removing expired entries. By default (100), all expired entries are removed
     * `setStaleCacheEntriesTTL(n)`: allows using cache entries expired for at most `n` seconds when no backend available to answer for a query
  * DNSCrypt related:
     * `addDNSCryptBind("127.0.0.1:8443", "provider name", "/path/to/resolver.cert", "/path/to/resolver.key", [false], [TCP Fast Open queue size]):` listen to incoming DNSCrypt queries on 127.0.0.1 port 8443, with a provider name of "provider name", using a resolver certificate and associated key stored respectively in the `resolver.cert` and `resolver.key` files. The fifth optional parameter sets SO_REUSEPORT when available. The last parameter sets the TCP Fast Open queue size, enabling TCP Fast Open when available and the value is larger than 0.
index ecfc53e8003bfcd083e5d5c51b97c401f5f8f22a..cae2b7feb58ae5c5d7323f4081caf509f8a3e831 100644 (file)
@@ -1523,6 +1523,7 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
     });
 
   g_lua.writeFunction("setCacheCleaningDelay", [](uint32_t delay) { g_cacheCleaningDelay = delay; });
+  g_lua.writeFunction("setCacheCleaningPercentage", [](uint16_t percentage) { if (percentage < 100) g_cacheCleaningPercentage = percentage; else g_cacheCleaningPercentage = 100; });
 
   g_lua.writeFunction("setECSSourcePrefixV4", [](uint16_t prefix) { g_ECSSourcePrefixV4=prefix; });
 
index faad4d79f3def503d0813c01e7121c4d2ac6b593..bee97ef9ee95d9c50a9c14b179613bbcdb237e74 100644 (file)
@@ -1264,6 +1264,7 @@ catch(...)
 
 uint64_t g_maxTCPClientThreads{10};
 std::atomic<uint16_t> g_cacheCleaningDelay{60};
+std::atomic<uint16_t> g_cacheCleaningPercentage{100};
 
 void* maintThread()
 {
@@ -1290,7 +1291,8 @@ void* maintThread()
           packetCache = entry.second->packetCache;
         }
         if (packetCache) {
-          packetCache->purgeExpired();
+          size_t upTo = (packetCache->getMaxEntries()* (100 - g_cacheCleaningPercentage)) / 100;
+          packetCache->purgeExpired(upTo);
         }
       }
       counter = 0;
index 7c4ac6f68782755961619e548e647fafdf7cce95..62089e1ac4cd1e2a3ea46bb588db42a9851a1260 100644 (file)
@@ -687,6 +687,7 @@ extern std::atomic<bool> g_configurationDone;
 extern uint64_t g_maxTCPClientThreads;
 extern uint64_t g_maxTCPQueuedConnections;
 extern std::atomic<uint16_t> g_cacheCleaningDelay;
+extern std::atomic<uint16_t> g_cacheCleaningPercentage;
 extern bool g_verboseHealthChecks;
 extern uint32_t g_staleCacheEntriesTTL;