From: Remi Gacogne Date: Wed, 23 Jun 2021 10:08:09 +0000 (+0200) Subject: dnsdist: Don't look up the LMDB dbi by name for every query X-Git-Tag: dnsdist-1.7.0-alpha1~87^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4fc52785940e35477e863eeb5290a0c23e58e898;p=thirdparty%2Fpdns.git dnsdist: Don't look up the LMDB dbi by name for every query This yields a ~5% performance improvement for LMDB lookups. --- diff --git a/pdns/dnsdistdist/dnsdist-kvs.cc b/pdns/dnsdistdist/dnsdist-kvs.cc index 3b60dfc2ac..35621dd219 100644 --- a/pdns/dnsdistdist/dnsdist-kvs.cc +++ b/pdns/dnsdistdist/dnsdist-kvs.cc @@ -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(); 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; } diff --git a/pdns/dnsdistdist/dnsdist-kvs.hh b/pdns/dnsdistdist/dnsdist-kvs.hh index f0968b08ab..939be8a4da 100644 --- a/pdns/dnsdistdist/dnsdist-kvs.hh +++ b/pdns/dnsdistdist/dnsdist-kvs.hh @@ -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; };