]> granicus.if.org Git - pdns/commitdiff
limit packet cache cleaning to at most once every 30 seconds
authorbert hubert <bert.hubert@powerdns.com>
Tue, 16 Aug 2016 12:30:41 +0000 (14:30 +0200)
committerbert hubert <bert.hubert@powerdns.com>
Tue, 16 Aug 2016 12:30:41 +0000 (14:30 +0200)
pdns/packetcache.hh

index 74e3770b2452c4fb613c56baa5cb7ca160b4efc0..14545b848b4b5656957c2b236bd6002f235388ee 100644 (file)
@@ -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;