Permalink
Browse files

document cache cleaning rate adjustment, plus switch to symbolic name…

…s for limits
  • Loading branch information...
1 parent 8c879d4 commit 3a0bded74eab4cb002a8afb5402c819478fd0157 @ahupowerdns ahupowerdns committed with mind04 Sep 29, 2016
Showing with 21 additions and 3 deletions.
  1. +18 −2 pdns/packetcache.cc
  2. +3 −1 pdns/packetcache.hh
View
@@ -434,22 +434,38 @@ void PacketCache::cleanup()
DLOG(L<<"Done with cache clean"<<endl);
}
+/* the logic:
+ after d_nextclean operations, we clean. We also adjust the cleaninterval
+ a bit so we slowly move it to a value where we clean roughly every 30 seconds.
+
+ If d_nextclean has reached its maximum value, we also test if we were called
+ within 30 seconds, and if so, we skip cleaning. This means that under high load,
+ we will not clean more often than every 30 seconds anyhow.
+*/
+
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) {
+ if (d_cleaninterval == s_maxcleaninterval && timediff < 30) {
d_cleanskipped = true;
d_nextclean += d_cleaninterval;
DLOG(L<<"cleaning skipped, timediff: "<<timediff<<endl);
return;
}
- if(d_cleanskipped) {
+
+ if(!d_cleanskipped) {
+ d_cleaninterval=(int)(0.6*d_cleaninterval)+(0.4*d_cleaninterval*(30.0/timediff));
+ d_cleaninterval=std::max(d_cleaninterval, s_mincleaninterval);
+ d_cleaninterval=std::min(d_cleaninterval, s_maxcleaninterval);
+
+ DLOG(L<<"new cleaninterval: "<<d_cleaninterval<<endl);
+ } else {
d_cleanskipped = false;
}
View
@@ -141,7 +141,7 @@ private:
AtomicCounter d_ops;
time_t d_lastclean; // doesn't need to be atomic
unsigned long d_nextclean;
- int d_cleaninterval;
+ unsigned int d_cleaninterval;
bool d_cleanskipped;
AtomicCounter *d_statnumhit;
AtomicCounter *d_statnummiss;
@@ -150,6 +150,8 @@ private:
int d_ttl;
int d_recursivettl;
bool d_doRecursion;
+
+ static constexpr unsigned int s_mincleaninterval=1000, s_maxcleaninterval=300000;
};

0 comments on commit 3a0bded

Please sign in to comment.