From 4fc52785940e35477e863eeb5290a0c23e58e898 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 23 Jun 2021 12:08:09 +0200 Subject: [PATCH] dnsdist: Don't look up the LMDB dbi by name for every query This yields a ~5% performance improvement for LMDB lookups. --- pdns/dnsdistdist/dnsdist-kvs.cc | 6 ++---- pdns/dnsdistdist/dnsdist-kvs.hh | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) 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; }; -- 2.47.2