From a9c2e4ab4d840a3bea9050bb072086c5861dae10 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 22 Mar 2018 18:44:41 +0100 Subject: [PATCH] dnsdist: Reduce the amount of times we copy our shared objects --- pdns/dnsdist-carbon.cc | 8 ++++---- pdns/dnsdist-lua.cc | 6 +++--- pdns/dnsdist-snmp.cc | 6 +++--- pdns/dnsdist-web.cc | 32 ++++++++++++++++---------------- pdns/dnsdist.cc | 17 +++++++++-------- 5 files changed, 35 insertions(+), 34 deletions(-) diff --git a/pdns/dnsdist-carbon.cc b/pdns/dnsdist-carbon.cc index 32cab5d9a..7929dd14a 100644 --- a/pdns/dnsdist-carbon.cc +++ b/pdns/dnsdist-carbon.cc @@ -82,8 +82,8 @@ try str<<(*boost::get(&e.second))(e.first); str<<' '<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<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()) { diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index e3c305dd9..7f557f085 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -494,7 +494,7 @@ void setupLuaConfig(bool client) setLuaNoSideEffect(); vector 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) { diff --git a/pdns/dnsdist-snmp.cc b/pdns/dnsdist-snmp.cc index 90cad6873..ec9683f45 100644 --- a/pdns/dnsdist-snmp.cc +++ b/pdns/dnsdist-snmp.cc @@ -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); } diff --git a/pdns/dnsdist-web.cc b/pdns/dnsdist-web.cc index 8ebb4818e..76977946a 100644 --- a/pdns/dnsdist-web.cc +++ b/pdns/dnsdist-web.cc @@ -65,7 +65,7 @@ static bool apiWriteConfigFile(const string& filebasename, const string& content static void apiSaveACL(const NetmaskGroup& nmg) { vector 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>* 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& node) { + auto smt = g_dynblockSMT.getLocal(); + smt->visit([&now,&obj](const SuffixMatchTree& node) { if(now 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 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 configentry_t; std::vector > 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 vec; - g_ACL.getCopy().toStringVector(&vec); + g_ACL.getLocal()->toStringVector(&vec); for(const auto& s : vec) { acl.push_back(s); diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index c928994a1..fe665e513 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -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 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 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 } -- 2.40.0