From: Neil Cook Date: Mon, 22 Oct 2018 10:37:29 +0000 (+0000) Subject: Make SBF size configurable X-Git-Tag: dnsdist-1.3.3~16^2~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b78727c64bb331542bd5764f58eb1ad46c7f3f39;p=thirdparty%2Fpdns.git Make SBF size configurable --- diff --git a/pdns/nod.hh b/pdns/nod.hh index 84e7ae6591..ce32f12d25 100644 --- a/pdns/nod.hh +++ b/pdns/nod.hh @@ -27,9 +27,9 @@ #include "stable-bloom.hh" namespace nod { - const float fp_rate = 0.01; - const size_t num_cells = 67108864; - const uint8_t num_dec = 10; + const float c_fp_rate = 0.01; + const size_t c_num_cells = 67108864; + const uint8_t c_num_dec = 10; const unsigned int snapshot_interval_default = 600; const std::string bf_suffix = "bf"; const std::string sbf_prefix = "sbf"; @@ -41,6 +41,8 @@ namespace nod { // Synchronization (at the instance level) is needed when snapshotting class PersistentSBF { public: + PersistentSBF() : d_sbf{c_fp_rate, c_num_cells, c_num_dec} {} + PersistentSBF(uint32_t num_cells) : d_sbf{c_fp_rate, num_cells, c_num_dec} {} bool init(bool ignore_pid=false); void setPrefix(const std::string& prefix) { d_prefix = prefix; } // Added to filenames in cachedir void setCacheDir(const std::string& cachedir); @@ -58,7 +60,7 @@ namespace nod { } private: bool d_init{false}; - bf::stableBF d_sbf{fp_rate, num_cells, num_dec}; // Stable Bloom Filter + bf::stableBF d_sbf; // Stable Bloom Filter std::string d_cachedir; std::string d_prefix = sbf_prefix; std::mutex d_sbf_mutex; // Per-instance mutex for snapshots @@ -67,7 +69,8 @@ namespace nod { class NODDB { public: - NODDB() {} + NODDB() : d_psbf{} {} + NODDB(uint32_t num_cells) : d_psbf{num_cells} {} // Set ignore_pid to true if you don't mind loading files // created by the current process bool init(bool ignore_pid=false) { @@ -94,7 +97,8 @@ namespace nod { class UniqueResponseDB { public: - UniqueResponseDB() {} + UniqueResponseDB() : d_psbf{} {} + UniqueResponseDB(uint32_t num_cells) : d_psbf{num_cells} {} bool init(bool ignore_pid=false) { d_psbf.setPrefix("udr"); return d_psbf.init(ignore_pid); diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index f5f7b71ea2..fe16ecb77a 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -3305,7 +3305,8 @@ static void setCPUMap(const std::map >& cpusMap, uns static void setupNODThread() { if (g_nodEnabled) { - t_nodDBp = std::make_shared(); + uint32_t num_cells = ::arg().asNum("new-domain-db-size"); + t_nodDBp = std::make_shared(num_cells); try { t_nodDBp->setCacheDir(::arg()["new-domain-history-dir"]); } @@ -3321,7 +3322,8 @@ static void setupNODThread() t.detach(); } if (g_udrEnabled) { - t_udrDBp = std::make_shared(); + uint32_t num_cells = ::arg().asNum("unique-response-db-size"); + t_udrDBp = std::make_shared(num_cells); try { t_udrDBp->setCacheDir(::arg()["unique-response-history-dir"]); } @@ -4137,9 +4139,11 @@ int main(int argc, char **argv) ::arg().set("new-domain-lookup", "Perform a DNS lookup newly observed domains as a subdomain of the configured domain")=""; ::arg().set("new-domain-history-dir", "Persist new domain tracking data here to persist between restarts")=string(NODCACHEDIR)+"/nod"; ::arg().set("new-domain-whitelist", "List of domains (and implicitly all subdomains) which will never be considered a new domain")=""; + ::arg().set("new-domain-db-size", "Size of the DB used to track new domains in terms of number of cells. Defaults to 67108864")="67108864"; ::arg().set("unique-response-tracking", "Track unique responses (tuple of query name, type and RR).")="no"; ::arg().set("unique-response-log", "Log unique responses")="yes"; ::arg().set("unique-response-history-dir", "Persist unique response tracking data here to persist between restarts")=string(NODCACHEDIR)+"/udr"; + ::arg().set("unique-response-db-size", "Size of the DB used to track unique responses in terms of number of cells. Defaults to 67108864")="67108864"; #endif /* NOD_ENABLED */ ::arg().setCmd("help","Provide a helpful message"); ::arg().setCmd("version","Print version string");