aboutsummaryrefslogtreecommitdiff
path: root/src/service/namestore/perf_namestore_api_import.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/namestore/perf_namestore_api_import.c')
-rw-r--r--src/service/namestore/perf_namestore_api_import.c383
1 files changed, 383 insertions, 0 deletions
diff --git a/src/service/namestore/perf_namestore_api_import.c b/src/service/namestore/perf_namestore_api_import.c
new file mode 100644
index 000000000..326955dff
--- /dev/null
+++ b/src/service/namestore/perf_namestore_api_import.c
@@ -0,0 +1,383 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @file namestore/perf_namestore_api_import.c
22 * @brief testcase for namestore: Import a lot of records
23 * @author Martin Schanzenbach
24 */
25#include "platform.h"
26#include "gnunet_namestore_service.h"
27#include "gnunet_testing_lib.h"
28
29#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
30
31#define TEST_RECORD_COUNT 10000
32
33/**
34 * A #BENCHMARK_SIZE of 1000 takes less than a minute on a reasonably
35 * modern system, so 30 minutes should be OK even for very, very
36 * slow systems.
37 */
38#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
39
40/**
41 * The runtime of the benchmark is expected to be linear
42 * for the iteration phase with a *good* database. The FLAT
43 * database uses a quadratic retrieval algorithm,
44 * hence it should be quadratic in the size.
45 */
46#define BENCHMARK_SIZE 1000
47
48/**
49 * Maximum record size
50 */
51#define MAX_REC_SIZE 500
52
53/**
54 * How big are the blocks we fetch? Note that the first block is
55 * always just 1 record set per current API. Smaller block
56 * sizes will make quadratic iteration-by-offset penalties
57 * more pronounced.
58 */
59#define BLOCK_SIZE 100
60
61static struct GNUNET_NAMESTORE_Handle *nsh;
62
63static struct GNUNET_SCHEDULER_Task *timeout_task;
64
65static struct GNUNET_SCHEDULER_Task *t;
66
67static struct GNUNET_CRYPTO_PrivateKey privkey;
68
69static struct GNUNET_NAMESTORE_QueueEntry *qe;
70
71static int res;
72
73static struct GNUNET_TIME_Absolute start;
74
75struct GNUNET_NAMESTORE_RecordInfo ri[TEST_RECORD_COUNT];
76
77int single_put_pos;
78
79static int bulk_count = 0;
80
81
82/**
83 * Terminate everything
84 *
85 * @param cls NULL
86 */
87static void
88end (void *cls)
89{
90 (void) cls;
91 if (NULL != qe)
92 {
93 GNUNET_NAMESTORE_cancel (qe);
94 qe = NULL;
95 }
96 if (NULL != nsh)
97 {
98 GNUNET_NAMESTORE_disconnect (nsh);
99 nsh = NULL;
100 }
101 if (NULL != t)
102 {
103 GNUNET_SCHEDULER_cancel (t);
104 t = NULL;
105 }
106 if (NULL != timeout_task)
107 {
108 GNUNET_SCHEDULER_cancel (timeout_task);
109 timeout_task = NULL;
110 }
111}
112
113
114/**
115 * End with timeout. As this is a benchmark, we do not
116 * fail hard but return "skipped".
117 */
118static void
119timeout (void *cls)
120{
121 (void) cls;
122 timeout_task = NULL;
123 GNUNET_SCHEDULER_shutdown ();
124 res = 77;
125}
126
127
128static struct GNUNET_GNSRECORD_Data *
129create_record (unsigned int count)
130{
131 struct GNUNET_GNSRECORD_Data *rd;
132
133 rd = GNUNET_malloc (count + sizeof(struct GNUNET_GNSRECORD_Data));
134 rd->expiration_time = GNUNET_TIME_relative_to_absolute (
135 GNUNET_TIME_UNIT_HOURS).abs_value_us;
136 rd->record_type = TEST_RECORD_TYPE;
137 rd->data_size = count;
138 rd->data = (void *) &rd[1];
139 rd->flags = 0;
140 memset (&rd[1],
141 'a',
142 count);
143 return rd;
144}
145
146
147static void
148publish_records_single (void *cls);
149
150static void
151publish_records_bulk_tx (void *cls);
152
153
154static void
155put_cont_bulk_tx (void *cls,
156 enum GNUNET_ErrorCode ec)
157{
158 struct GNUNET_TIME_Relative delay;
159 qe = NULL;
160 if (GNUNET_EC_NONE != ec)
161 {
162 GNUNET_break (0);
163 GNUNET_SCHEDULER_shutdown ();
164 return;
165 }
166 if (bulk_count == TEST_RECORD_COUNT)
167 {
168 single_put_pos++;
169 delay = GNUNET_TIME_absolute_get_duration (start);
170 fprintf (stdout,
171 "BULK-TX: Publishing %u records took %s\n",
172 TEST_RECORD_COUNT,
173 GNUNET_STRINGS_relative_time_to_string (delay,
174 GNUNET_YES));
175 res = 0;
176 GNUNET_SCHEDULER_shutdown ();
177 return;
178 }
179 t = GNUNET_SCHEDULER_add_now (&publish_records_bulk_tx, NULL);
180}
181
182
183static void
184publish_records_bulk_tx (void *cls)
185{
186 unsigned int sent_rds;
187 t = NULL;
188 qe = GNUNET_NAMESTORE_records_store (nsh,
189 &privkey,
190 TEST_RECORD_COUNT - bulk_count,
191 &ri[bulk_count],
192 &sent_rds,
193 &put_cont_bulk_tx,
194 NULL);
195 bulk_count += sent_rds;
196 GNUNET_assert (sent_rds != 0);
197}
198
199
200static void
201publish_records_bulk (void *cls);
202
203static void
204put_cont_bulk (void *cls,
205 enum GNUNET_ErrorCode ec)
206{
207 struct GNUNET_TIME_Relative delay;
208 unsigned int sent_rds;
209
210 (void) cls;
211 qe = NULL;
212 if (GNUNET_EC_NONE != ec)
213 {
214 GNUNET_break (0);
215 GNUNET_SCHEDULER_shutdown ();
216 return;
217 }
218
219 if (bulk_count == TEST_RECORD_COUNT)
220 {
221 delay = GNUNET_TIME_absolute_get_duration (start);
222 fprintf (stdout,
223 "BULK: Publishing %u records took %s\n",
224 TEST_RECORD_COUNT,
225 GNUNET_STRINGS_relative_time_to_string (delay,
226 GNUNET_YES));
227 start = GNUNET_TIME_absolute_get ();
228 bulk_count = 0;
229 qe = GNUNET_NAMESTORE_records_store (nsh,
230 &privkey,
231 TEST_RECORD_COUNT - bulk_count,
232 &ri[bulk_count],
233 &sent_rds,
234 &put_cont_bulk_tx,
235 NULL);
236 bulk_count += sent_rds;
237 GNUNET_assert (sent_rds != 0);
238 return;
239 }
240 (void) cls;
241 qe = NULL;
242 if (GNUNET_EC_NONE != ec)
243 {
244 GNUNET_break (0);
245 GNUNET_SCHEDULER_shutdown ();
246 return;
247 }
248 t = GNUNET_SCHEDULER_add_now (&publish_records_bulk, NULL);
249}
250
251
252static void
253publish_records_bulk (void *cls)
254{
255 static unsigned int sent_rds = 0;
256 (void) cls;
257 t = NULL;
258 qe = GNUNET_NAMESTORE_records_store (nsh,
259 &privkey,
260 TEST_RECORD_COUNT - bulk_count,
261 &ri[bulk_count],
262 &sent_rds,
263 &put_cont_bulk,
264 NULL);
265 bulk_count += sent_rds;
266 GNUNET_assert (sent_rds != 0);
267}
268
269
270static void
271put_cont_single (void *cls,
272 enum GNUNET_ErrorCode ec)
273{
274 struct GNUNET_TIME_Relative delay;
275 (void) cls;
276 qe = NULL;
277 if (GNUNET_EC_NONE != ec)
278 {
279 GNUNET_break (0);
280 GNUNET_SCHEDULER_shutdown ();
281 return;
282 }
283 single_put_pos++;
284 if (single_put_pos == TEST_RECORD_COUNT)
285 {
286 delay = GNUNET_TIME_absolute_get_duration (start);
287 fprintf (stdout,
288 "SINGLE: Publishing %u records took %s\n",
289 TEST_RECORD_COUNT,
290 GNUNET_STRINGS_relative_time_to_string (delay,
291 GNUNET_YES));
292 start = GNUNET_TIME_absolute_get ();
293 t = GNUNET_SCHEDULER_add_now (&publish_records_bulk, NULL);
294 return;
295 }
296 t = GNUNET_SCHEDULER_add_now (&publish_records_single,
297 NULL);
298}
299
300
301static void
302publish_records_single (void *cls)
303{
304 struct GNUNET_TIME_Relative delay;
305
306 (void) cls;
307 t = NULL;
308 if (single_put_pos == TEST_RECORD_COUNT)
309 {
310 delay = GNUNET_TIME_absolute_get_duration (start);
311 fprintf (stdout,
312 "Publishing %u records took %s\n",
313 TEST_RECORD_COUNT,
314 GNUNET_STRINGS_relative_time_to_string (delay,
315 GNUNET_YES));
316 GNUNET_SCHEDULER_add_now (&publish_records_bulk, NULL);
317 }
318 qe = GNUNET_NAMESTORE_record_set_store (nsh,
319 &privkey,
320 ri[single_put_pos].a_label,
321 ri[single_put_pos].a_rd_count,
322 ri[single_put_pos].a_rd,
323 &put_cont_single,
324 NULL);
325}
326
327
328static void
329run (void *cls,
330 const struct GNUNET_CONFIGURATION_Handle *cfg,
331 struct GNUNET_TESTING_Peer *peer)
332{
333
334 for (int i = 0; i < TEST_RECORD_COUNT; i++)
335 {
336 ri[i].a_rd = create_record (1);
337 ri[i].a_rd_count = 1;
338 GNUNET_asprintf ((char**) &ri[i].a_label, "label_%d", i);
339 }
340 GNUNET_SCHEDULER_add_shutdown (&end,
341 NULL);
342 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
343 &timeout,
344 NULL);
345 nsh = GNUNET_NAMESTORE_connect (cfg);
346 GNUNET_assert (NULL != nsh);
347 privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY);
348 GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key);
349 start = GNUNET_TIME_absolute_get ();
350 t = GNUNET_SCHEDULER_add_now (&publish_records_single,
351 NULL);
352}
353
354
355#include "test_common.c"
356
357
358int
359main (int argc,
360 char *argv[])
361{
362 char *plugin_name;
363 char *cfg_name;
364
365 SETUP_CFG2 ("perf_namestore_api_%s.conf", plugin_name, cfg_name);
366 res = 1;
367 if (0 !=
368 GNUNET_TESTING_peer_run ("perf-namestore-api-import",
369 cfg_name,
370 &run,
371 NULL))
372 {
373 res = 1;
374 }
375 GNUNET_DISK_purge_cfg_dir (cfg_name,
376 "GNUNET_TEST_HOME");
377 GNUNET_free (plugin_name);
378 GNUNET_free (cfg_name);
379 return res;
380}
381
382
383/* end of perf_namestore_api_zone_iteration.c */