File tree Expand file tree Collapse file tree 3 files changed +34
-23
lines changed Expand file tree Collapse file tree 3 files changed +34
-23
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,10 @@ PacketCache::PacketCache()
43
43
d_ttl=-1 ;
44
44
d_recursivettl=-1 ;
45
45
46
+ d_lastclean=time (0 );
47
+ d_cleanskipped=false ;
48
+ d_nextclean=d_cleaninterval=4096 ;
49
+
46
50
S.declare (" packetcache-hit" );
47
51
S.declare (" packetcache-miss" );
48
52
S.declare (" packetcache-size" );
@@ -429,3 +433,28 @@ void PacketCache::cleanup()
429
433
430
434
DLOG (L<<" Done with cache clean" <<endl);
431
435
}
436
+
437
+ void PacketCache::cleanupIfNeeded ()
438
+ {
439
+ if (d_ops++ == d_nextclean) {
440
+ int timediff = max ((int )(time (0 ) - d_lastclean), 1 );
441
+
442
+ DLOG (L<<" cleaninterval: " <<d_cleaninterval<<" , timediff: " <<timediff<<endl);
443
+
444
+ if (d_cleaninterval == 300000 && timediff < 30 ) {
445
+ d_cleanskipped = true ;
446
+ d_nextclean += d_cleaninterval;
447
+
448
+ DLOG (L<<" cleaning skipped, timediff: " <<timediff<<endl);
449
+
450
+ return ;
451
+ }
452
+ if (d_cleanskipped) {
453
+ d_cleanskipped = false ;
454
+ }
455
+
456
+ d_nextclean += d_cleaninterval;
457
+ d_lastclean=time (0 );
458
+ cleanup ();
459
+ }
460
+ }
Original file line number Diff line number Diff line change @@ -68,15 +68,7 @@ public:
68
68
69
69
70
70
int size () { return *d_statnumentries; } // !< number of entries in the cache
71
- void cleanupIfNeeded ()
72
- {
73
- if (!(++d_ops % 300000 )) {
74
- if (d_lastclean + 30 < time (0 )) {
75
- d_lastclean=time (0 );
76
- cleanup ();
77
- }
78
- }
79
- }
71
+ void cleanupIfNeeded ();
80
72
void cleanup (); // !< force the cache to preen itself from expired packets
81
73
int purge ();
82
74
int purge (const std::string& match); // could be $ terminated. Is not a dnsname!
@@ -147,7 +139,10 @@ private:
147
139
}
148
140
149
141
AtomicCounter d_ops;
150
- time_t d_lastclean{0 }; // doesn't need to be atomic
142
+ time_t d_lastclean; // doesn't need to be atomic
143
+ unsigned long d_nextclean;
144
+ int d_cleaninterval;
145
+ bool d_cleanskipped;
151
146
AtomicCounter *d_statnumhit;
152
147
AtomicCounter *d_statnummiss;
153
148
AtomicCounter *d_statnumentries;
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments