]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Don't look up the LMDB dbi by name for every query
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 23 Jun 2021 10:08:09 +0000 (12:08 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 23 Jun 2021 10:08:09 +0000 (12:08 +0200)
This yields a ~5% performance improvement for LMDB lookups.

pdns/dnsdistdist/dnsdist-kvs.cc
pdns/dnsdistdist/dnsdist-kvs.hh

index 3b60dfc2acd0bda2636c4acaaf46b895c16a5588..35621dd2198a7a060ed8b77ad96bf29c9ae87c36 100644 (file)
@@ -77,9 +77,8 @@ bool LMDBKVStore::getValue(const std::string& key, std::string& value)
 {
   try {
     auto transaction = d_env.getROTransaction();
-    auto dbi = transaction->openDB(d_dbName, 0);
     MDBOutVal result;
-    int rc = transaction->get(dbi, MDBInVal(key), result);
+    int rc = transaction->get(d_dbi, MDBInVal(key), result);
     if (rc == 0) {
       value = result.get<std::string>();
       return true;
@@ -98,9 +97,8 @@ bool LMDBKVStore::keyExists(const std::string& key)
 {
   try {
     auto transaction = d_env.getROTransaction();
-    auto dbi = transaction->openDB(d_dbName, 0);
     MDBOutVal result;
-    int rc = transaction->get(dbi, MDBInVal(key), result);
+    int rc = transaction->get(d_dbi, MDBInVal(key), result);
     if (rc == 0) {
       return true;
     }
index f0968b08ab14b971e69d0acaf9097785f9be6fe7..939be8a4da2798e2d2162c94b924ccfa4ccca860 100644 (file)
@@ -165,7 +165,7 @@ public:
 class LMDBKVStore: public KeyValueStore
 {
 public:
-  LMDBKVStore(const std::string& fname, const std::string& dbName): d_env(fname.c_str(), MDB_NOSUBDIR, 0600), d_fname(fname), d_dbName(dbName)
+  LMDBKVStore(const std::string& fname, const std::string& dbName): d_env(fname.c_str(), MDB_NOSUBDIR, 0600), d_dbi(d_env.openDB(dbName, 0)), d_fname(fname), d_dbName(dbName)
   {
   }
 
@@ -174,6 +174,7 @@ public:
 
 private:
   MDBEnv d_env;
+  MDBDbi d_dbi;
   std::string d_fname;
   std::string d_dbName;
 };