Permalink
Browse files

adaptive packetcache cleaning interval

  • Loading branch information...
1 parent 8c03126 commit 8c879d4fc45408a3d9778b513dbe6928fab92fa1 @mind04 mind04 committed with mind04 Sep 27, 2016
Showing with 34 additions and 23 deletions.
  1. +29 −0 pdns/packetcache.cc
  2. +5 −10 pdns/packetcache.hh
  3. +0 −13 regression-tests/startpdns
View
@@ -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();
+ }
+}
View
@@ -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;
@@ -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

0 comments on commit 8c879d4

Please sign in to comment.