]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Make SBF size configurable
authorNeil Cook <neil.cook@noware.co.uk>
Mon, 22 Oct 2018 10:37:29 +0000 (10:37 +0000)
committerNeil Cook <neil.cook@noware.co.uk>
Wed, 24 Oct 2018 12:43:25 +0000 (12:43 +0000)
pdns/nod.hh
pdns/pdns_recursor.cc

index 84e7ae65913a605e81aee3f2a8440a1e57846e7e..ce32f12d2503f7cd3e4550ba553c973106be1980 100644 (file)
@@ -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); 
index f5f7b71ea219e2e73b143d2ab64ac5fa663d8ee9..fe16ecb77af2cf1f954d7b37916d2bc6843c1a3c 100644 (file)
@@ -3305,7 +3305,8 @@ static void setCPUMap(const std::map<unsigned int, std::set<int> >& cpusMap, uns
 static void setupNODThread()
 {
   if (g_nodEnabled) {
-    t_nodDBp = std::make_shared<nod::NODDB>();
+    uint32_t num_cells = ::arg().asNum("new-domain-db-size");
+    t_nodDBp = std::make_shared<nod::NODDB>(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<nod::UniqueResponseDB>();
+    uint32_t num_cells = ::arg().asNum("unique-response-db-size");
+    t_udrDBp = std::make_shared<nod::UniqueResponseDB>(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");