Kea 1.5.0
pgsql_host_data_source_benchmark.cc
Go to the documentation of this file.
1// Copyright (C) 2018 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
23#include <dhcpsrv/testutils/pgsql_schema.h>
24#include <iostream>
25
26using namespace isc::dhcp::bench;
27using namespace isc::dhcp::test;
28using namespace isc::dhcp;
29using namespace std;
30
31namespace {
32
34class PgSqlHostDataSourceBenchmark : public GenericHostDataSourceBenchmark {
35public:
36
40 void SetUp(::benchmark::State const&) override {
41 destroyPgSQLSchema(false);
42 createPgSQLSchema(false);
43 try {
44 HostDataSourceFactory::destroy();
45 HostDataSourceFactory::create(validPgSQLConnectionString());
46 } catch (...) {
47 cerr << "ERROR: unable to open database" << endl;
48 throw;
49 }
50 hdsptr_ = HostDataSourceFactory::getHostDataSourcePtr();
51 }
52
54 void TearDown(::benchmark::State const&) override {
55 try {
56 hdsptr_->rollback();
57 } catch (...) {
58 cerr << "WARNING: rollback has failed, this is expected if database"
59 " is opened in read-only mode, continuing..."
60 << endl;
61 }
62 HostDataSourceFactory::destroy();
63 destroyPgSQLSchema(false);
64 }
65};
66
69BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, insertHosts)(benchmark::State& state) {
70 const size_t host_count = state.range(0);
71 while (state.KeepRunning()) {
72 setUp(state, host_count);
73 insertHosts();
74 }
75}
76
79BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, updateHosts)(benchmark::State& state) {
80 const size_t host_count = state.range(0);
81 while (state.KeepRunning()) {
82 setUpWithInserts(state, host_count);
83 updateHosts();
84 }
85}
86
89BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, getAllByHWAddrDuid)(benchmark::State& state) {
90 const size_t host_count = state.range(0);
91 while (state.KeepRunning()) {
92 setUpWithInserts(state, host_count);
93 benchGetAllByHWAddrDuid();
94 }
95}
96
99BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, getAll)(benchmark::State& state) {
100 const size_t host_count = state.range(0);
101 while (state.KeepRunning()) {
102 setUpWithInserts(state, host_count);
103 benchGetAll();
104 }
105}
106
109BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, getAllv4Resv)(benchmark::State& state) {
110 const size_t host_count = state.range(0);
111 while (state.KeepRunning()) {
112 setUpWithInserts(state, host_count);
113 getAllv4Resv();
114 }
115}
116
119BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get4BySubnetHWAddrDuid)(benchmark::State& state) {
120 const size_t host_count = state.range(0);
121 while (state.KeepRunning()) {
122 setUpWithInserts(state, host_count);
123 benchGet4BySubnetHWAddrDuid();
124 }
125}
126
129BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get4IdentifierSubnetId)(benchmark::State& state) {
130 const size_t host_count = state.range(0);
131 while (state.KeepRunning()) {
132 setUpWithInserts(state, host_count);
133 benchGet4IdentifierSubnetId();
134 }
135}
136
139BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get4SubnetIdv4Resrv)(benchmark::State& state) {
140 const size_t host_count = state.range(0);
141 while (state.KeepRunning()) {
142 setUpWithInserts(state, host_count);
143 benchGet4SubnetIdv4Resrv();
144 }
145}
146
149BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get6SubnetIdDuidHWAddr)(benchmark::State& state) {
150 const size_t host_count = state.range(0);
151 while (state.KeepRunning()) {
152 setUpWithInserts(state, host_count);
153 benchGet6SubnetIdDuidHWAddr();
154 }
155}
156
159BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get6IdentifierSubnetId)(benchmark::State& state) {
160 const size_t host_count = state.range(0);
161 while (state.KeepRunning()) {
162 setUpWithInserts(state, host_count);
163 benchGet6IdentifierSubnetId();
164 }
165}
166
169BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get6SubnetIdAddr)(benchmark::State& state) {
170 const size_t host_count = state.range(0);
171 while (state.KeepRunning()) {
172 setUpWithInserts(state, host_count);
173 benchGet6SubnetIdAddr();
174 }
175}
176
179BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get6Prefix)(benchmark::State& state) {
180 const size_t host_count = state.range(0);
181 while (state.KeepRunning()) {
182 setUpWithInserts(state, host_count);
183 benchGet6Prefix();
184 }
185}
186
189BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, insertHosts)
190 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
191
194BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, updateHosts)
195 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
196
199BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, getAllByHWAddrDuid)
200 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
201
204BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, getAll)
205 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
206
209BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, getAllv4Resv)
210 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
211
214BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, get4BySubnetHWAddrDuid)
215 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
216
219BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, get4IdentifierSubnetId)
220 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
221
224BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, get4SubnetIdv4Resrv)
225 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
226
229BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, get6SubnetIdDuidHWAddr)
230 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
231
234BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, get6IdentifierSubnetId)
235 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
236
239BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, get6SubnetIdAddr)
240 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
241
244BENCHMARK_REGISTER_F(PgSqlHostDataSourceBenchmark, get6Prefix)
245 ->Range(MIN_HOST_COUNT, MAX_HOST_COUNT)->Unit(UNIT);
246
247} // namespace
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