bool g_snmpTrapsEnabled{false};
DNSDistSNMPAgent* g_snmpAgent{nullptr};
+#if BENCH_POLICIES
+bool g_verbose{true};
+bool g_syslog{true};
+#include "dnsdist-rings.hh"
+Rings g_rings;
+GlobalStateHolder<NetmaskTree<DynBlock>> g_dynblockNMG;
+GlobalStateHolder<SuffixMatchTree<DynBlock>> g_dynblockSMT;
+#endif /* BENCH_POLICIES */
+
/* add stub implementations, we don't want to include the corresponding object files
and their dependencies */
return dq;
}
+static void benchPolicy(const ServerPolicy& pol)
+{
+#if BENCH_POLICIES
+ bool existingVerboseValue = g_verbose;
+ g_verbose = false;
+
+ std::vector<DNSName> names;
+ names.reserve(1000);
+ for (size_t idx = 0; idx < 1000; idx++) {
+ names.push_back(DNSName("powerdns-" + std::to_string(idx) + ".com."));
+ }
+ ServerPolicy::NumberedServerVector servers;
+ for (size_t idx = 1; idx <= 10; idx++) {
+ servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53")) });
+ servers.at(idx - 1).second->setUp();
+ }
+
+ StopWatch sw;
+ sw.start();
+ for (const auto& name : names) {
+ auto dq = getDQ(&name);
+ auto server = getSelectedBackendFromPolicy(pol, servers, dq);
+ }
+ cerr<<pol.name<<" took "<<std::to_string(sw.udiff())<<" us for "<<names.size()<<endl;
+
+ g_verbose = existingVerboseValue;
+#endif /* BENCH_POLICIES */
+}
+
BOOST_AUTO_TEST_SUITE(dnsdistlbpolicies)
BOOST_AUTO_TEST_CASE(test_firstAvailable) {
server = getSelectedBackendFromPolicy(pol, servers, dq);
BOOST_REQUIRE(server != nullptr);
BOOST_CHECK(server == servers.at(1).second);
+
+ std::vector<DNSName> names;
+ names.reserve(1000);
+ for (size_t idx = 0; idx < 1000; idx++) {
+ names.push_back(DNSName("powerdns-" + std::to_string(idx) + ".com."));
+ }
+ std::map<std::shared_ptr<DownstreamState>, uint64_t> serversMap;
+ for (size_t idx = 1; idx <= 10; idx++) {
+ servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53")) });
+ serversMap[servers.at(idx - 1).second] = 0;
+ servers.at(idx - 1).second->setUp();
+ }
+
+ benchPolicy(pol);
}
BOOST_AUTO_TEST_CASE(test_leastOutstanding) {
server = getSelectedBackendFromPolicy(pol, servers, dq);
BOOST_REQUIRE(server != nullptr);
BOOST_CHECK(server == servers.at(1).second);
+
+ benchPolicy(pol);
}
BOOST_AUTO_TEST_CASE(test_wrandom) {
servers.at(idx - 1).second->setUp();
}
+ benchPolicy(pol);
+
for (size_t idx = 0; idx < 1000; idx++) {
auto server = getSelectedBackendFromPolicy(pol, servers, dq);
BOOST_REQUIRE(serversMap.count(server) == 1);
servers.at(idx - 1).second->setUp();
}
+ benchPolicy(pol);
+
for (const auto& name : names) {
auto dq = getDQ(&name);
auto server = getSelectedBackendFromPolicy(pol, servers, dq);
BOOST_REQUIRE(serversMap.count(server) == 1);
++serversMap[server];
}
+
uint64_t total = 0;
for (const auto& entry : serversMap) {
BOOST_CHECK_GT(entry.second, 0);
servers.at(idx - 1).second->hash();
}
+ benchPolicy(pol);
+
for (const auto& name : names) {
auto dq = getDQ(&name);
auto server = getSelectedBackendFromPolicy(pol, servers, dq);
BOOST_REQUIRE(serversMap.count(server) == 1);
++serversMap[server];
}
+
uint64_t total = 0;
for (const auto& entry : serversMap) {
BOOST_CHECK_GT(entry.second, 0);
BOOST_REQUIRE(serversMap.count(server) == 1);
++serversMap[server];
}
+
uint64_t total = 0;
for (const auto& entry : serversMap) {
BOOST_CHECK_GT(entry.second, 0);
total += entry.second;
}
BOOST_CHECK_EQUAL(total, names.size());
+
+ benchPolicy(pol);
}
#ifdef LUAJIT_VERSION
function ffilb(servers_list, dq)
local serversCount = tonumber(C.dnsdist_ffi_servers_list_get_count(servers_list))
counter = counter + 1
- return counter % serversCount
+ local hash = tonumber(C.dnsdist_ffi_dnsquestion_get_qname_hash(dq, 0))
+ return hash % serversCount
end
setServerPolicyLuaFFI("FFI", ffilb)
BOOST_REQUIRE(serversMap.count(server) == 1);
++serversMap[server];
}
+
uint64_t total = 0;
for (const auto& entry : serversMap) {
BOOST_CHECK_GT(entry.second, 0);
total += entry.second;
}
BOOST_CHECK_EQUAL(total, names.size());
+
+ benchPolicy(pol);
}
#endif /* LUAJIT_VERSION */