Kea 2.0.3
cql_lease_mgr_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
26using namespace isc::db::test;
27using namespace isc::dhcp;
28using namespace isc::dhcp::bench;
29using namespace std;
30
31namespace {
32
34class CqlLeaseMgrBenchmark : public GenericLeaseMgrBenchmark {
35public:
39 void SetUp(::benchmark::State const&) override {
40 // Ensure we have the proper schema with no transient data.
41 createCqlSchema();
42 try {
44 LeaseMgrFactory::create(validCqlConnectionString());
45 } catch (...) {
46 cerr << "ERROR: unable to open database" << endl;
47 throw;
48 }
49 lmptr_ = &(LeaseMgrFactory::instance());
50 }
51
52 void SetUp(::benchmark::State& s) override {
53 ::benchmark::State const& cs = s;
54 SetUp(cs);
55 }
56
58 void TearDown(::benchmark::State const&) override {
59 try {
60 lmptr_->rollback();
61 } catch (...) {
62 cerr << "WARNING: rollback has failed, this is expected if database"
63 " is opened in read-only mode, continuing..."
64 << endl;
65 }
67 // If data wipe enabled, delete transient data otherwise destroy the schema
68 destroyCqlSchema(false, true);
69 }
70
71 void TearDown(::benchmark::State& s) override {
72 ::benchmark::State const& cs = s;
73 TearDown(cs);
74 }
75};
76
77// Defines a benchmark that measures IPv4 leases insertion.
78BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, insertLeases4)(benchmark::State& state) {
79 const size_t lease_count = state.range(0);
80 while (state.KeepRunning()) {
81 setUp4(state, lease_count);
82 benchInsertLeases4();
83 }
84}
85
86// Defines a benchmark that measures IPv4 leases update.
87BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, updateLeases4)(benchmark::State& state) {
88 const size_t lease_count = state.range(0);
89 while (state.KeepRunning()) {
90 setUpWithInserts4(state, lease_count);
91 benchUpdateLeases4();
92 }
93}
94
95// Defines a benchmark that measures IPv4 leases retrieval by address.
96BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease4_address)(benchmark::State& state) {
97 const size_t lease_count = state.range(0);
98 while (state.KeepRunning()) {
99 setUpWithInserts4(state, lease_count);
100 benchGetLease4_address();
101 }
102}
103
104// Defines a benchmark that measures IPv4 leases retrieval by hardware address.
105BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease4_hwaddr)(benchmark::State& state) {
106 const size_t lease_count = state.range(0);
107 while (state.KeepRunning()) {
108 setUpWithInserts4(state, lease_count);
109 benchGetLease4_hwaddr();
110 }
111}
112
113// Defines a benchmark that measures IPv4 leases retrieval by hardware address
114// and subnet-id.
115BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease4_hwaddr_subnetid)(benchmark::State& state) {
116 const size_t lease_count = state.range(0);
117 while (state.KeepRunning()) {
118 setUpWithInserts4(state, lease_count);
119 benchGetLease4_hwaddr_subnetid();
120 }
121}
122
123// Defines a benchmark that measures IPv4 leases retrieval by client-id.
124BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease4_clientid)(benchmark::State& state) {
125 const size_t lease_count = state.range(0);
126 while (state.KeepRunning()) {
127 setUpWithInserts4(state, lease_count);
128 benchGetLease4_clientid();
129 }
130}
131
132// Defines a benchmark that measures IPv4 leases retrieval by client-id and
133// subnet-id.
134BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease4_clientid_subnetid)(benchmark::State& state) {
135 const size_t lease_count = state.range(0);
136 while (state.KeepRunning()) {
137 setUpWithInserts4(state, lease_count);
138 benchGetLease4_clientid_subnetid();
139 }
140}
141
142// Defines a benchmark that measures retrieval of expired IPv4 leases.
143BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getExpiredLeases4)(benchmark::State& state) {
144 const size_t lease_count = state.range(0);
145 while (state.KeepRunning()) {
146 setUpWithInserts4(state, lease_count);
147 benchGetExpiredLeases4();
148 }
149}
150
151// Defines a benchmark that measures IPv6 leases insertion.
152BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, insertLeases6)(benchmark::State& state) {
153 const size_t lease_count = state.range(0);
154 while (state.KeepRunning()) {
155 setUp6(state, lease_count);
156 benchInsertLeases6();
157 }
158}
159
160// Defines a benchmark that measures IPv6 leases update.
161BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, updateLeases6)(benchmark::State& state) {
162 const size_t lease_count = state.range(0);
163 while (state.KeepRunning()) {
164 setUpWithInserts6(state, lease_count);
165 benchUpdateLeases6();
166 }
167}
168
169// Defines a benchmark that measures IPv6 leases retrieval by type and address.
170BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease6_type_address)(benchmark::State& state) {
171 const size_t lease_count = state.range(0);
172 while (state.KeepRunning()) {
173 setUpWithInserts6(state, lease_count);
174 benchGetLease6_type_address();
175 }
176}
177
178// Defines a benchmark that measures IPv6 leases retrieval by type, duid and iaid.
179BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease6_type_duid_iaid)(benchmark::State& state) {
180 const size_t lease_count = state.range(0);
181 while (state.KeepRunning()) {
182 setUpWithInserts6(state, lease_count);
183 benchGetLease6_type_duid_iaid();
184 }
185}
186
187// Defines a benchmark that measures IPv6 leases retrieval by lease type, duid, iaid
188// and subnet-id.
189BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid)
190 (benchmark::State& state) {
191 const size_t lease_count = state.range(0);
192 while (state.KeepRunning()) {
193 setUpWithInserts6(state, lease_count);
194 benchGetLease6_type_duid_iaid_subnetid();
195 }
196}
197
198// Defines a benchmark that measures retrieval of expired IPv6 leases.
199BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getExpiredLeases6)(benchmark::State& state) {
200 const size_t lease_count = state.range(0);
201 while (state.KeepRunning()) {
202 setUpWithInserts6(state, lease_count);
203 benchGetExpiredLeases6();
204 }
205}
206
209
211BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, insertLeases4)
212 ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
213
215BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, updateLeases4)
216 ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
217
219BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_address)
220 ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
221
223BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_hwaddr)
224 ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
225
228BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_hwaddr_subnetid)
229 ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
230
232BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_clientid)
233 ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
234
236BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_clientid_subnetid)
237 ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
238
240BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getExpiredLeases4)
241 ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
242
244BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, insertLeases6)
245 ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
246
248BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, updateLeases6)
249 ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
250
252BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease6_type_address)
253 ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
254
256BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease6_type_duid_iaid)
257 ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
258
261BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid)
262 ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
263
265BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getExpiredLeases6)
266 ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
267
268} // namespace
static void create(const std::string &dbaccess)
Create an instance of a lease manager.
static void destroy()
Destroy lease manager.
static LeaseMgr & instance()
Return current lease manager.
A base class for a fixture for specific lease manager benchmarks.
constexpr benchmark::TimeUnit UNIT
A time unit used - all results to be expressed in us (microseconds)
Definition: parameters.h:35
constexpr size_t MIN_LEASE_COUNT
A minimum number of leases used in a benchmark.
Definition: parameters.h:25
constexpr size_t MAX_LEASE_COUNT
A maximum number of leases used in a benchmark.
Definition: parameters.h:27