Permalink
Browse files

add 'bench-db' to do very simple database backend performance benchmark

  • Loading branch information...
1 parent 796321c commit 02653a7cacee9491dfdb9191bbd9f5ef3cd82ccc @ahupowerdns ahupowerdns committed with mind04 Dec 11, 2014
Showing with 48 additions and 0 deletions.
  1. +48 −0 pdns/pdnssec.cc
View
@@ -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");
@@ -1127,6 +1171,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;
@@ -1244,6 +1289,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));
}

0 comments on commit 02653a7

Please sign in to comment.