From: bert hubert Date: Fri, 15 Sep 2017 15:42:51 +0000 (+0200) Subject: implement dynamic cache sizeing for recursor X-Git-Tag: rec-4.1.0-rc1~19^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a6f7f5fec29ff4e2579ca93f019c77265a8f2a67;p=thirdparty%2Fpdns.git implement dynamic cache sizeing for recursor With this commit, the number of (packet)cache entries can be changed at runtime, although the effect may not be immediate in case of shrinking the cache. --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index f733f81e9d..e863614f12 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -156,6 +156,7 @@ static bool g_useOneSocketPerThread; static bool g_gettagNeedsEDNSOptions{false}; static time_t g_statisticsInterval; static bool g_useIncomingECS; +std::atomic g_maxCacheEntries, g_maxPacketCacheEntries; RecursorControlChannel s_rcc; // only active in thread 0 RecursorStats g_stats; @@ -2080,10 +2081,10 @@ static void houseKeeping(void *) if(now.tv_sec - last_prune > (time_t)(5 + t_id)) { DTime dt; dt.setTimeval(now); - t_RC->doPrune(); // this function is local to a thread, so fine anyhow - t_packetCache->doPruneTo(::arg().asNum("max-packetcache-entries") / g_numWorkerThreads); + t_RC->doPrune(g_maxCacheEntries / g_numThreads); // this function is local to a thread, so fine anyhow + t_packetCache->doPruneTo(g_maxPacketCacheEntries / g_numWorkerThreads); - SyncRes::pruneNegCache(::arg().asNum("max-cache-entries") / (g_numWorkerThreads * 10)); + SyncRes::pruneNegCache(g_maxCacheEntries / (g_numWorkerThreads * 10)); if(!((cleanCounter++)%40)) { // this is a full scan! time_t limit=now.tv_sec-300; @@ -2817,6 +2818,9 @@ static int serviceMain(int argc, char*argv[]) g_dnssecLogBogus = ::arg().mustDo("dnssec-log-bogus"); g_maxNSEC3Iterations = ::arg().asNum("nsec3-max-iterations"); + g_maxCacheEntries = ::arg().asNum("max-cache-entries"); + g_maxPacketCacheEntries = ::arg().asNum("max-packetcache-entries"); + try { loadRecursorLuaConfig(::arg()["lua-config-file"], ::arg().mustDo("daemon")); } diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 269dbe649e..e722f202dd 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -612,6 +612,24 @@ string setMinimumTTL(T begin, T end) return "New minimum TTL: " + std::to_string(SyncRes::s_minimumTTL) + "\n"; } +template +string setMaxCacheEntries(T begin, T end) +{ + if(end-begin != 1) + return "Need to supply new cache size\n"; + g_maxCacheEntries = pdns_stou(*begin); + return "New minimum TTL: " + std::to_string(g_maxCacheEntries) + "\n"; +} + +template +string setMaxPacketCacheEntries(T begin, T end) +{ + if(end-begin != 1) + return "Need to supply new packet cache size\n"; + g_maxPacketCacheEntries = pdns_stou(*begin); + return "New minimum TTL: " + std::to_string(g_maxPacketCacheEntries) + "\n"; +} + static uint64_t getSysTimeMsec() { @@ -1205,6 +1223,8 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP "reload-lua-script [filename] (re)load Lua script\n" "reload-lua-config [filename] (re)load Lua configuration file\n" "reload-zones reload all auth and forward zones\n" +"set-max-cache-entries value set new maximum cache size" +"set-max-packetcache-entries val set new maximum packet cache size" "set-minimum-ttl value set minimum-ttl-override\n" "set-carbon-server set a carbon server for telemetry\n" "set-dnssec-log-bogus SETTING enable (SETTING=yes) or disable (SETTING=no) logging of DNSSEC validation failures\n" @@ -1352,6 +1372,13 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP return reloadAuthAndForwards(); } + if(cmd=="set-max-cache-entries") { + return setMaxCacheEntries(begin, end); + } + if(cmd=="set-max-packetcache-entries") { + return setMaxPacketCacheEntries(begin, end); + } + if(cmd=="set-minimum-ttl") { return setMinimumTTL(begin, end); } diff --git a/pdns/recursor_cache.cc b/pdns/recursor_cache.cc index 2b6e9010b5..d3245420fb 100644 --- a/pdns/recursor_cache.cc +++ b/pdns/recursor_cache.cc @@ -484,8 +484,3 @@ void MemRecursorCache::doPrune(unsigned int keep) pruneCollection(*this, d_cache, keep); } -void MemRecursorCache::doPrune(void) -{ - unsigned int maxCached=::arg().asNum("max-cache-entries") / g_numThreads; - doPrune(maxCached); -} diff --git a/pdns/recursor_cache.hh b/pdns/recursor_cache.hh index ca9cf4a982..9f53ca5724 100644 --- a/pdns/recursor_cache.hh +++ b/pdns/recursor_cache.hh @@ -61,7 +61,6 @@ public: void replace(time_t, const DNSName &qname, const QType& qt, const vector& content, const vector>& signatures, const std::vector>& authorityRecs, bool auth, boost::optional ednsmask=boost::none, vState state=Indeterminate); - void doPrune(void); void doPrune(unsigned int keep); uint64_t doDump(int fd); diff --git a/pdns/recursordist/docs/manpages/rec_control.rst b/pdns/recursordist/docs/manpages/rec_control.rst index 352b5d577c..0db7b10c85 100644 --- a/pdns/recursordist/docs/manpages/rec_control.rst +++ b/pdns/recursordist/docs/manpages/rec_control.rst @@ -150,6 +150,16 @@ set-dnssec-log-bogus *SETTING* DNSSEC validation failures and to 'no' or 'off' to disable logging these failures. +set-max-cache-entries *NUM* + Change the maximum number of entries in the DNS cache. If reduced, the + cache size will start shrinking to this number as part of the normal + cache purging process, which might take a while. + +set-max-packetcache-entries *NUM* + Change the maximum number of entries in the packet cache. If reduced, the + cache size will start shrinking to this number as part of the normal + cache purging process, which might take a while. + set-minimum-ttl *NUM* Set minimum-ttl-override to *NUM*. diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 980650f6d3..fddfb9721a 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -949,6 +949,7 @@ void parseACLs(); extern RecursorStats g_stats; extern unsigned int g_numThreads; extern uint16_t g_outgoingEDNSBufsize; +extern std::atomic g_maxCacheEntries, g_maxPacketCacheEntries; std::string reloadAuthAndForwards();