From: bert hubert Date: Tue, 16 Aug 2016 12:30:41 +0000 (+0200) Subject: limit packet cache cleaning to at most once every 30 seconds X-Git-Tag: rec-4.0.2~27^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f47b3054e30ff49129596e3a703080ff6fa89588;p=thirdparty%2Fpdns.git limit packet cache cleaning to at most once every 30 seconds --- diff --git a/pdns/packetcache.hh b/pdns/packetcache.hh index 74e3770b24..14545b848b 100644 --- a/pdns/packetcache.hh +++ b/pdns/packetcache.hh @@ -70,8 +70,12 @@ public: int size(); //!< number of entries in the cache void cleanupIfNeeded() { - if(!(++d_ops % 300000)) - cleanup(); + if(!(++d_ops % 300000)) { + if(d_lastclean + 30 < time(0)) { + d_lastclean=time(0); + cleanup(); + } + } } void cleanup(); //!< force the cache to preen itself from expired packets int purge(); @@ -143,6 +147,7 @@ private: } AtomicCounter d_ops; + time_t d_lastclean{0}; // doesn't need to be atomic AtomicCounter *d_statnumhit; AtomicCounter *d_statnummiss; AtomicCounter *d_statnumentries;