2 This file is part of GNUnet.
3 Copyright (C) 2013, 2018 GNUnet e.V.
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.
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.
16 * @file namestore/perf_namestore_api_zone_iteration.c
17 * @brief testcase for zone iteration functionality: iterate all zones
18 * @author Christian Grothoff
21 #include "gnunet_namestore_service.h"
22 #include "gnunet_testing_lib.h"
23 #include "namestore.h"
24 #include "gnunet_dnsparser_lib.h"
26 #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
29 * A #BENCHMARK_SIZE of 1000 takes less than a minute on a reasonably
30 * modern system, so 30 minutes should be OK even for very, very
33 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
36 * The runtime of the benchmark is expected to be linear
37 * for the iteration phase with a *good* database. The FLAT
38 * database uses a quadratic retrieval algorithm,
39 * hence it should be quadratic in the size.
41 #define BENCHMARK_SIZE 1000
46 #define MAX_REC_SIZE 500
49 * How big are the blocks we fetch? Note that the first block is
50 * always just 1 record set per current API. Smaller block
51 * sizes will make quadratic iteration-by-offset penalties
54 #define BLOCK_SIZE 100
56 static struct GNUNET_NAMESTORE_Handle *nsh;
58 static struct GNUNET_SCHEDULER_Task *timeout_task;
60 static struct GNUNET_SCHEDULER_Task *t;
62 static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
64 static struct GNUNET_NAMESTORE_ZoneIterator *zi;
66 static struct GNUNET_NAMESTORE_QueueEntry *qe;
70 static unsigned int off;
72 static unsigned int left_until_next;
74 static uint8_t seen[1 + BENCHMARK_SIZE / 8];
76 static struct GNUNET_TIME_Absolute start;
80 * Terminate everything
90 GNUNET_NAMESTORE_cancel (qe);
95 GNUNET_NAMESTORE_zone_iteration_stop (zi);
100 GNUNET_NAMESTORE_disconnect (nsh);
105 GNUNET_SCHEDULER_cancel (t);
108 if (NULL != timeout_task)
110 GNUNET_SCHEDULER_cancel (timeout_task);
115 GNUNET_free (privkey);
122 * End with timeout. As this is a benchmark, we do not
123 * fail hard but return "skipped".
130 GNUNET_SCHEDULER_shutdown ();
135 static struct GNUNET_GNSRECORD_Data *
136 create_record (unsigned int count)
138 struct GNUNET_GNSRECORD_Data *rd;
140 rd = GNUNET_malloc (count + sizeof (struct GNUNET_GNSRECORD_Data));
141 rd->expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
142 rd->record_type = TEST_RECORD_TYPE;
143 rd->data_size = count;
144 rd->data = (void *) &rd[1];
156 struct GNUNET_TIME_Relative delay;
159 delay = GNUNET_TIME_absolute_get_duration (start);
161 "Iterating over %u records took %s\n",
163 GNUNET_STRINGS_relative_time_to_string (delay,
165 if (BENCHMARK_SIZE == off)
174 GNUNET_SCHEDULER_shutdown ();
184 GNUNET_SCHEDULER_shutdown ();
189 zone_proc (void *cls,
190 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
192 unsigned int rd_count,
193 const struct GNUNET_GNSRECORD_Data *rd)
195 struct GNUNET_GNSRECORD_Data *wrd;
198 GNUNET_assert (NULL != zone);
199 if (1 != sscanf (label,
205 GNUNET_SCHEDULER_shutdown ();
208 if ( (xoff > BENCHMARK_SIZE) ||
209 (0 != (seen[xoff / 8] & (1U << (xoff % 8)))) )
213 GNUNET_SCHEDULER_shutdown ();
216 seen[xoff / 8] |= (1U << (xoff % 8));
217 wrd = create_record (xoff % MAX_REC_SIZE);
218 if ( (rd->record_type != wrd->record_type) ||
219 (rd->data_size != wrd->data_size) ||
220 (rd->flags != wrd->flags) )
224 GNUNET_SCHEDULER_shutdown ();
228 if (0 != memcmp (rd->data,
234 GNUNET_SCHEDULER_shutdown ();
239 if (0 != memcmp (zone,
241 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
245 GNUNET_SCHEDULER_shutdown ();
250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
251 "Obtained record %u, expecting %u more until asking for mor explicitly\n",
254 if (0 == left_until_next)
256 left_until_next = BLOCK_SIZE;
257 GNUNET_NAMESTORE_zone_iterator_next (zi,
264 publish_record (void *cls);
274 GNUNET_assert (GNUNET_OK == success);
275 t = GNUNET_SCHEDULER_add_now (&publish_record,
281 publish_record (void *cls)
283 struct GNUNET_GNSRECORD_Data *rd;
288 if (BENCHMARK_SIZE == off)
290 struct GNUNET_TIME_Relative delay;
292 delay = GNUNET_TIME_absolute_get_duration (start);
294 "Inserting %u records took %s\n",
296 GNUNET_STRINGS_relative_time_to_string (delay,
298 start = GNUNET_TIME_absolute_get ();
301 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
309 GNUNET_assert (NULL != zi);
312 rd = create_record ((++off) % MAX_REC_SIZE);
313 GNUNET_asprintf (&label,
316 qe = GNUNET_NAMESTORE_records_store (nsh,
329 const struct GNUNET_CONFIGURATION_Handle *cfg,
330 struct GNUNET_TESTING_Peer *peer)
332 GNUNET_SCHEDULER_add_shutdown (&end,
334 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
337 nsh = GNUNET_NAMESTORE_connect (cfg);
338 GNUNET_assert (NULL != nsh);
339 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
340 GNUNET_assert (NULL != privkey);
341 start = GNUNET_TIME_absolute_get ();
342 t = GNUNET_SCHEDULER_add_now (&publish_record,
351 const char *plugin_name;
354 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
355 GNUNET_asprintf (&cfg_name,
356 "perf_namestore_api_%s.conf",
359 GNUNET_DISK_purge_cfg_dir (cfg_name,
362 GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration",
369 GNUNET_DISK_purge_cfg_dir (cfg_name,
371 GNUNET_free (cfg_name);
376 /* end of perf_namestore_api_zone_iteration.c */