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
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file namestore/perf_namestore_api_zone_iteration.c
22 * @brief testcase for zone iteration functionality: iterate all zones
23 * @author Christian Grothoff
26 #include "gnunet_namestore_service.h"
27 #include "gnunet_testing_lib.h"
28 #include "namestore.h"
31 * A #BENCHMARK_SIZE of 1000 takes less than a minute on a reasonably
32 * modern system, so 30 minutes should be OK even for very, very
35 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
38 * The runtime of the benchmark is expected to be linear
39 * for the iteration phase with a *good* database. The FLAT
40 * database uses a quadratic retrieval algorithm,
41 * hence it should be quadratic in the size.
43 #define BENCHMARK_SIZE 1000
48 #define MAX_REC_SIZE 500
51 * How big are the blocks we fetch? Note that the first block is
52 * always just 1 record set per current API. Smaller block
53 * sizes will make quadratic iteration-by-offset penalties
56 #define BLOCK_SIZE 100
58 static struct GNUNET_NAMESTORE_Handle *nsh;
60 static struct GNUNET_SCHEDULER_Task *timeout_task;
62 static struct GNUNET_SCHEDULER_Task *t;
64 static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
66 static struct GNUNET_NAMESTORE_ZoneIterator *zi;
68 static struct GNUNET_NAMESTORE_QueueEntry *qe;
72 static unsigned int off;
74 static unsigned int left_until_next;
76 static uint8_t seen[1 + BENCHMARK_SIZE / 8];
78 static struct GNUNET_TIME_Absolute start;
82 * Terminate everything
92 GNUNET_NAMESTORE_cancel (qe);
97 GNUNET_NAMESTORE_zone_iteration_stop (zi);
102 GNUNET_NAMESTORE_disconnect (nsh);
107 GNUNET_SCHEDULER_cancel (t);
110 if (NULL != timeout_task)
112 GNUNET_SCHEDULER_cancel (timeout_task);
117 GNUNET_free (privkey);
124 * End with timeout. As this is a benchmark, we do not
125 * fail hard but return "skipped".
132 GNUNET_SCHEDULER_shutdown ();
137 static struct GNUNET_GNSRECORD_Data *
138 create_record (unsigned int count)
140 struct GNUNET_GNSRECORD_Data *rd;
142 rd = GNUNET_malloc (count + sizeof (struct GNUNET_GNSRECORD_Data));
143 rd->expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
144 rd->record_type = count;
145 rd->data_size = count;
146 rd->data = (void *) &rd[1];
158 struct GNUNET_TIME_Relative delay;
161 delay = GNUNET_TIME_absolute_get_duration (start);
163 "Iterating over %u records took %s\n",
165 GNUNET_STRINGS_relative_time_to_string (delay,
167 if (BENCHMARK_SIZE == off)
176 GNUNET_SCHEDULER_shutdown ();
186 GNUNET_SCHEDULER_shutdown ();
191 zone_proc (void *cls,
192 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
194 unsigned int rd_count,
195 const struct GNUNET_GNSRECORD_Data *rd)
197 struct GNUNET_GNSRECORD_Data *wrd;
200 GNUNET_assert (NULL != zone);
201 if (1 != sscanf (label,
207 GNUNET_SCHEDULER_shutdown ();
210 if ( (xoff > BENCHMARK_SIZE) ||
211 (0 != (seen[xoff / 8] & (1U << (xoff % 8)))) )
215 GNUNET_SCHEDULER_shutdown ();
218 seen[xoff / 8] |= (1U << (xoff % 8));
219 wrd = create_record (xoff % MAX_REC_SIZE);
220 if ( (rd->record_type != wrd->record_type) ||
221 (rd->data_size != wrd->data_size) ||
222 (rd->flags != wrd->flags) )
226 GNUNET_SCHEDULER_shutdown ();
230 if (0 != memcmp (rd->data,
236 GNUNET_SCHEDULER_shutdown ();
241 if (0 != memcmp (zone,
243 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
247 GNUNET_SCHEDULER_shutdown ();
252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
253 "Obtained record %u, expecting %u more until asking for mor explicitly\n",
256 if (0 == left_until_next)
258 left_until_next = BLOCK_SIZE;
259 GNUNET_NAMESTORE_zone_iterator_next (zi,
266 publish_record (void *cls);
276 GNUNET_assert (GNUNET_OK == success);
277 t = GNUNET_SCHEDULER_add_now (&publish_record,
283 publish_record (void *cls)
285 struct GNUNET_GNSRECORD_Data *rd;
290 if (BENCHMARK_SIZE == off)
292 struct GNUNET_TIME_Relative delay;
294 delay = GNUNET_TIME_absolute_get_duration (start);
296 "Inserting %u records took %s\n",
298 GNUNET_STRINGS_relative_time_to_string (delay,
300 start = GNUNET_TIME_absolute_get ();
303 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
311 GNUNET_assert (NULL != zi);
314 rd = create_record ((++off) % MAX_REC_SIZE);
315 GNUNET_asprintf (&label,
318 qe = GNUNET_NAMESTORE_records_store (nsh,
331 const struct GNUNET_CONFIGURATION_Handle *cfg,
332 struct GNUNET_TESTING_Peer *peer)
334 GNUNET_SCHEDULER_add_shutdown (&end,
336 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
339 nsh = GNUNET_NAMESTORE_connect (cfg);
340 GNUNET_assert (NULL != nsh);
341 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
342 GNUNET_assert (NULL != privkey);
343 start = GNUNET_TIME_absolute_get ();
344 t = GNUNET_SCHEDULER_add_now (&publish_record,
353 const char *plugin_name;
356 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
357 GNUNET_asprintf (&cfg_name,
358 "perf_namestore_api_%s.conf",
361 GNUNET_DISK_purge_cfg_dir (cfg_name,
364 GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration",
371 GNUNET_DISK_purge_cfg_dir (cfg_name,
373 GNUNET_free (cfg_name);
378 /* end of perf_namestore_api_zone_iteration.c */