]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add the `setRingBuffersSize()` directive 4898/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 12 Jan 2017 17:23:35 +0000 (18:23 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 12 Jan 2017 17:23:35 +0000 (18:23 +0100)
The default ringbuffers size might be too small for large deployments,
this new directive allows changing it without recompiling.

pdns/README-dnsdist.md
pdns/dnsdist-console.cc
pdns/dnsdist-lua2.cc
pdns/dnsdist.hh

index 602c6314390509e2abfc27c54b792fe40f562d7b..032e0f59dfefefb4fd9a534dca883ecae7510fad 100644 (file)
@@ -1277,6 +1277,7 @@ Here are all functions:
     * `topSlow([top][, limit][, labels])`: show `top` queries slower than `limit` milliseconds, grouped by last `labels` labels
     * `topBandwidth(top)`: show top-`top` clients that consume the most bandwidth over length of ringbuffer
     * `topClients(n)`: show top-`n` clients sending the most queries over length of ringbuffer
+    * `setRingBuffersSize(n)`: set the capacity of the ringbuffers used for live traffic inspection to `n` (default to 10000)
     * `showResponseLatency()`: show a plot of the response time latency distribution
     * `showTCPStats()`: show some statistics regarding TCP
     * `showVersion()`: show the current version of dnsdist
index 45052f08db4997a28e8a44a9006a86186a6473b1..17e3b5c843aea042676b286a9f5bdca0892ce779 100644 (file)
@@ -336,6 +336,7 @@ const std::vector<ConsoleKeyword> g_consoleKeywords{
   { "setMaxUDPOutstanding", true, "n", "set the maximum number of outstanding UDP queries to a given backend server. This can only be set at configuration time and defaults to 10240" },
   { "setQueryCount", true, "bool", "set whether queries should be counted" },
   { "setQueryCountFilter", true, "func", "filter queries that would be counted, where `func` is a function with parameter `dq` which decides whether a query should and how it should be counted" },
+  { "setRingBuffersSize", true, "n", "set the capacity of the ringbuffers used for live traffic inspection to `n`" },
   { "setRules", true, "list of rules", "replace the current rules with the supplied list of pairs of DNS Rules and DNS Actions (see `newRuleAction()`)" },
   { "setServerPolicy", true, "policy", "set server selection policy to that policy" },
   { "setServerPolicyLua", true, "name, function", "set server selection policy to one named 'name' and provided by 'function'" },
index 416d4554ce243da38f8a6d461df7ab8a88154c1f..2f775a1d4d39217f6bba1ad2e7dcd8371ba00148 100644 (file)
@@ -1128,4 +1128,14 @@ void moreLua(bool client)
         setLuaSideEffect();
         g_servFailOnNoPolicy = servfail;
       });
+
+    g_lua.writeFunction("setRingBuffersSize", [](size_t capacity) {
+        setLuaSideEffect();
+        if (g_configurationDone) {
+          errlog("setRingBuffersSize() cannot be used at runtime!");
+          g_outputBuffer="setRingBuffersSize() cannot be used at runtime!\n";
+          return;
+        }
+        g_rings.setCapacity(capacity);
+      });    
 }
index cab656521a9da762586c7046b527022887172253..dc219cc8dd2e121fe1f4bd2c19337bc633335f5e 100644 (file)
@@ -273,10 +273,10 @@ struct IDState
 };
 
 struct Rings {
-  Rings()
+  Rings(size_t capacity=10000)
   {
-    queryRing.set_capacity(10000);
-    respRing.set_capacity(10000);
+    queryRing.set_capacity(capacity);
+    respRing.set_capacity(capacity);
     pthread_rwlock_init(&queryLock, 0);
   }
   struct Query
@@ -306,6 +306,17 @@ struct Rings {
 
   std::unordered_map<int, vector<boost::variant<string,double> > > getTopBandwidth(unsigned int numentries);
   size_t numDistinctRequestors();
+  void setCapacity(size_t newCapacity) 
+  {
+    {
+      WriteLock wl(&queryLock);
+      queryRing.set_capacity(newCapacity);
+    }
+    {
+      std::lock_guard<std::mutex> lock(respMutex);
+      respRing.set_capacity(newCapacity);
+    }
+  }
 };
 
 extern Rings g_rings;