[Pdns-dev] Recursor : feature proposal : cache-hitratio & packetcache-hitratio metrics via rec_control get

GAVARRET, David david.gavarret at sfr.com
Wed Feb 8 17:43:16 CET 2012


Hello,

as I was doing some tuning of my max-[packet]cache-entires settings, I tought it could be useful to get cache & packet-cache hit ratio metrics also available via "rec_control get" command with only one call (in my case, values are fetched via snmp polling, associating snmp extends to a "rec_control get" command for each counter).

Small patch proposal at the end of this mail. For more precision, ratio is returned as per one thousand.

By the way, I was wondering what was the difference between SyncRes::s_queries and g_stats.qcounter ? On the stats log, packet cache hit ratio is computed with the first one, but some manual testings seem to show that packet cache hits / g_stats.qcounter would be a more accurate value ...

-- 
David Gavarret


diff -crb pdns-recursor-3.4-pre/rec_channel_rec.cc pdns-recursor-3.4-pre-hitratio-patch//rec_channel_rec.cc
*** pdns-recursor-3.4-pre/rec_channel_rec.cc	2011-04-21 15:29:12.000000000 +0200
--- pdns-recursor-3.4-pre-hitratio-patch//rec_channel_rec.cc	2012-02-08 16:52:21.000000000 +0100
***************
*** 334,339 ****
--- 334,348 ----
    return broadcastAccFunction<uint64_t>(pleaseGetCacheMisses);
  }
  
+ uint64_t* pleaseGetCacheHitRatio()
+ {
+ 	  return new uint64_t((t_RC->cacheHits*1000.0)/(t_RC->cacheHits+t_RC->cacheMisses));
+ }
+ 
+ uint64_t doGetCacheHitRatio()
+ {
+ 	  return broadcastAccFunction<uint64_t>(pleaseGetCacheHitRatio);
+ }
  
  uint64_t* pleaseGetPacketCacheSize()
  {
***************
*** 377,382 ****
--- 386,401 ----
    return broadcastAccFunction<uint64_t>(pleaseGetPacketCacheMisses);
  }
  
+ uint64_t* pleaseGetPacketCacheHitRatio()
+ {
+ 	  return new uint64_t((t_packetCache->d_hits*1000.0)/SyncRes::s_queries);
+ }
+ 
+ uint64_t doGetPacketCacheHitRatio()
+ {
+ 	  return broadcastAccFunction<uint64_t>(pleaseGetPacketCacheHitRatio);
+ }
+ 
  uint64_t doGetMallocated()
  {
    // this turned out to be broken
***************
*** 393,404 ****
--- 412,425 ----
    addGetStat("cache-hits", doGetCacheHits);
    addGetStat("cache-misses", doGetCacheMisses); 
    addGetStat("cache-entries", doGetCacheSize); 
+   addGetStat("cache-hitratio", doGetCacheHitRatio);
    addGetStat("cache-bytes", doGetCacheBytes); 
    
    addGetStat("packetcache-hits", doGetPacketCacheHits);
    addGetStat("packetcache-misses", doGetPacketCacheMisses); 
    addGetStat("packetcache-entries", doGetPacketCacheSize); 
    addGetStat("packetcache-bytes", doGetPacketCacheBytes); 
+   addGetStat("packetcache-hitratio", doGetPacketCacheHitRatio);
    
    addGetStat("malloc-bytes", doGetMallocated);
    


More information about the Pdns-dev mailing list