Skip to content

Commit

Permalink
document cache cleaning rate adjustment, plus switch to symbolic name…
Browse files Browse the repository at this point in the history
…s for limits
  • Loading branch information
ahupowerdns authored and mind04 committed Oct 1, 2016
1 parent 8c879d4 commit 3a0bded
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
20 changes: 18 additions & 2 deletions pdns/packetcache.cc
Expand Up @@ -434,22 +434,38 @@ void PacketCache::cleanup()
DLOG(L<<"Done with cache clean"<<endl); 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() void PacketCache::cleanupIfNeeded()
{ {
if (d_ops++ == d_nextclean) { if (d_ops++ == d_nextclean) {
int timediff = max((int)(time(0) - d_lastclean), 1); int timediff = max((int)(time(0) - d_lastclean), 1);


DLOG(L<<"cleaninterval: "<<d_cleaninterval<<", timediff: "<<timediff<<endl); 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_cleanskipped = true;
d_nextclean += d_cleaninterval; d_nextclean += d_cleaninterval;


DLOG(L<<"cleaning skipped, timediff: "<<timediff<<endl); DLOG(L<<"cleaning skipped, timediff: "<<timediff<<endl);


return; 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; d_cleanskipped = false;
} }


Expand Down
4 changes: 3 additions & 1 deletion pdns/packetcache.hh
Expand Up @@ -141,7 +141,7 @@ private:
AtomicCounter d_ops; AtomicCounter d_ops;
time_t d_lastclean; // doesn't need to be atomic time_t d_lastclean; // doesn't need to be atomic
unsigned long d_nextclean; unsigned long d_nextclean;
int d_cleaninterval; unsigned int d_cleaninterval;
bool d_cleanskipped; bool d_cleanskipped;
AtomicCounter *d_statnumhit; AtomicCounter *d_statnumhit;
AtomicCounter *d_statnummiss; AtomicCounter *d_statnummiss;
Expand All @@ -150,6 +150,8 @@ private:
int d_ttl; int d_ttl;
int d_recursivettl; int d_recursivettl;
bool d_doRecursion; bool d_doRecursion;

static constexpr unsigned int s_mincleaninterval=1000, s_maxcleaninterval=300000;
}; };




Expand Down

0 comments on commit 3a0bded

Please sign in to comment.