Kea  1.5.0
memfile_lease_mgr_benchmark.cc
Go to the documentation of this file.
1 // Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #include <config.h>
8 
13 #include <dhcpsrv/testutils/lease_file_io.h>
14 
15 using namespace isc::dhcp::bench;
16 using namespace isc::dhcp::test;
17 using namespace isc::dhcp;
18 using namespace std;
19 
20 namespace {
21 
23 class MemfileLeaseMgrBenchmark : public GenericLeaseMgrBenchmark {
24 public:
25 
29  MemfileLeaseMgrBenchmark()
30  : io4_(""), io6_("") {
31  }
32 
38  void SetUp(::benchmark::State const&) override {
39 
40  io4_ = LeaseFileIO(getLeaseFilePath("leasefile4_0.csv"));
41  io6_ = LeaseFileIO(getLeaseFilePath("leasefile6_0.csv"));
42 
43  // Remove lease files and products of Lease File Cleanup.
44  removeFiles(getLeaseFilePath("leasefile4_0.csv"));
45  removeFiles(getLeaseFilePath("leasefile6_0.csv"));
46 
47  try {
49  startBackend(V4);
50  } catch (...) {
51  std::cerr << "ERROR: unable to start memfile backend." << std::endl;
52  throw;
53  }
54  lmptr_ = &(LeaseMgrFactory::instance());
55  }
56 
60  void startBackend(Universe u) {
61  try {
62  LeaseMgrFactory::create(getConfigString(u));
63  } catch (...) {
64  std::cerr << "*** ERROR: unable to create instance of the Memfile\n"
65  " lease database backend.\n";
66  throw;
67  }
68  lmptr_ = &(LeaseMgrFactory::instance());
69  }
70 
81  static std::string getConfigString(Universe u) {
82  std::ostringstream s;
83  s << "type=memfile " << (u == V4 ? "universe=4 " : "universe=6 ") << "name="
84  << getLeaseFilePath(u == V4 ? "leasefile4_0.csv" : "leasefile6_0.csv")
85  << " lfc-interval=0";
86  return (s.str());
87  }
88 
95  static std::string getLeaseFilePath(const std::string& filename) {
96  std::ostringstream s;
97  s << TEST_DATA_BUILDDIR << "/" << filename;
98  return (s.str());
99  }
100 
106  void removeFiles(const std::string& base_name) const {
107  // Generate suffixes and append them to the base name. The
108  // resulting file names are the ones that may exist as a
109  // result of LFC.
110  for (int i = static_cast<int>(Memfile_LeaseMgr::FILE_CURRENT);
111  i <= static_cast<int>(Memfile_LeaseMgr::FILE_FINISH); ++i) {
113  LeaseFileIO io(Memfile_LeaseMgr::appendSuffix(base_name, type));
114  io.removeFile();
115  }
116  }
117 
123  void TearDown(::benchmark::State const&) override {
124  try {
125  lmptr_->rollback();
126  } catch (...) {
127  std::cerr << "WARNING: rollback has failed. This is surprising as "
128  "memfile doesn't support rollback." << std::endl;
129  }
130 
132 
133  // Remove lease files and products of Lease File Cleanup.
134  removeFiles(getLeaseFilePath("leasefile4_0.csv"));
135  removeFiles(getLeaseFilePath("leasefile6_0.csv"));
136  }
137 
139  LeaseFileIO io4_;
140 
142  LeaseFileIO io6_;
143 };
144 
145 // Defines a benchmark that measures IPv4 leases insertion.
146 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, insertLeases4)(benchmark::State& state) {
147  const size_t lease_count = state.range(0);
148  while (state.KeepRunning()) {
149  setUp4(state, lease_count);
150  benchInsertLeases4();
151  }
152 }
153 
154 // Defines a benchmark that measures IPv4 leases update.
155 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, updateLeases4)(benchmark::State& state) {
156  const size_t lease_count = state.range(0);
157  while (state.KeepRunning()) {
158  setUpWithInserts4(state, lease_count);
159  benchUpdateLeases4();
160  }
161 }
162 
163 // Defines a benchmark that measures IPv4 leases retrieval by address.
164 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease4_address)(benchmark::State& state) {
165  const size_t lease_count = state.range(0);
166  while (state.KeepRunning()) {
167  setUpWithInserts4(state, lease_count);
168  benchGetLease4_address();
169  }
170 }
171 
172 // Defines a benchmark that measures IPv4 leases retrieval by hardware address.
173 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease4_hwaddr)(benchmark::State& state) {
174  const size_t lease_count = state.range(0);
175  while (state.KeepRunning()) {
176  setUpWithInserts4(state, lease_count);
177  benchGetLease4_hwaddr();
178  }
179 }
180 
181 // Defines a benchmark that measures IPv4 leases retrieval by hardware address
182 // and subnet-id.
183 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease4_hwaddr_subnetid)(benchmark::State& state) {
184  const size_t lease_count = state.range(0);
185  while (state.KeepRunning()) {
186  setUpWithInserts4(state, lease_count);
187  benchGetLease4_hwaddr_subnetid();
188  }
189 }
190 
191 // Defines a benchmark that measures IPv4 leases retrieval by client-id.
192 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease4_clientid)(benchmark::State& state) {
193  const size_t lease_count = state.range(0);
194  while (state.KeepRunning()) {
195  setUpWithInserts4(state, lease_count);
196  benchGetLease4_clientid();
197  }
198 }
199 
200 // Defines a benchmark that measures IPv4 leases retrieval by client-id and
201 // subnet-id.
202 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease4_clientid_subnetid)(benchmark::State& state) {
203  const size_t lease_count = state.range(0);
204  while (state.KeepRunning()) {
205  setUpWithInserts4(state, lease_count);
206  benchGetLease4_clientid_subnetid();
207  }
208 }
209 
210 // Defines a benchmark that measures retrieval of expired IPv4 leases.
211 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getExpiredLeases4)(benchmark::State& state) {
212  const size_t lease_count = state.range(0);
213  while (state.KeepRunning()) {
214  setUpWithInserts4(state, lease_count);
215  benchGetExpiredLeases4();
216  }
217 }
218 
219 // Defines a benchmark that measures IPv6 leases insertion.
220 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, insertLeases6)(benchmark::State& state) {
221  const size_t lease_count = state.range(0);
222  while (state.KeepRunning()) {
223  setUp6(state, lease_count);
224  benchInsertLeases6();
225  }
226 }
227 
228 // Defines a benchmark that measures IPv6 leases update.
229 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, updateLeases6)(benchmark::State& state) {
230  const size_t lease_count = state.range(0);
231  while (state.KeepRunning()) {
232  setUpWithInserts6(state, lease_count);
233  benchUpdateLeases6();
234  }
235 }
236 
237 // Defines a benchmark that measures IPv6 leases retrieval by type and address.
238 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease6_type_address)(benchmark::State& state) {
239  const size_t lease_count = state.range(0);
240  while (state.KeepRunning()) {
241  setUpWithInserts6(state, lease_count);
242  benchGetLease6_type_address();
243  }
244 }
245 
246 // Defines a benchmark that measures IPv6 leases retrieval by type, duid and iaid.
247 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease6_type_duid_iaid)(benchmark::State& state) {
248  const size_t lease_count = state.range(0);
249  while (state.KeepRunning()) {
250  setUpWithInserts6(state, lease_count);
251  benchGetLease6_type_duid_iaid();
252  }
253 }
254 
255 // Defines a benchmark that measures IPv6 leases retrieval by lease type, duid, iaid
256 // and subnet-id.
257 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid)
258  (benchmark::State& state) {
259  const size_t lease_count = state.range(0);
260  while (state.KeepRunning()) {
261  setUpWithInserts6(state, lease_count);
262  benchGetLease6_type_duid_iaid_subnetid();
263  }
264 }
265 
266 // Defines a benchmark that measures retrieval of expired IPv6 leases.
267 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getExpiredLeases6)(benchmark::State& state) {
268  const size_t lease_count = state.range(0);
269  while (state.KeepRunning()) {
270  setUpWithInserts6(state, lease_count);
271  benchGetExpiredLeases6();
272  }
273 }
274 
275 
278 
280 BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, insertLeases4)
281  ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
282 
284 BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, updateLeases4)
285  ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
286 
288 BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getLease4_address)
289  ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
290 
292 BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getLease4_hwaddr)
293  ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
294 
297 BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getLease4_hwaddr_subnetid)
298  ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
299 
301 BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getLease4_clientid)
302  ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
303 
305 BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getLease4_clientid_subnetid)
306  ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
307 
309 BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getExpiredLeases4)
310  ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
311 
313 BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, insertLeases6)
314  ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
315 
317 BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, updateLeases6)
318  ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
319 
321 BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getLease6_type_address)
322  ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
323 
325 BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getLease6_type_duid_iaid)
326  ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
327 
330 BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid)
331  ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
332 
334 BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getExpiredLeases6)
335  ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
336 
337 } // namespace
isc::dhcp::Memfile_LeaseMgr::FILE_FINISH
@ FILE_FINISH
LFC Finish File.
Definition: memfile_lease_mgr.h:537
generic_lease_mgr_benchmark.h
isc::dhcp::bench::UNIT
constexpr benchmark::TimeUnit UNIT
A time unit used - all results to be expressed in us (microseconds)
Definition: parameters.h:35
lease_mgr_factory.h
isc::dhcp::LeaseMgrFactory::instance
static LeaseMgr & instance()
Return current lease manager.
Definition: lease_mgr_factory.cc:111
isc::dhcp::test
Definition: log_utils.cc:14
isc::dhcp::LeaseMgrFactory::destroy
static void destroy()
Destroy lease manager.
Definition: lease_mgr_factory.cc:95
isc::dhcp::bench::GenericLeaseMgrBenchmark
A base class for a fixture for specific lease manager benchmarks.
Definition: generic_lease_mgr_benchmark.h:30
isc::dhcp::bench::MAX_LEASE_COUNT
constexpr size_t MAX_LEASE_COUNT
A maximum number of leases used in a benchmark.
Definition: parameters.h:27
isc::dhcp::Memfile_LeaseMgr::appendSuffix
static std::string appendSuffix(const std::string &file_name, const LFCFileType &file_type)
Appends appropriate suffix to the file name.
Definition: memfile_lease_mgr.cc:1320
isc::dhcp
Definition: ctrl_dhcp4_srv.cc:75
memfile_lease_mgr.h
isc::dhcp::bench::MIN_LEASE_COUNT
constexpr size_t MIN_LEASE_COUNT
A minimum number of leases used in a benchmark.
Definition: parameters.h:25
parameters.h
isc::dhcp::LeaseMgrFactory::create
static void create(const std::string &dbaccess)
Create an instance of a lease manager.
Definition: lease_mgr_factory.cc:45
isc::dhcp::Memfile_LeaseMgr::FILE_CURRENT
@ FILE_CURRENT
Lease File
Definition: memfile_lease_mgr.h:533
isc::dhcp::Memfile_LeaseMgr::LFCFileType
LFCFileType
Types of the lease files used by the Lease File Cleanup.
Definition: memfile_lease_mgr.h:532
isc::dhcp::bench
Definition: generic_host_data_source_benchmark.cc:41