]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Reduce the amount of times we copy our shared objects 6378/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 22 Mar 2018 17:44:41 +0000 (18:44 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 26 Mar 2018 08:42:08 +0000 (10:42 +0200)
pdns/dnsdist-carbon.cc
pdns/dnsdist-lua.cc
pdns/dnsdist-snmp.cc
pdns/dnsdist-web.cc
pdns/dnsdist.cc

index 32cab5d9a69b46523d612a19d51bd8d2db03dbab..7929dd14ae2e3acf535af37720c241f3b5640875 100644 (file)
@@ -82,8 +82,8 @@ try
             str<<(*boost::get<DNSDistStats::statfunction_t>(&e.second))(e.first);
           str<<' '<<now<<"\r\n";
         }
-        const auto states = g_dstates.getCopy();
-        for(const auto& state : states) {
+        auto states = g_dstates.getLocal();
+        for(const auto& state : *states) {
           string serverName = state->name.empty() ? (state->remote.toString() + ":" + std::to_string(state->remote.getPort())) : state->getName();
           boost::replace_all(serverName, ".", "_");
           const string base = "dnsdist." + hostname + ".main.servers." + serverName + ".";
@@ -102,8 +102,8 @@ try
           const string base = "dnsdist." + hostname + ".main.frontends." + frontName + ".";
           str<<base<<"queries" << ' ' << front->queries.load() << " " << now << "\r\n";
         }
-        const auto localPools = g_pools.getCopy();
-        for (const auto& entry : localPools) {
+        auto localPools = g_pools.getLocal();
+        for (const auto& entry : *localPools) {
           string poolName = entry.first;
           boost::replace_all(poolName, ".", "_");
           if (poolName.empty()) {
index e3c305dd9d5118904b0885d85ba967f0779a52aa..7f557f085d57146e72fb69a6532f74a4e0468310 100644 (file)
@@ -494,7 +494,7 @@ void setupLuaConfig(bool client)
       setLuaNoSideEffect();
       vector<string> vec;
 
-      g_ACL.getCopy().toStringVector(&vec);
+      g_ACL.getLocal()->toStringVector(&vec);
 
       for(const auto& s : vec)
         g_outputBuffer+=s+"\n";
@@ -529,8 +529,8 @@ void setupLuaConfig(bool client)
 
       uint64_t totQPS{0}, totQueries{0}, totDrops{0};
       int counter=0;
-      auto states = g_dstates.getCopy();
-      for(const auto& s : states) {
+      auto states = g_dstates.getLocal();
+      for(const auto& s : *states) {
        string status = s->getStatus();
        string pools;
        for(auto& p : s->pools) {
index 90cad6873195e7eeeb7b087f5a3ab8bfd4167cbb..ec9683f4580944848498003ddeff6b7221d34283 100644 (file)
@@ -257,10 +257,10 @@ static netsnmp_variable_list* backendStatTable_get_first_data_point(void** loop_
 
   /* get a copy of the shared_ptrs so they are not
      destroyed while we process the request */
-  const auto& dstates = g_dstates.getCopy();
+  auto dstates = g_dstates.getLocal();
   s_servers.clear();
-  s_servers.reserve(dstates.size());
-  for (const auto& server : dstates) {
+  s_servers.reserve(dstates->size());
+  for (const auto& server : *dstates) {
     s_servers.push_back(server);
   }
 
index 8ebb4818eda911ada9a3b46daf96fae25f663f96..76977946a79dee48e477a567826c8bbd91638240 100644 (file)
@@ -65,7 +65,7 @@ static bool apiWriteConfigFile(const string& filebasename, const string& content
 static void apiSaveACL(const NetmaskGroup& nmg)
 {
   vector<string> vec;
-  g_ACL.getCopy().toStringVector(&vec);
+  g_ACL.getLocal()->toStringVector(&vec);
 
   string acl;
   for(const auto& s : vec) {
@@ -225,8 +225,8 @@ static json11::Json::array someResponseRulesToJson(GlobalStateHolder<vector<T>>*
   using namespace json11;
   Json::array responseRules;
   int num=0;
-  auto localResponseRules = someResponseRules->getCopy();
-  for(const auto& a : localResponseRules) {
+  auto localResponseRules = someResponseRules->getLocal();
+  for(const auto& a : *localResponseRules) {
     Json::object rule{
       {"id", num++},
       {"uuid", boost::uuids::to_string(a.d_id)},
@@ -322,10 +322,10 @@ static void connectionThread(int sock, ComboAddress remote, string password, str
       }
       else if(command=="dynblocklist") {
         Json::object obj;
-        auto slow = g_dynblockNMG.getCopy();
+        auto nmg = g_dynblockNMG.getLocal();
         struct timespec now;
         gettime(&now);
-        for(const auto& e: slow) {
+        for(const auto& e: *nmg) {
           if(now < e->second.until ) {
             Json::object thing{
               {"reason", e->second.reason},
@@ -336,8 +336,8 @@ static void connectionThread(int sock, ComboAddress remote, string password, str
           }
         }
 
-        auto slow2 = g_dynblockSMT.getCopy();
-        slow2.visit([&now,&obj](const SuffixMatchTree<DynBlock>& node) {
+        auto smt = g_dynblockSMT.getLocal();
+        smt->visit([&now,&obj](const SuffixMatchTree<DynBlock>& node) {
             if(now <node.d_value.until) {
               string dom("empty");
               if(!node.d_value.domain.empty())
@@ -385,9 +385,9 @@ static void connectionThread(int sock, ComboAddress remote, string password, str
       resp.status=200;
 
       Json::array servers;
-      auto localServers = g_dstates.getCopy();
+      auto localServers = g_dstates.getLocal();
       int num=0;
-      for(const auto& a : localServers) {
+      for(const auto& a : *localServers) {
        string status;
        if(a->availability == DownstreamState::Availability::Up) 
          status = "UP";
@@ -441,9 +441,9 @@ static void connectionThread(int sock, ComboAddress remote, string password, str
       }
 
       Json::array pools;
-      auto localPools = g_pools.getCopy();
+      auto localPools = g_pools.getLocal();
       num=0;
-      for(const auto& pool :localPools) {
+      for(const auto& pool : *localPools) {
         const auto& cache = pool.second->packetCache;
         Json::object entry {
           { "id", num++ },
@@ -463,9 +463,9 @@ static void connectionThread(int sock, ComboAddress remote, string password, str
       }
 
       Json::array rules;
-      auto localRules = g_rulactions.getCopy();
+      auto localRules = g_rulactions.getLocal();
       num=0;
-      for(const auto& a : localRules) {
+      for(const auto& a : *localRules) {
        Json::object rule{
           {"id", num++},
           {"uuid", boost::uuids::to_string(a.d_id)},
@@ -484,7 +484,7 @@ static void connectionThread(int sock, ComboAddress remote, string password, str
       string acl;
 
       vector<string> vec;
-      g_ACL.getCopy().toStringVector(&vec);
+      g_ACL.getLocal()->toStringVector(&vec);
 
       for(const auto& s : vec) {
         if(!acl.empty()) acl += ", ";
@@ -551,7 +551,7 @@ static void connectionThread(int sock, ComboAddress remote, string password, str
       Json::array doc;
       typedef boost::variant<bool, double, std::string> configentry_t;
       std::vector<std::pair<std::string, configentry_t> > configEntries {
-        { "acl", g_ACL.getCopy().toString() },
+        { "acl", g_ACL.getLocal()->toString() },
         { "control-socket", g_serverControl.toStringWithPort() },
         { "ecs-override", g_ECSOverride },
         { "ecs-source-prefix-v4", (double) g_ECSSourcePrefixV4 },
@@ -634,7 +634,7 @@ static void connectionThread(int sock, ComboAddress remote, string password, str
       if (resp.status == 200) {
         Json::array acl;
         vector<string> vec;
-        g_ACL.getCopy().toStringVector(&vec);
+        g_ACL.getLocal()->toStringVector(&vec);
 
         for(const auto& s : vec) {
           acl.push_back(s);
index c928994a17bb2a4e887aa8d47ab535f8b5667878..fe665e5134ae2b69751b863d30835ae9bc5bd76f 100644 (file)
@@ -1778,9 +1778,9 @@ void* maintThread()
 
     counter++;
     if (counter >= g_cacheCleaningDelay) {
-      const auto localPools = g_pools.getCopy();
+      auto localPools = g_pools.getLocal();
       std::shared_ptr<DNSDistPacketCache> packetCache = nullptr;
-      for (const auto& entry : localPools) {
+      for (const auto& entry : *localPools) {
         packetCache = entry.second->packetCache;
         if (packetCache) {
           size_t upTo = (packetCache->getMaxEntries()* (100 - g_cacheCleaningPercentage)) / 100;
@@ -1805,7 +1805,8 @@ void* healthChecksThread()
     if(g_tcpclientthreads->getQueuedCount() > 1 && !g_tcpclientthreads->hasReachedMaxThreads())
       g_tcpclientthreads->addTCPClientThread();
 
-    for(auto& dss : g_dstates.getCopy()) { // this points to the actual shared_ptrs!
+    auto states = g_dstates.getLocal(); // this points to the actual shared_ptrs!
+    for(auto& dss : *states) {
       if(dss->availability==DownstreamState::Availability::Auto) {
         bool newState=upCheck(*dss);
         if (newState) {
@@ -1971,15 +1972,15 @@ static void checkFileDescriptorsLimits(size_t udpBindsCount, size_t tcpBindsCoun
 {
   /* stdin, stdout, stderr */
   size_t requiredFDsCount = 3;
-  const auto backends = g_dstates.getCopy();
+  auto backends = g_dstates.getLocal();
   /* UDP sockets to backends */
   size_t backendUDPSocketsCount = 0;
-  for (const auto& backend : backends) {
+  for (const auto& backend : *backends) {
     backendUDPSocketsCount += backend->sockets.size();
   }
   requiredFDsCount += backendUDPSocketsCount;
   /* TCP sockets to backends */
-  requiredFDsCount += (backends.size() * g_maxTCPClientThreads);
+  requiredFDsCount += (backends->size() * g_maxTCPClientThreads);
   /* listening sockets */
   requiredFDsCount += udpBindsCount;
   requiredFDsCount += tcpBindsCount;
@@ -2573,7 +2574,7 @@ try
     warnlog("dnsdist %s comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it according to the terms of the GPL version 2", VERSION);
     vector<string> vec;
     std::string acls;
-    g_ACL.getCopy().toStringVector(&vec);
+    g_ACL.getLocal()->toStringVector(&vec);
     for(const auto& s : vec) {
       if (!acls.empty())
         acls += ", ";
@@ -2621,7 +2622,7 @@ try
   }
   g_pools.setState(localPools);
 
-  if(g_dstates.getCopy().empty()) {
+  if(g_dstates.getLocal()->empty()) {
     errlog("No downstream servers defined: all packets will get dropped");
     // you might define them later, but you need to know
   }