Kea 2.0.0
cql_host_data_source_benchmark.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
2// Copyright (C) 2017 Deutsche Telekom AG.
3//
4// Authors: Andrei Pavel <andrei.pavel@qualitance.com>
5//
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18#include <config.h>
19
20#include <cql/testutils/cql_schema.h>
21
25#include <dhcpsrv/host_mgr.h>
26
27#include <iostream>
28
29using namespace isc::db::test;
30using namespace isc::dhcp;
31using namespace isc::dhcp::bench;
32using namespace std;
33
34namespace {
35
37class CqlHostDataSourceBenchmark : public GenericHostDataSourceBenchmark {
38public:
42 void SetUp(::benchmark::State const&) override {
43 // Ensure we have the proper schema with no transient data.
44 createCqlSchema();
45 try {
47 HostMgr::addBackend(validCqlConnectionString());
48 } catch (...) {
49 cerr << "ERROR: unable to open database" << endl;
50 throw;
51 }
53 }
54
55 void SetUp(::benchmark::State& s) override {
56 ::benchmark::State const& cs = s;
57 SetUp(cs);
58 }
59
61 void TearDown(::benchmark::State const&) override {
62 try {
63 hdsptr_->rollback();
64 } catch (...) {
65 cerr << "WARNING: rollback has failed, this is expected if database"
66 " is opened in read-only mode, continuing..."
67 << endl;
68 }
70 // If data wipe enabled, delete transient data otherwise destroy the schema
71 destroyCqlSchema(false, true);
72 }
73
74 void TearDown(::benchmark::State& s) override {
75 ::benchmark::State const& cs = s;
76 TearDown(cs);
77 }
78};
79
82BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, insertHosts)(benchmark::State& state) {
83 const size_t host_count = state.range(0);
84 while (state.KeepRunning()) {
85 setUp(state, host_count);
86 insertHosts();
87 }
88}
89
92BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, getAll)(benchmark::State& state) {
93 const size_t host_count = state.range(0);
94 while (state.KeepRunning()) {
95 setUpWithInserts(state, host_count);
96 benchGetAll();
97 }
98}
99
102BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, getAllv4Resv)(benchmark::State& state) {
103 const size_t host_count = state.range(0);
104 while (state.KeepRunning()) {
105 setUpWithInserts(state, host_count);
106 getAllv4Resv();
107 }
108}
109
112BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get4IdentifierSubnetId)(benchmark::State& state) {
113 const size_t host_count = state.range(0);
114 while (state.KeepRunning()) {
115 setUpWithInserts(state, host_count);
116 benchGet4IdentifierSubnetId();
117 }
118}
119
122BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get4SubnetIdv4Resrv)(benchmark::State& state) {
123 const size_t host_count = state.range(0);
124 while (state.KeepRunning()) {
125 setUpWithInserts(state, host_count);
126 benchGet4SubnetIdv4Resrv();
127 }
128}
129
132BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get6IdentifierSubnetId)(benchmark::State& state) {
133 const size_t host_count = state.range(0);
134 while (state.KeepRunning()) {
135 setUpWithInserts(state, host_count);
136 benchGet6IdentifierSubnetId();
137 }
138}
139
142BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get6SubnetIdAddr)(benchmark::State& state) {
143 const size_t host_count = state.range(0);
144 while (state.KeepRunning()) {
145 setUpWithInserts(state, host_count);
146 benchGet6SubnetIdAddr();
147 }
148}
149
152BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get6Prefix)(benchmark::State& state) {
153 const size_t host_count = state.range(0);
154 while (state.KeepRunning()) {
155 setUpWithInserts(state, host_count);
156 benchGet6Prefix();
157 }
158}
159
162BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, insertHosts)
163 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
164
167BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, getAll)
168 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
169
172BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, getAllv4Resv)
173 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
174
177BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, get4IdentifierSubnetId)
178 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
179
182BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, get4SubnetIdv4Resrv)
183 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
184
187BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, get6IdentifierSubnetId)
188 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
189
192BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, get6SubnetIdAddr)
193 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
194
197BENCHMARK_REGISTER_F(CqlHostDataSourceBenchmark, get6Prefix)
198 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
199
200} // namespace
static void create()
Creates new instance of the HostMgr.
Definition: host_mgr.cc:43
static bool delBackend(const std::string &db_type)
Delete an alternate host backend (aka host data source).
Definition: host_mgr.cc:53
static void addBackend(const std::string &access)
Add an alternate host backend (aka host data source).
Definition: host_mgr.cc:48
HostDataSourcePtr getHostDataSource() const
Returns the first host data source.
Definition: host_mgr.cc:75
static HostMgr & instance()
Returns a sole instance of the HostMgr.
Definition: host_mgr.cc:105
Base fixture class for benchmarking host backends.
constexpr size_t MIN_HOST_COUNT
A minimum number of leases used in a benchmark.
Definition: parameters.h:30
constexpr benchmark::TimeUnit UNIT
A time unit used - all results to be expressed in us (microseconds)
Definition: parameters.h:35
constexpr size_t MAX_HOST_COUNT
A maximum number of leases used in a benchmark.
Definition: parameters.h:32