]> granicus.if.org Git - pdns/commitdiff
add 'bench-db' to do very simple database backend performance benchmark
authorbert hubert <bert.hubert@netherlabs.nl>
Thu, 11 Dec 2014 11:18:13 +0000 (12:18 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Thu, 11 Dec 2014 11:18:13 +0000 (12:18 +0100)
pdns/pdnssec.cc

index 488c9509e47252c0c12046dac392bc2f56a02c33..608179a82ed8dbbe0cb9c91c8451b2626b1be2b4 100644 (file)
@@ -14,6 +14,7 @@
 #include "zoneparser-tng.hh"
 #include "signingpipe.hh"
 #include "dns_random.hh"
+#include <fstream>
 #ifdef HAVE_SQLITE3
 #include "ssqlite3.hh"
 #include "bind-dnssec.schema.sqlite3.sql.h"
@@ -339,6 +340,49 @@ bool rectifyZone(DNSSECKeeper& dk, const std::string& zone)
   return true;
 }
 
+void dbBench(const std::string& fname)
+{
+  ::arg().set("query-cache-ttl")="0";
+  ::arg().set("negquery-cache-ttl")="0";
+  UeberBackend B("default");
+
+  vector<string> domains;
+  if(!fname.empty()) {
+    ifstream ifs(fname.c_str());
+    if(!ifs) {
+      cerr<<"Could not open '"<<fname<<"' for reading domain names to query"<<endl;
+    }
+    string line;
+    while(getline(ifs,line)) {
+      trim(line);
+      domains.push_back(line);
+    }
+  }
+  if(domains.empty())
+    domains.push_back("powerdns.com");
+
+  int n=0;
+  DNSResourceRecord rr;
+  DTime dt;
+  dt.set();
+  unsigned int hits=0, misses=0;
+  for(; n < 10000; ++n) {
+    const string& domain = domains[random() % domains.size()];
+    B.lookup(QType(QType::NS), domain);
+    while(B.get(rr)) {
+      hits++;
+    }
+    B.lookup(QType(QType::A), boost::lexical_cast<string>(random())+"."+domain);
+    while(B.get(rr)) {
+    }
+    misses++;
+
+  }
+  cout<<0.001*dt.udiff()/n<<" millisecond/lookup"<<endl;
+  cout<<"Retrieved "<<hits<<" records, did "<<misses<<" queries which should have no match"<<endl;
+  cout<<"Packet cache reports: "<<S.read("query-cache-hit")<<" hits (should be 0) and "<<S.read("query-cache-miss") <<" misses"<<endl;
+}
+
 void rectifyAllZones(DNSSECKeeper &dk) 
 {
   UeberBackend B("default");
@@ -1123,6 +1167,7 @@ try
     cerr<<"add-zone-key ZONE zsk|ksk [bits] [active|passive]"<<endl;
     cerr<<"             [rsasha1|rsasha256|rsasha512|gost|ecdsa256|ecdsa384]"<<endl;
     cerr<<"                                   Add a ZSK or KSK to zone and specify algo&bits"<<endl;
+    cerr<<"bench-db [filename]                Bench database backend with queries, one domain per line"<<endl;
     cerr<<"check-zone ZONE                    Check a zone for correctness"<<endl;
     cerr<<"check-all-zones                    Check all zones for correctness"<<endl;
     cerr<<"create-bind-db FNAME               Create DNSSEC db for BIND backend (bind-dnssec-db)"<<endl;
@@ -1240,6 +1285,9 @@ try
     UeberBackend B("default");
     exit(checkZone(dk, B, cmds[1]));
   }
+  else if(cmds[0] == "bench-db") {
+    dbBench(cmds.size() > 1 ? cmds[1] : "");
+  }
   else if (cmds[0] == "check-all-zones") {
     exit(checkAllZones(dk));
   }