From: Remi Gacogne Date: Thu, 26 Dec 2019 15:37:29 +0000 (+0100) Subject: dnsdist: Bench LB policies X-Git-Tag: auth-4.3.0-beta2~1^2~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bf9c8b6c4a54f74bfa043a9cec48046ff3b0853f;p=thirdparty%2Fpdns.git dnsdist: Bench LB policies --- diff --git a/pdns/dnsdistdist/test-dnsdistlbpolicies_cc.cc b/pdns/dnsdistdist/test-dnsdistlbpolicies_cc.cc index 90a8ece93d..be75da1929 100644 --- a/pdns/dnsdistdist/test-dnsdistlbpolicies_cc.cc +++ b/pdns/dnsdistdist/test-dnsdistlbpolicies_cc.cc @@ -19,6 +19,15 @@ bool g_snmpEnabled{false}; 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> g_dynblockNMG; +GlobalStateHolder> g_dynblockSMT; +#endif /* BENCH_POLICIES */ + /* add stub implementations, we don't want to include the corresponding object files and their dependencies */ @@ -88,6 +97,35 @@ static DNSQuestion getDQ(const DNSName* providedName = nullptr) return dq; } +static void benchPolicy(const ServerPolicy& pol) +{ +#if BENCH_POLICIES + bool existingVerboseValue = g_verbose; + g_verbose = false; + + std::vector 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(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< names; + names.reserve(1000); + for (size_t idx = 0; idx < 1000; idx++) { + names.push_back(DNSName("powerdns-" + std::to_string(idx) + ".com.")); + } + std::map, uint64_t> serversMap; + for (size_t idx = 1; idx <= 10; idx++) { + servers.push_back({ idx, std::make_shared(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) { @@ -156,6 +208,8 @@ 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) { @@ -170,6 +224,8 @@ 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); @@ -234,12 +290,15 @@ BOOST_AUTO_TEST_CASE(test_whashed) { 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); @@ -317,12 +376,15 @@ BOOST_AUTO_TEST_CASE(test_chashed) { 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); @@ -415,6 +477,7 @@ BOOST_AUTO_TEST_CASE(test_lua) { BOOST_REQUIRE(serversMap.count(server) == 1); ++serversMap[server]; } + uint64_t total = 0; for (const auto& entry : serversMap) { BOOST_CHECK_GT(entry.second, 0); @@ -423,6 +486,8 @@ BOOST_AUTO_TEST_CASE(test_lua) { total += entry.second; } BOOST_CHECK_EQUAL(total, names.size()); + + benchPolicy(pol); } #ifdef LUAJIT_VERSION @@ -440,7 +505,8 @@ BOOST_AUTO_TEST_CASE(test_lua_ffi) { 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) @@ -468,6 +534,7 @@ BOOST_AUTO_TEST_CASE(test_lua_ffi) { BOOST_REQUIRE(serversMap.count(server) == 1); ++serversMap[server]; } + uint64_t total = 0; for (const auto& entry : serversMap) { BOOST_CHECK_GT(entry.second, 0); @@ -476,6 +543,8 @@ BOOST_AUTO_TEST_CASE(test_lua_ffi) { total += entry.second; } BOOST_CHECK_EQUAL(total, names.size()); + + benchPolicy(pol); } #endif /* LUAJIT_VERSION */