From f47b3054e30ff49129596e3a703080ff6fa89588 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Tue, 16 Aug 2016 14:30:41 +0200 Subject: [PATCH] limit packet cache cleaning to at most once every 30 seconds --- pdns/packetcache.hh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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; -- 2.47.2