]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
adaptive packetcache cleaning interval
authorKees Monshouwer <mind04@monshouwer.org>
Tue, 27 Sep 2016 08:55:47 +0000 (10:55 +0200)
committermind04 <mind04@monshouwer.org>
Sat, 1 Oct 2016 16:51:36 +0000 (18:51 +0200)
pdns/packetcache.cc
pdns/packetcache.hh
regression-tests/startpdns [deleted file]

index 8b20949a169da8bab13ee6c5ec8dbc4de2574a25..a30f56e960c3ea9a5cbd880f280be6fc31618916 100644 (file)
@@ -43,6 +43,10 @@ PacketCache::PacketCache()
   d_ttl=-1;
   d_recursivettl=-1;
 
+  d_lastclean=time(0);
+  d_cleanskipped=false;
+  d_nextclean=d_cleaninterval=4096;
+
   S.declare("packetcache-hit");
   S.declare("packetcache-miss");
   S.declare("packetcache-size");
@@ -429,3 +433,28 @@ void PacketCache::cleanup()
   
   DLOG(L<<"Done with cache clean"<<endl);
 }
+
+void PacketCache::cleanupIfNeeded()
+{
+  if (d_ops++ == d_nextclean) {
+    int timediff = max((int)(time(0) - d_lastclean), 1);
+
+    DLOG(L<<"cleaninterval: "<<d_cleaninterval<<", timediff: "<<timediff<<endl);
+
+    if (d_cleaninterval == 300000 && timediff < 30) {
+      d_cleanskipped = true;
+      d_nextclean += d_cleaninterval;
+
+      DLOG(L<<"cleaning skipped, timediff: "<<timediff<<endl);
+
+      return;
+    }
+    if(d_cleanskipped) {
+      d_cleanskipped = false;
+    }
+
+    d_nextclean += d_cleaninterval;
+    d_lastclean=time(0);
+    cleanup();
+  }
+}
index cd8ea9ad6bef4d0502d9d0a65215007760e520a4..aee5a7a728f0398c965da0bb0df445b70ad5d9bd 100644 (file)
@@ -68,15 +68,7 @@ public:
   
 
   int size() { return *d_statnumentries; } //!< number of entries in the cache
-  void cleanupIfNeeded()
-  {
-    if(!(++d_ops % 300000)) {
-      if(d_lastclean + 30 < time(0)) {
-        d_lastclean=time(0); 
-        cleanup();
-      }
-    }
-  }
+  void cleanupIfNeeded();
   void cleanup(); //!< force the cache to preen itself from expired packets
   int purge();
   int purge(const std::string& match); // could be $ terminated. Is not a dnsname!
@@ -147,7 +139,10 @@ private:
   }
 
   AtomicCounter d_ops;
-  time_t d_lastclean{0}; // doesn't need to be atomic
+  time_t d_lastclean; // doesn't need to be atomic
+  unsigned long d_nextclean;
+  int d_cleaninterval;
+  bool d_cleanskipped;
   AtomicCounter *d_statnumhit;
   AtomicCounter *d_statnummiss;
   AtomicCounter *d_statnumentries;
diff --git a/regression-tests/startpdns b/regression-tests/startpdns
deleted file mode 100755 (executable)
index 2fc8ab5..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/usr/bin/env bash
-
-../pdns/pdns_server --daemon=no --local-port=5300 --config-dir=. --module-dir=modules --config-name=bind --socket-dir=./ --master --webserver=yes --webserver-allow-from=0.0.0.0/0 --cache-ttl=1 --query-cache-ttl=1 --negquery-cache-ttl=1 --reuseport=yes --receiver-threads=4 --distributor-threads=3 --carbon-server=195.191.112.4 --carbon-ourname=pruts --loglevel=9 &
-#../pdns/pdns_server --daemon=no --local-port=5200 --config-dir=. --module-dir=modules --config-name=gmysql --socket-dir=./ --no-shuffle --master --send-root-referral --allow-dnsupdate-from=127.0.0.0/8 --experimental-dnsupdate=yes --cache-ttl=0 --experimental-dname-processing --lua-prequery-script=./check_stest_source --webserver=yes --webserver-allow-from=0.0.0.0/0 --loglevel=99999 --query-logging=yes &
-#      ./pdns/pdns_server --daemon=no --local-port=5300 --config-dir=. --config-name=gmysql2 --socket-dir=./ --no-shuffle --send-root-referral --slave --retrieval-threads=4 --slave-cycle-interval=300 --experimental-dname-processing &
-
-sleep 2
-
-echo push enter to terminate instance
-read l
-
-killall pdns_server
-#perf top -p $(pgrep pdns_server)q
\ No newline at end of file