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.
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/>.
19 * @file namestore/perf_namestore_api_zone_iteration.c
20 * @brief testcase for zone iteration functionality: iterate all zones
21 * @author Christian Grothoff
24 #include "gnunet_namestore_service.h"
25 #include "gnunet_testing_lib.h"
26 #include "namestore.h"
27 #include "gnunet_dnsparser_lib.h"
29 #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
32 * A #BENCHMARK_SIZE of 1000 takes less than a minute on a reasonably
33 * modern system, so 30 minutes should be OK even for very, very
36 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
39 * The runtime of the benchmark is expected to be linear
40 * for the iteration phase with a *good* database. The FLAT
41 * database uses a quadratic retrieval algorithm,
42 * hence it should be quadratic in the size.
44 #define BENCHMARK_SIZE 1000
49 #define MAX_REC_SIZE 500
52 * How big are the blocks we fetch? Note that the first block is
53 * always just 1 record set per current API. Smaller block
54 * sizes will make quadratic iteration-by-offset penalties
57 #define BLOCK_SIZE 100
59 static struct GNUNET_NAMESTORE_Handle *nsh;
61 static struct GNUNET_SCHEDULER_Task *timeout_task;
63 static struct GNUNET_SCHEDULER_Task *t;
65 static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
67 static struct GNUNET_NAMESTORE_ZoneIterator *zi;
69 static struct GNUNET_NAMESTORE_QueueEntry *qe;
73 static unsigned int off;
75 static unsigned int left_until_next;
77 static uint8_t seen[1 + BENCHMARK_SIZE / 8];
79 static struct GNUNET_TIME_Absolute start;
83 * Terminate everything
93 GNUNET_NAMESTORE_cancel (qe);
98 GNUNET_NAMESTORE_zone_iteration_stop (zi);
103 GNUNET_NAMESTORE_disconnect (nsh);
108 GNUNET_SCHEDULER_cancel (t);
111 if (NULL != timeout_task)
113 GNUNET_SCHEDULER_cancel (timeout_task);
118 GNUNET_free (privkey);
125 * End with timeout. As this is a benchmark, we do not
126 * fail hard but return "skipped".
133 GNUNET_SCHEDULER_shutdown ();
138 static struct GNUNET_GNSRECORD_Data *
139 create_record (unsigned int count)
141 struct GNUNET_GNSRECORD_Data *rd;
143 rd = GNUNET_malloc (count + sizeof (struct GNUNET_GNSRECORD_Data));
144 rd->expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
145 rd->record_type = TEST_RECORD_TYPE;
146 rd->data_size = count;
147 rd->data = (void *) &rd[1];
159 struct GNUNET_TIME_Relative delay;
162 delay = GNUNET_TIME_absolute_get_duration (start);
164 "Iterating over %u records took %s\n",
166 GNUNET_STRINGS_relative_time_to_string (delay,
168 if (BENCHMARK_SIZE == off)
177 GNUNET_SCHEDULER_shutdown ();
187 GNUNET_SCHEDULER_shutdown ();
192 zone_proc (void *cls,
193 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
195 unsigned int rd_count,
196 const struct GNUNET_GNSRECORD_Data *rd)
198 struct GNUNET_GNSRECORD_Data *wrd;
201 GNUNET_assert (NULL != zone);
202 if (1 != sscanf (label,
208 GNUNET_SCHEDULER_shutdown ();
211 if ( (xoff > BENCHMARK_SIZE) ||
212 (0 != (seen[xoff / 8] & (1U << (xoff % 8)))) )
216 GNUNET_SCHEDULER_shutdown ();
219 seen[xoff / 8] |= (1U << (xoff % 8));
220 wrd = create_record (xoff % MAX_REC_SIZE);
221 if ( (rd->record_type != wrd->record_type) ||
222 (rd->data_size != wrd->data_size) ||
223 (rd->flags != wrd->flags) )
227 GNUNET_SCHEDULER_shutdown ();
231 if (0 != memcmp (rd->data,
237 GNUNET_SCHEDULER_shutdown ();
242 if (0 != memcmp (zone,
244 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
248 GNUNET_SCHEDULER_shutdown ();
253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
254 "Obtained record %u, expecting %u more until asking for mor explicitly\n",
257 if (0 == left_until_next)
259 left_until_next = BLOCK_SIZE;
260 GNUNET_NAMESTORE_zone_iterator_next (zi,
267 publish_record (void *cls);
277 GNUNET_assert (GNUNET_OK == success);
278 t = GNUNET_SCHEDULER_add_now (&publish_record,
284 publish_record (void *cls)
286 struct GNUNET_GNSRECORD_Data *rd;
291 if (BENCHMARK_SIZE == off)
293 struct GNUNET_TIME_Relative delay;
295 delay = GNUNET_TIME_absolute_get_duration (start);
297 "Inserting %u records took %s\n",
299 GNUNET_STRINGS_relative_time_to_string (delay,
301 start = GNUNET_TIME_absolute_get ();
304 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
312 GNUNET_assert (NULL != zi);
315 rd = create_record ((++off) % MAX_REC_SIZE);
316 GNUNET_asprintf (&label,
319 qe = GNUNET_NAMESTORE_records_store (nsh,
332 const struct GNUNET_CONFIGURATION_Handle *cfg,
333 struct GNUNET_TESTING_Peer *peer)
335 GNUNET_SCHEDULER_add_shutdown (&end,
337 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
340 nsh = GNUNET_NAMESTORE_connect (cfg);
341 GNUNET_assert (NULL != nsh);
342 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
343 GNUNET_assert (NULL != privkey);
344 start = GNUNET_TIME_absolute_get ();
345 t = GNUNET_SCHEDULER_add_now (&publish_record,
354 const char *plugin_name;
357 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
358 GNUNET_asprintf (&cfg_name,
359 "perf_namestore_api_%s.conf",
362 GNUNET_DISK_purge_cfg_dir (cfg_name,
365 GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration",
372 GNUNET_DISK_purge_cfg_dir (cfg_name,
374 GNUNET_free (cfg_name);
379 /* end of perf_namestore_api_zone_iteration.c */