Permalink
Browse files

improve cache hitrate

  • Loading branch information...
1 parent 37aa990 commit 90974597aadaf1096e3fd0dc450be7422ea591a5 @ahupowerdns ahupowerdns committed Dec 9, 2014
Showing with 12 additions and 1 deletion.
  1. +1 −1 pdns/dns.cc
  2. +11 −0 pdns/recpacketcache.cc
View
@@ -101,7 +101,7 @@ bool dnspacketLessThan(const std::string& a, const std::string& b)
int result=0;
unsigned int n;
for(n = 0; n < aLabelLen && n < bLabelLen; ++n)
- if((result = aSafe[aPos + n] - bSafe[bPos +n])) // XXX this should perhaps be dns_tolower
+ if((result = dns_tolower(aSafe[aPos + n]) - dns_tolower(bSafe[bPos +n])))
break;
// cerr<<"Done loop, result="<<result<<", n = "<<n<<", aLabelLen="<<aLabelLen<<", bLabelLen="<<bLabelLen<<endl;
if(result < 0)
@@ -62,6 +62,17 @@ bool RecursorPacketCache::getResponsePacket(const std::string& queryPacket, time
memcpy(&id, queryPacket.c_str(), 2);
*responsePacket = iter->d_packet;
responsePacket->replace(0, 2, (char*)&id, 2);
+
+ string::size_type i=sizeof(dnsheader);
+
+ for(;;) {
+ int labellen = (unsigned char)queryPacket[i];
+ if(!labellen || i + labellen > responsePacket->size()) break;
+ i++;
+ responsePacket->replace(i, labellen, queryPacket, i, labellen);
+ i = i + labellen;
+ }
+
d_hits++;
moveCacheItemToBack(d_packetCache, iter);

0 comments on commit 9097459

Please sign in to comment.