From: Razvan Becheriu Date: Mon, 4 Mar 2019 15:07:44 +0000 (+0200) Subject: fixed benchmarks X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=28204380c786af38418a6cebc933d37abb725ab8;p=thirdparty%2Fkea.git fixed benchmarks --- diff --git a/configure.ac b/configure.ac index 25323f8baf..ccb930644a 100644 --- a/configure.ac +++ b/configure.ac @@ -928,8 +928,8 @@ if test "$SYSREPO_CONFIG" != "" ; then ) AC_LINK_IFELSE( - [AC_LANG_PROGRAM([#include ], - [Connection("conn-name");])], + [AC_LANG_PROGRAM([#include ], + [sysrepo::Connection("conn-name");])], [AC_MSG_RESULT([checking for Sysrepo C++ bindings headers and library... yes])], [AC_MSG_RESULT([checking for Sysrepo C++ bindings headers and library... no]) AC_MSG_ERROR([Needs Sysrepo C++ bindings (unable to find Sysrepo-ccp library. To get it, you need to compile sysrepo with -DGEN_CPP_BINDINGS=ON.])] diff --git a/src/lib/dhcpsrv/benchmarks/cql_host_data_source_benchmark.cc b/src/lib/dhcpsrv/benchmarks/cql_host_data_source_benchmark.cc index f0223012be..bfe54e45de 100644 --- a/src/lib/dhcpsrv/benchmarks/cql_host_data_source_benchmark.cc +++ b/src/lib/dhcpsrv/benchmarks/cql_host_data_source_benchmark.cc @@ -17,23 +17,24 @@ #include +#include + #include #include #include -#include +#include + #include -using namespace isc::dhcp::bench; -using namespace isc::dhcp::test; +using namespace isc::db::test; using namespace isc::dhcp; +using namespace isc::dhcp::bench; using namespace std; namespace { /// @brief This is a fixture class used for benchmarking Cassandra host backend -class CqlHostDataSourceBenchmark : public GenericHostDataSourceBenchmark { -public: - +struct CqlHostDataSourceBenchmark : public GenericHostDataSourceBenchmark { /// @brief Setup routine. /// /// It cleans up schema and recreates tables, then instantiates HostMgr @@ -41,13 +42,18 @@ public: destroyCqlSchema(false, true); createCqlSchema(false, true); try { - HostDataSourceFactory::destroy(); - HostDataSourceFactory::create(validCqlConnectionString()); + HostMgr::delBackend("cql"); + HostMgr::addBackend(validCqlConnectionString()); } catch (...) { cerr << "ERROR: unable to open database" << endl; throw; } - hdsptr_ = HostDataSourceFactory::getHostDataSourcePtr(); + hdsptr_ = HostMgr::instance().getHostDataSource(); + } + + void SetUp(::benchmark::State& s) override { + ::benchmark::State const& cs = s; + SetUp(cs); } /// @brief Cleans up after the test. @@ -59,9 +65,14 @@ public: " is opened in read-only mode, continuing..." << endl; } - HostDataSourceFactory::destroy(); + HostMgr::delBackend("cql"); destroyCqlSchema(false, true); } + + void TearDown(::benchmark::State& s) override { + ::benchmark::State const& cs = s; + TearDown(cs); + } }; /// Defines steps necessary for conducting a benchmark that measures @@ -84,16 +95,6 @@ BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, updateHosts)(benchmark::State& st } } -/// Defines steps necessary for conducting a benchmark that measures -/// hosts retrieval by getAll(hw-addr, duid) call. -BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, getAllByHWAddrDuid)(benchmark::State& state) { - const size_t host_count = state.range(0); - while (state.KeepRunning()) { - setUpWithInserts(state, host_count); - benchGetAllByHWAddrDuid(); - } -} - /// Defines steps necessary for conducting a benchmark that measures /// hosts retrieval by getAll4(hw-addr, duid) call. BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, getAll)(benchmark::State& state) { @@ -114,16 +115,6 @@ BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, getAllv4Resv)(benchmark::State& s } } -/// Defines steps necessary for conducting a benchmark that measures -/// hosts retrieval by get4(subnet-id, hw-addr, duid) call. -BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get4BySubnetHWAddrDuid)(benchmark::State& state) { - const size_t host_count = state.range(0); - while (state.KeepRunning()) { - setUpWithInserts(state, host_count); - benchGet4BySubnetHWAddrDuid(); - } -} - /// Defines steps necessary for conducting a benchmark that measures /// hosts retrieval by get4(identifier-type, identifier, subnet-id) call. BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get4IdentifierSubnetId)(benchmark::State& state) { @@ -144,16 +135,6 @@ BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get4SubnetIdv4Resrv)(benchmark::S } } -/// Defines steps necessary for conducting a benchmark that measures -/// hosts retrieval by get6(subnet-id, duid, hw-addr) call. -BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get6SubnetIdDuidHWAddr)(benchmark::State& state) { - const size_t host_count = state.range(0); - while (state.KeepRunning()) { - setUpWithInserts(state, host_count); - benchGet6SubnetIdDuidHWAddr(); - } -} - /// Defines steps necessary for conducting a benchmark that measures /// hosts retrieval by get6(subnet-id, identifier-type, identifier) call. BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get6IdentifierSubnetId)(benchmark::State& state) { @@ -187,61 +168,55 @@ BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get6Prefix)(benchmark::State& sta /// Defines parameters necessary for running a benchmark that measures /// hosts insertion. BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, insertHosts) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts update. BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, updateHosts) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); - -/// Defines parameters necessary for running a benchmark that measures -/// hosts retrieval by getAll(hw-addr, duid) call. -BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, getAllByHWAddrDuid) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by getAll4(hw-addr, duid) call. BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, getAll) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by getAll(v4-reservation) call. BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, getAllv4Resv) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); - -/// Defines parameters necessary for running a benchmark that measures -/// hosts retrieval by get4(subnet-id, hw-addr, duid) call. -BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, get4BySubnetHWAddrDuid) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by get4(identifier-type, identifier, subnet-id) call. BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, get4IdentifierSubnetId) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by get4(subnet-id, v4-reservation) call. BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, get4SubnetIdv4Resrv) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); - -/// Defines parameters necessary for running a benchmark that measures -/// hosts retrieval by get6(subnet-id, duid, hw-addr) call. -BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, get6SubnetIdDuidHWAddr) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by get6(subnet-id, identifier-type, identifier) call. BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, get6IdentifierSubnetId) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by get6(subnet-id, ip-address) call. BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, get6SubnetIdAddr) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by get6(ip-prefix, prefix-len) call. BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, get6Prefix) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); } // namespace diff --git a/src/lib/dhcpsrv/benchmarks/cql_lease_mgr_benchmark.cc b/src/lib/dhcpsrv/benchmarks/cql_lease_mgr_benchmark.cc index 2179f6415f..493189e7c8 100644 --- a/src/lib/dhcpsrv/benchmarks/cql_lease_mgr_benchmark.cc +++ b/src/lib/dhcpsrv/benchmarks/cql_lease_mgr_benchmark.cc @@ -17,21 +17,21 @@ #include +#include + #include #include #include -#include +using namespace isc::db::test; using namespace isc::dhcp::bench; -using namespace isc::dhcp::test; using namespace isc::dhcp; using namespace std; namespace { /// @brief This is a fixture class used for benchmarking Cassandra lease backend -class CqlLeaseMgrBenchmark : public GenericLeaseMgrBenchmark { -public: +struct CqlLeaseMgrBenchmark : public GenericLeaseMgrBenchmark { /// @brief Setup routine. /// /// It cleans up schema and recreates tables, then instantiates LeaseMgr @@ -48,6 +48,11 @@ public: lmptr_ = &(LeaseMgrFactory::instance()); } + void SetUp(::benchmark::State& s) override { + ::benchmark::State const& cs = s; + SetUp(cs); + } + /// @brief Cleans up after the test. void TearDown(::benchmark::State const&) override { try { @@ -60,6 +65,13 @@ public: LeaseMgrFactory::destroy(); destroyCqlSchema(false, true); } + + void TearDown(::benchmark::State& s) override { + ::benchmark::State const& cs = s; + TearDown(cs); + } + + }; // Defines a benchmark that measures IPv4 leases insertion. @@ -175,7 +187,7 @@ BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease6_type_duid_iaid)(benchmark::St // Defines a benchmark that measures IPv6 leases retrieval by lease type, duid, iaid // and subnet-id. BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid) - (benchmark::State& state) { +(benchmark::State& state) { const size_t lease_count = state.range(0); while (state.KeepRunning()) { setUpWithInserts6(state, lease_count); @@ -192,66 +204,79 @@ BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getExpiredLeases6)(benchmark::State& st } } - /// The following macros define run parameters for previously defined /// Cassandra benchmarks. /// A benchmark that measures IPv4 leases insertion. BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, insertLeases4) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 leases update. BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, updateLeases4) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by IP address. BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_address) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by hardware address. BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_hwaddr) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by hardware address and a /// subnet-id. BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_hwaddr_subnetid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by client-id. BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_clientid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by client-id and subnet-id. BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_clientid_subnetid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures expired IPv4 leases retrieval. BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getExpiredLeases4) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 leases insertion. BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, insertLeases6) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 leases update. BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, updateLeases6) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 lease retrieval by lease type and IP address. BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease6_type_address) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 lease retrieval by lease type, duid and iaid. BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease6_type_duid_iaid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 lease retrieval by lease type, duid, iaid and /// subnet-id. BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures expired IPv6 leases retrieval. BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getExpiredLeases6) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); } // namespace diff --git a/src/lib/dhcpsrv/benchmarks/generic_host_data_source_benchmark.cc b/src/lib/dhcpsrv/benchmarks/generic_host_data_source_benchmark.cc index ed944b0871..9c899b79bf 100644 --- a/src/lib/dhcpsrv/benchmarks/generic_host_data_source_benchmark.cc +++ b/src/lib/dhcpsrv/benchmarks/generic_host_data_source_benchmark.cc @@ -189,14 +189,6 @@ GenericHostDataSourceBenchmark::updateHosts() { } } -void -GenericHostDataSourceBenchmark::benchGetAllByHWAddrDuid() { - for (HostPtr host : hosts_) { - ConstHostCollection from_hds = - hdsptr_->getAll(host->getHWAddress(), host->getDuid()); - } -} - void GenericHostDataSourceBenchmark::benchGetAll() { for (HostPtr host : hosts_) { @@ -212,15 +204,6 @@ GenericHostDataSourceBenchmark::getAllv4Resv() { } } -void -GenericHostDataSourceBenchmark::benchGet4BySubnetHWAddrDuid() { - for (HostPtr host : hosts_) { - std::vector hwaddr = host->getIdentifier(); - hdsptr_->get4(host->getIPv4SubnetID(), HWAddrPtr(new HWAddr(hwaddr, - host->getIdentifierType())), host->getDuid()); - } -} - void GenericHostDataSourceBenchmark::benchGet4IdentifierSubnetId() { for (HostPtr host : hosts_) { @@ -237,14 +220,6 @@ GenericHostDataSourceBenchmark::benchGet4SubnetIdv4Resrv() { } } -void -GenericHostDataSourceBenchmark::benchGet6SubnetIdDuidHWAddr() { - for (HostPtr host : hosts_) { - hdsptr_->get6(host->getIPv6SubnetID(), host->getDuid(), - host->getHWAddress()); - } -} - void GenericHostDataSourceBenchmark::benchGet6IdentifierSubnetId() { for (HostPtr host : hosts_) { diff --git a/src/lib/dhcpsrv/benchmarks/generic_host_data_source_benchmark.h b/src/lib/dhcpsrv/benchmarks/generic_host_data_source_benchmark.h index 8521bcb09e..ceb6b4c7f6 100644 --- a/src/lib/dhcpsrv/benchmarks/generic_host_data_source_benchmark.h +++ b/src/lib/dhcpsrv/benchmarks/generic_host_data_source_benchmark.h @@ -184,8 +184,6 @@ public: /// @brief Updates all hosts stored in hosts_ in the benchmarked host backend void updateHosts(); - void benchGetAllByHWAddrDuid(); - /// @brief Essential steps required to benchmark the /// getAll(identifier-type, identifier) call. void benchGetAll(); @@ -194,10 +192,6 @@ public: /// using getAll(ipv4-reservation) call. void getAllv4Resv(); - /// @brief Essential steps requires to benchmark host reservation retrieval - /// using getAll(hw-addr, duid) call. - void benchGet4BySubnetHWAddrDuid(); - /// @brief Essential steps requires to benchmark host reservation retrieval /// using getAll(identifier-type, identifier, subnet-id) call. void benchGet4IdentifierSubnetId(); @@ -206,10 +200,6 @@ public: /// using getAll(v4-reservation) call. void benchGet4SubnetIdv4Resrv(); - /// @brief Essential steps requires to benchmark host reservation retrieval - /// using get6(subnet-id, duid, hw-addr) call. - void benchGet6SubnetIdDuidHWAddr(); - /// @brief Essential steps requires to benchmark host reservation retrieval /// using get6(identifier-type, identifier, subnet-id) call. void benchGet6IdentifierSubnetId(); diff --git a/src/lib/dhcpsrv/benchmarks/memfile_lease_mgr_benchmark.cc b/src/lib/dhcpsrv/benchmarks/memfile_lease_mgr_benchmark.cc index ce6e738af5..2afe5f4205 100644 --- a/src/lib/dhcpsrv/benchmarks/memfile_lease_mgr_benchmark.cc +++ b/src/lib/dhcpsrv/benchmarks/memfile_lease_mgr_benchmark.cc @@ -8,8 +8,8 @@ #include #include -#include #include +#include #include using namespace isc::dhcp::bench; @@ -20,14 +20,11 @@ using namespace std; namespace { /// @brief This is a fixture class used for benchmarking Memfile lease backend -class MemfileLeaseMgrBenchmark : public GenericLeaseMgrBenchmark { -public: - +struct MemfileLeaseMgrBenchmark : public GenericLeaseMgrBenchmark { /// @brief Constructor /// /// Sets the files used for writing lease files. - MemfileLeaseMgrBenchmark() - : io4_(""), io6_("") { + MemfileLeaseMgrBenchmark() : io4_(""), io6_("") { } /// @brief Setup routine. @@ -54,6 +51,11 @@ public: lmptr_ = &(LeaseMgrFactory::instance()); } + void SetUp(::benchmark::State& s) override { + ::benchmark::State const& cs = s; + SetUp(cs); + } + /// @brief Creates instance of the backend. /// /// @param u Universe (v4 or V6). @@ -62,7 +64,7 @@ public: LeaseMgrFactory::create(getConfigString(u)); } catch (...) { std::cerr << "*** ERROR: unable to create instance of the Memfile\n" - " lease database backend.\n"; + " lease database backend.\n"; throw; } lmptr_ = &(LeaseMgrFactory::instance()); @@ -80,8 +82,8 @@ public: /// @return Configuration string for @c LeaseMgrFactory. static std::string getConfigString(Universe u) { std::ostringstream s; - s << "type=memfile " << (u == V4 ? "universe=4 " : "universe=6 ") << "name=" - << getLeaseFilePath(u == V4 ? "leasefile4_0.csv" : "leasefile6_0.csv") + s << "type=memfile " << (u == V4 ? "universe=4 " : "universe=6 ") + << "name=" << getLeaseFilePath(u == V4 ? "leasefile4_0.csv" : "leasefile6_0.csv") << " lfc-interval=0"; return (s.str()); } @@ -125,7 +127,8 @@ public: lmptr_->rollback(); } catch (...) { std::cerr << "WARNING: rollback has failed. This is surprising as " - "memfile doesn't support rollback." << std::endl; + "memfile doesn't support rollback." + << std::endl; } LeaseMgrFactory::destroy(); @@ -135,6 +138,11 @@ public: removeFiles(getLeaseFilePath("leasefile6_0.csv")); } + void TearDown(::benchmark::State& s) override { + ::benchmark::State const& cs = s; + TearDown(cs); + } + /// @brief Object providing access to v4 lease IO. LeaseFileIO io4_; @@ -255,7 +263,7 @@ BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease6_type_duid_iaid)(benchmark // Defines a benchmark that measures IPv6 leases retrieval by lease type, duid, iaid // and subnet-id. BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid) - (benchmark::State& state) { +(benchmark::State& state) { const size_t lease_count = state.range(0); while (state.KeepRunning()) { setUpWithInserts6(state, lease_count); @@ -272,66 +280,79 @@ BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getExpiredLeases6)(benchmark::State } } - /// The following macros define run parameters for previously defined /// memfile benchmarks. /// A benchmark that measures IPv4 leases insertion. BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, insertLeases4) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 leases update. BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, updateLeases4) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by IP address. BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getLease4_address) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by hardware address. BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getLease4_hwaddr) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by hardware address and a /// subnet-id. BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getLease4_hwaddr_subnetid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by client-id. BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getLease4_clientid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by client-id and subnet-id. BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getLease4_clientid_subnetid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures expired IPv4 leases retrieval. BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getExpiredLeases4) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 leases insertion. BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, insertLeases6) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 leases update. BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, updateLeases6) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 lease retrieval by lease type and IP address. BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getLease6_type_address) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 lease retrieval by lease type, duid and iaid. BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getLease6_type_duid_iaid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 lease retrieval by lease type, duid, iaid and /// subnet-id. BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures expired IPv6 leases retrieval. BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getExpiredLeases6) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); } // namespace diff --git a/src/lib/dhcpsrv/benchmarks/mysql_host_data_source_benchmark.cc b/src/lib/dhcpsrv/benchmarks/mysql_host_data_source_benchmark.cc index a06e9b788f..1ca163461a 100644 --- a/src/lib/dhcpsrv/benchmarks/mysql_host_data_source_benchmark.cc +++ b/src/lib/dhcpsrv/benchmarks/mysql_host_data_source_benchmark.cc @@ -17,37 +17,43 @@ #include +#include + #include #include #include -#include +#include + #include -using namespace isc::dhcp::bench; -using namespace isc::dhcp::test; +using namespace isc::db::test; using namespace isc::dhcp; +using namespace isc::dhcp::bench; using namespace std; namespace { /// @brief This is a fixture class used for benchmarking MySQL host backend -class MySqlHostDataSourceBenchmark : public GenericHostDataSourceBenchmark { -public: - +struct MySqlHostDataSourceBenchmark : public GenericHostDataSourceBenchmark { /// @brief Setup routine. /// /// It cleans up schema and recreates tables, then instantiates HostMgr void SetUp(::benchmark::State const&) override { - destroyMySQLSchema(false); - createMySQLSchema(false); + destroyMySQLSchema(); + createMySQLSchema(); try { - HostDataSourceFactory::destroy(); - HostDataSourceFactory::create(validMySQLConnectionString()); + HostMgr::delBackend("mysql"); + HostMgr::addBackend(validMySQLConnectionString()); } catch (...) { cerr << "ERROR: unable to open database" << endl; throw; } - hdsptr_ = HostDataSourceFactory::getHostDataSourcePtr(); + hdsptr_ = HostMgr::instance().getHostDataSource(); + } + + void SetUp(::benchmark::State& s) override { + ::benchmark::State const& cs = s; + SetUp(cs); } /// @brief Cleans up after the test. @@ -59,8 +65,13 @@ public: " is opened in read-only mode, continuing..." << endl; } - HostDataSourceFactory::destroy(); - destroyMySQLSchema(false); + HostMgr::delBackend("mysql"); + destroyMySQLSchema(); + } + + void TearDown(::benchmark::State& s) override { + ::benchmark::State const& cs = s; + TearDown(cs); } }; @@ -84,16 +95,6 @@ BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, updateHosts)(benchmark::State& } } -/// Defines steps necessary for conducting a benchmark that measures -/// hosts retrieval by getAll(hw-addr, duid) call. -BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, getAllByHWAddrDuid)(benchmark::State& state) { - const size_t host_count = state.range(0); - while (state.KeepRunning()) { - setUpWithInserts(state, host_count); - benchGetAllByHWAddrDuid(); - } -} - /// Defines steps necessary for conducting a benchmark that measures /// hosts retrieval by getAll4(hw-addr, duid) call. BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, getAll)(benchmark::State& state) { @@ -114,16 +115,6 @@ BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, getAllv4Resv)(benchmark::State& } } -/// Defines steps necessary for conducting a benchmark that measures -/// hosts retrieval by get4(subnet-id, hw-addr, duid) call. -BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get4BySubnetHWAddrDuid)(benchmark::State& state) { - const size_t host_count = state.range(0); - while (state.KeepRunning()) { - setUpWithInserts(state, host_count); - benchGet4BySubnetHWAddrDuid(); - } -} - /// Defines steps necessary for conducting a benchmark that measures /// hosts retrieval by get4(identifier-type, identifier, subnet-id) call. BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get4IdentifierSubnetId)(benchmark::State& state) { @@ -144,16 +135,6 @@ BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get4SubnetIdv4Resrv)(benchmark: } } -/// Defines steps necessary for conducting a benchmark that measures -/// hosts retrieval by get6(subnet-id, duid, hw-addr) call. -BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get6SubnetIdDuidHWAddr)(benchmark::State& state) { - const size_t host_count = state.range(0); - while (state.KeepRunning()) { - setUpWithInserts(state, host_count); - benchGet6SubnetIdDuidHWAddr(); - } -} - /// Defines steps necessary for conducting a benchmark that measures /// hosts retrieval by get6(subnet-id, identifier-type, identifier) call. BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get6IdentifierSubnetId)(benchmark::State& state) { @@ -187,61 +168,55 @@ BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get6Prefix)(benchmark::State& s /// Defines parameters necessary for running a benchmark that measures /// hosts insertion. BENCHMARK_REGISTER_F(MySqlHostDataSourceBenchmark, insertHosts) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts update. BENCHMARK_REGISTER_F(MySqlHostDataSourceBenchmark, updateHosts) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); - -/// Defines parameters necessary for running a benchmark that measures -/// hosts retrieval by getAll(hw-addr, duid) call. -BENCHMARK_REGISTER_F(MySqlHostDataSourceBenchmark, getAllByHWAddrDuid) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by getAll4(hw-addr, duid) call. BENCHMARK_REGISTER_F(MySqlHostDataSourceBenchmark, getAll) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by getAll(v4-reservation) call. BENCHMARK_REGISTER_F(MySqlHostDataSourceBenchmark, getAllv4Resv) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); - -/// Defines parameters necessary for running a benchmark that measures -/// hosts retrieval by get4(subnet-id, hw-addr, duid) call. -BENCHMARK_REGISTER_F(MySqlHostDataSourceBenchmark, get4BySubnetHWAddrDuid) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by get4(identifier-type, identifier, subnet-id) call. BENCHMARK_REGISTER_F(MySqlHostDataSourceBenchmark, get4IdentifierSubnetId) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by get4(subnet-id, v4-reservation) call. BENCHMARK_REGISTER_F(MySqlHostDataSourceBenchmark, get4SubnetIdv4Resrv) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); - -/// Defines parameters necessary for running a benchmark that measures -/// hosts retrieval by get6(subnet-id, duid, hw-addr) call. -BENCHMARK_REGISTER_F(MySqlHostDataSourceBenchmark, get6SubnetIdDuidHWAddr) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by get6(subnet-id, identifier-type, identifier) call. BENCHMARK_REGISTER_F(MySqlHostDataSourceBenchmark, get6IdentifierSubnetId) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by get6(subnet-id, ip-address) call. BENCHMARK_REGISTER_F(MySqlHostDataSourceBenchmark, get6SubnetIdAddr) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by get6(ip-prefix, prefix-len) call. BENCHMARK_REGISTER_F(MySqlHostDataSourceBenchmark, get6Prefix) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); } // namespace diff --git a/src/lib/dhcpsrv/benchmarks/mysql_lease_mgr_benchmark.cc b/src/lib/dhcpsrv/benchmarks/mysql_lease_mgr_benchmark.cc index c856a25ac9..cb93c1e447 100644 --- a/src/lib/dhcpsrv/benchmarks/mysql_lease_mgr_benchmark.cc +++ b/src/lib/dhcpsrv/benchmarks/mysql_lease_mgr_benchmark.cc @@ -20,24 +20,24 @@ #include #include #include -#include -using namespace isc::dhcp::bench; -using namespace isc::dhcp::test; +#include + +using namespace isc::db::test; using namespace isc::dhcp; +using namespace isc::dhcp::bench; using namespace std; namespace { /// @brief This is a fixture class used for benchmarking MySQL lease backend -class MySqlLeaseMgrBenchmark : public GenericLeaseMgrBenchmark { -public: +struct MySqlLeaseMgrBenchmark : public GenericLeaseMgrBenchmark { /// @brief Setup routine. /// /// It cleans up schema and recreates tables, then instantiates LeaseMgr void SetUp(::benchmark::State const&) override { - destroyMySQLSchema(false); - createMySQLSchema(false); + destroyMySQLSchema(); + createMySQLSchema(); try { LeaseMgrFactory::destroy(); LeaseMgrFactory::create(validMySQLConnectionString()); @@ -48,6 +48,11 @@ public: lmptr_ = &(LeaseMgrFactory::instance()); } + void SetUp(::benchmark::State& s) override { + ::benchmark::State const& cs = s; + SetUp(cs); + } + /// @brief Cleans up after the test. void TearDown(::benchmark::State const&) override { try { @@ -58,7 +63,12 @@ public: << endl; } LeaseMgrFactory::destroy(); - destroyMySQLSchema(false); + destroyMySQLSchema(); + } + + void TearDown(::benchmark::State& s) override { + ::benchmark::State const& cs = s; + TearDown(cs); } }; @@ -175,7 +185,7 @@ BENCHMARK_DEFINE_F(MySqlLeaseMgrBenchmark, getLease6_type_duid_iaid)(benchmark:: // Defines a benchmark that measures IPv6 leases retrieval by lease type, duid, iaid // and subnet-id. BENCHMARK_DEFINE_F(MySqlLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid) - (benchmark::State& state) { +(benchmark::State& state) { const size_t lease_count = state.range(0); while (state.KeepRunning()) { setUpWithInserts6(state, lease_count); @@ -192,66 +202,79 @@ BENCHMARK_DEFINE_F(MySqlLeaseMgrBenchmark, getExpiredLeases6)(benchmark::State& } } - /// The following macros define run parameters for previously defined /// MySQL benchmarks. /// A benchmark that measures IPv4 leases insertion. BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, insertLeases4) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 leases update. BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, updateLeases4) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by IP address. BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease4_address) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by hardware address. BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease4_hwaddr) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by hardware address and a /// subnet-id. BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease4_hwaddr_subnetid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by client-id. BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease4_clientid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by client-id and subnet-id. BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease4_clientid_subnetid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures expired IPv4 leases retrieval. BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getExpiredLeases4) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 leases insertion. BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, insertLeases6) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 leases update. BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, updateLeases6) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 lease retrieval by lease type and IP address. BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease6_type_address) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 lease retrieval by lease type, duid and iaid. BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease6_type_duid_iaid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 lease retrieval by lease type, duid, iaid and /// subnet-id. BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures expired IPv6 leases retrieval. BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getExpiredLeases6) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); } // namespace diff --git a/src/lib/dhcpsrv/benchmarks/parameters.h b/src/lib/dhcpsrv/benchmarks/parameters.h index 2de54f93ce..2f54c28351 100644 --- a/src/lib/dhcpsrv/benchmarks/parameters.h +++ b/src/lib/dhcpsrv/benchmarks/parameters.h @@ -26,7 +26,7 @@ constexpr size_t MIN_LEASE_COUNT = 512; /// @brief A maximum number of leases used in a benchmark constexpr size_t MAX_LEASE_COUNT = 0xfffd; - /// @brief A minimum number of leases used in a benchmark +/// @brief A minimum number of leases used in a benchmark constexpr size_t MIN_HOST_COUNT = 512; /// @brief A maximum number of leases used in a benchmark constexpr size_t MAX_HOST_COUNT = 0xfffd; @@ -36,8 +36,8 @@ constexpr benchmark::TimeUnit UNIT = benchmark::kMicrosecond; /// @} -} -} -} +} // namespace bench +} // namespace dhcp +} // namespace isc #endif diff --git a/src/lib/dhcpsrv/benchmarks/pgsql_host_data_source_benchmark.cc b/src/lib/dhcpsrv/benchmarks/pgsql_host_data_source_benchmark.cc index 9dfd14299a..ae2e4a2805 100644 --- a/src/lib/dhcpsrv/benchmarks/pgsql_host_data_source_benchmark.cc +++ b/src/lib/dhcpsrv/benchmarks/pgsql_host_data_source_benchmark.cc @@ -20,34 +20,40 @@ #include #include #include -#include +#include + +#include + #include +using namespace isc::db::test; using namespace isc::dhcp::bench; -using namespace isc::dhcp::test; using namespace isc::dhcp; using namespace std; namespace { /// @brief This is a fixture class used for benchmarking PostgreSQL host backend -class PgSqlHostDataSourceBenchmark : public GenericHostDataSourceBenchmark { -public: - +struct PgSqlHostDataSourceBenchmark : public GenericHostDataSourceBenchmark { /// @brief Setup routine. /// /// It cleans up schema and recreates tables, then instantiates HostMgr void SetUp(::benchmark::State const&) override { - destroyPgSQLSchema(false); - createPgSQLSchema(false); + destroyPgSQLSchema(); + createPgSQLSchema(); try { - HostDataSourceFactory::destroy(); - HostDataSourceFactory::create(validPgSQLConnectionString()); + HostMgr::delBackend("postgresql"); + HostMgr::addBackend(validPgSQLConnectionString()); } catch (...) { cerr << "ERROR: unable to open database" << endl; throw; } - hdsptr_ = HostDataSourceFactory::getHostDataSourcePtr(); + hdsptr_ = HostMgr::instance().getHostDataSource(); + } + + void SetUp(::benchmark::State& s) override { + ::benchmark::State const& cs = s; + SetUp(cs); } /// @brief Cleans up after the test. @@ -59,8 +65,13 @@ public: " is opened in read-only mode, continuing..." << endl; } - HostDataSourceFactory::destroy(); - destroyPgSQLSchema(false); + HostMgr::delBackend("postgresql"); + destroyPgSQLSchema(); + } + + void TearDown(::benchmark::State& s) override { + ::benchmark::State const& cs = s; + TearDown(cs); } }; @@ -84,16 +95,6 @@ BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, updateHosts)(benchmark::State& } } -/// Defines steps necessary for conducting a benchmark that measures -/// hosts retrieval by getAll(hw-addr, duid) call. -BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, getAllByHWAddrDuid)(benchmark::State& state) { - const size_t host_count = state.range(0); - while (state.KeepRunning()) { - setUpWithInserts(state, host_count); - benchGetAllByHWAddrDuid(); - } -} - /// Defines steps necessary for conducting a benchmark that measures /// hosts retrieval by getAll4(hw-addr, duid) call. BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, getAll)(benchmark::State& state) { @@ -114,16 +115,6 @@ BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, getAllv4Resv)(benchmark::State& } } -/// Defines steps necessary for conducting a benchmark that measures -/// hosts retrieval by get4(subnet-id, hw-addr, duid) call. -BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get4BySubnetHWAddrDuid)(benchmark::State& state) { - const size_t host_count = state.range(0); - while (state.KeepRunning()) { - setUpWithInserts(state, host_count); - benchGet4BySubnetHWAddrDuid(); - } -} - /// Defines steps necessary for conducting a benchmark that measures /// hosts retrieval by get4(identifier-type, identifier, subnet-id) call. BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get4IdentifierSubnetId)(benchmark::State& state) { @@ -144,16 +135,6 @@ BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get4SubnetIdv4Resrv)(benchmark: } } -/// Defines steps necessary for conducting a benchmark that measures -/// hosts retrieval by get6(subnet-id, duid, hw-addr) call. -BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get6SubnetIdDuidHWAddr)(benchmark::State& state) { - const size_t host_count = state.range(0); - while (state.KeepRunning()) { - setUpWithInserts(state, host_count); - benchGet6SubnetIdDuidHWAddr(); - } -} - /// Defines steps necessary for conducting a benchmark that measures /// hosts retrieval by get6(subnet-id, identifier-type, identifier) call. BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get6IdentifierSubnetId)(benchmark::State& state) { @@ -187,61 +168,55 @@ BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get6Prefix)(benchmark::State& s /// Defines parameters necessary for running a benchmark that measures /// hosts insertion. BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, insertHosts) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts update. BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, updateHosts) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); - -/// Defines parameters necessary for running a benchmark that measures -/// hosts retrieval by getAll(hw-addr, duid) call. -BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, getAllByHWAddrDuid) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by getAll4(hw-addr, duid) call. BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, getAll) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by getAll(v4-reservation) call. BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, getAllv4Resv) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); - -/// Defines parameters necessary for running a benchmark that measures -/// hosts retrieval by get4(subnet-id, hw-addr, duid) call. -BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, get4BySubnetHWAddrDuid) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by get4(identifier-type, identifier, subnet-id) call. BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, get4IdentifierSubnetId) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by get4(subnet-id, v4-reservation) call. BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, get4SubnetIdv4Resrv) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); - -/// Defines parameters necessary for running a benchmark that measures -/// hosts retrieval by get6(subnet-id, duid, hw-addr) call. -BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, get6SubnetIdDuidHWAddr) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by get6(subnet-id, identifier-type, identifier) call. BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, get6IdentifierSubnetId) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by get6(subnet-id, ip-address) call. BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, get6SubnetIdAddr) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); /// Defines parameters necessary for running a benchmark that measures /// hosts retrieval by get6(ip-prefix, prefix-len) call. BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, get6Prefix) - ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT); + ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT) + ->Unit(UNIT); } // namespace diff --git a/src/lib/dhcpsrv/benchmarks/pgsql_lease_mgr_benchmark.cc b/src/lib/dhcpsrv/benchmarks/pgsql_lease_mgr_benchmark.cc index cad7acc978..7e21a14fd6 100644 --- a/src/lib/dhcpsrv/benchmarks/pgsql_lease_mgr_benchmark.cc +++ b/src/lib/dhcpsrv/benchmarks/pgsql_lease_mgr_benchmark.cc @@ -20,24 +20,24 @@ #include #include #include -#include -using namespace isc::dhcp::bench; -using namespace isc::dhcp::test; +#include + +using namespace isc::db::test; using namespace isc::dhcp; +using namespace isc::dhcp::bench; using namespace std; namespace { /// @brief This is a fixture class used for benchmarking PostgreSQL lease backend -class PgSqlLeaseMgrBenchmark : public GenericLeaseMgrBenchmark { -public: +struct PgSqlLeaseMgrBenchmark : public GenericLeaseMgrBenchmark { /// @brief Setup routine. /// /// It cleans up schema and recreates tables, then instantiates LeaseMgr void SetUp(::benchmark::State const&) override { - destroyPgSQLSchema(false); - createPgSQLSchema(false); + destroyPgSQLSchema(); + createPgSQLSchema(); try { LeaseMgrFactory::destroy(); LeaseMgrFactory::create(validPgSQLConnectionString()); @@ -48,6 +48,11 @@ public: lmptr_ = &(LeaseMgrFactory::instance()); } + void SetUp(::benchmark::State& s) override { + ::benchmark::State const& cs = s; + SetUp(cs); + } + /// @brief Cleans up after the test. void TearDown(::benchmark::State const&) override { try { @@ -58,7 +63,12 @@ public: << endl; } LeaseMgrFactory::destroy(); - destroyPgSQLSchema(false); + destroyPgSQLSchema(); + } + + void TearDown(::benchmark::State& s) override { + ::benchmark::State const& cs = s; + TearDown(cs); } }; @@ -175,7 +185,7 @@ BENCHMARK_DEFINE_F(PgSqlLeaseMgrBenchmark, getLease6_type_duid_iaid)(benchmark:: // Defines a benchmark that measures IPv6 leases retrieval by lease type, duid, iaid // and subnet-id. BENCHMARK_DEFINE_F(PgSqlLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid) - (benchmark::State& state) { +(benchmark::State& state) { const size_t lease_count = state.range(0); while (state.KeepRunning()) { setUpWithInserts6(state, lease_count); @@ -192,66 +202,79 @@ BENCHMARK_DEFINE_F(PgSqlLeaseMgrBenchmark, getExpiredLeases6)(benchmark::State& } } - /// The following macros define run parameters for previously defined /// PostgreSQL benchmarks. /// A benchmark that measures IPv4 leases insertion. BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, insertLeases4) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 leases update. BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, updateLeases4) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by IP address. BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease4_address) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by hardware address. BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease4_hwaddr) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by hardware address and a /// subnet-id. BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease4_hwaddr_subnetid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by client-id. BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease4_clientid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv4 lease retrieval by client-id and subnet-id. BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease4_clientid_subnetid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures expired IPv4 leases retrieval. BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getExpiredLeases4) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 leases insertion. BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, insertLeases6) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 leases update. BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, updateLeases6) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 lease retrieval by lease type and IP address. BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease6_type_address) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 lease retrieval by lease type, duid and iaid. BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease6_type_duid_iaid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures IPv6 lease retrieval by lease type, duid, iaid and /// subnet-id. BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); /// A benchmark that measures expired IPv6 leases retrieval. BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getExpiredLeases6) - ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT); + ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT) + ->Unit(UNIT); } // namespace diff --git a/src/lib/dhcpsrv/benchmarks/run_benchmarks.cc b/src/lib/dhcpsrv/benchmarks/run_benchmarks.cc index bcc4a536a9..35ac2c33b3 100644 --- a/src/lib/dhcpsrv/benchmarks/run_benchmarks.cc +++ b/src/lib/dhcpsrv/benchmarks/run_benchmarks.cc @@ -20,8 +20,7 @@ #include /// @brief A simple class that initializes logging. -class Initializer { -public: +struct Initializer { Initializer() { isc::log::initLogger(); } @@ -29,5 +28,4 @@ public: Initializer initializer; -BENCHMARK_MAIN() - +BENCHMARK_MAIN(); diff --git a/tools/sysrepo_config b/tools/sysrepo_config index 6da9404e63..db37e496b8 100755 --- a/tools/sysrepo_config +++ b/tools/sysrepo_config @@ -41,12 +41,13 @@ then echo " get version" echo "libraries:" echo " libsysrepo" + echo " libSysrepo-cpp" exit 0 else if [ $# -ne 2 ] then echo "run: \`$0 --help\` for more help" exit 0 - else if [ $2 != "libsysrepo" ] + else if [ $2 != "libsysrepo" ] && [ $2 != "libSysrepo-cpp" ] then echo "library $2 not supported" echo "run: \`$0 --help\` for more help" @@ -62,12 +63,12 @@ then fi if [ $1 == "--cflags-only-I" ] then - echo "-I${SYSREPO_PATH}/inc/" + echo "-I${SYSREPO_PATH}/include/" exit 0 fi if [ $1 == "--libs" ] then - echo "-L${SYSREPO_PATH}/build/src -L${SYSREPO_PATH}/build/swig -L$YANG_LIBRARY_PATH -l:${sysrepo_lib}.a -lSysrepo-cpp -lyang -pthread -lpcre -lev -lprotobuf -lavl -lprotobuf-c" + echo "-L${SYSREPO_PATH}/lib/ -L${YANG_LIBRARY_PATH} -lsysrepo -lSysrepo-cpp -lyang -pthread -lpcre -lev -lprotobuf -lavl -lprotobuf-c" exit 0 fi if [ $1 == "--modversion" ]