aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/perf_namestore_api_zone_iteration.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/perf_namestore_api_zone_iteration.c')
-rw-r--r--src/namestore/perf_namestore_api_zone_iteration.c389
1 files changed, 389 insertions, 0 deletions
diff --git a/src/namestore/perf_namestore_api_zone_iteration.c b/src/namestore/perf_namestore_api_zone_iteration.c
new file mode 100644
index 000000000..8b5c53576
--- /dev/null
+++ b/src/namestore/perf_namestore_api_zone_iteration.c
@@ -0,0 +1,389 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2013, 2018 GNUnet e.V.
4
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.
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 General Public License for more details.
14
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.
19*/
20/**
21 * @file namestore/perf_namestore_api_zone_iteration.c
22 * @brief testcase for zone iteration functionality: iterate all zones
23 * @author Christian Grothoff
24 */
25#include "platform.h"
26#include "gnunet_namestore_service.h"
27#include "gnunet_testing_lib.h"
28#include "namestore.h"
29
30/**
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
33 * slow systems.
34 */
35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
36
37/**
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.
42 */
43#define BENCHMARK_SIZE 1000
44
45/**
46 * Maximum record size
47 */
48#define MAX_REC_SIZE 500
49
50/**
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
54 * more pronounced.
55 */
56#define BLOCK_SIZE 100
57
58static struct GNUNET_NAMESTORE_Handle *nsh;
59
60static struct GNUNET_SCHEDULER_Task *timeout_task;
61
62static struct GNUNET_SCHEDULER_Task *t;
63
64static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
65
66static struct GNUNET_NAMESTORE_ZoneIterator *zi;
67
68static struct GNUNET_NAMESTORE_QueueEntry *qe;
69
70static int res;
71
72static char *directory;
73
74static unsigned int off;
75
76static unsigned int left_until_next;
77
78static uint8_t seen[1 + BENCHMARK_SIZE / 8];
79
80static struct GNUNET_TIME_Absolute start;
81
82
83/**
84 * Terminate everything
85 *
86 * @param cls NULL
87 */
88static void
89end (void *cls)
90{
91 (void) cls;
92 if (NULL != qe)
93 {
94 GNUNET_NAMESTORE_cancel (qe);
95 qe = NULL;
96 }
97 if (NULL != zi)
98 {
99 GNUNET_NAMESTORE_zone_iteration_stop (zi);
100 zi = NULL;
101 }
102 if (NULL != nsh)
103 {
104 GNUNET_NAMESTORE_disconnect (nsh);
105 nsh = NULL;
106 }
107 if (NULL != t)
108 {
109 GNUNET_SCHEDULER_cancel (t);
110 t = NULL;
111 }
112 if (NULL != timeout_task)
113 {
114 GNUNET_SCHEDULER_cancel (timeout_task);
115 timeout_task = NULL;
116 }
117 if (NULL != privkey)
118 {
119 GNUNET_free (privkey);
120 privkey = NULL;
121 }
122 res = 1;
123}
124
125
126/**
127 * End with timeout. As this is a benchmark, we do not
128 * fail hard but return "skipped".
129 */
130static void
131timeout (void *cls)
132{
133 (void) cls;
134 timeout_task = NULL;
135 GNUNET_SCHEDULER_shutdown ();
136 res = 77;
137}
138
139
140static struct GNUNET_GNSRECORD_Data *
141create_record (unsigned int count)
142{
143 struct GNUNET_GNSRECORD_Data *rd;
144
145 rd = GNUNET_malloc (count + sizeof (struct GNUNET_GNSRECORD_Data));
146 rd->expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
147 rd->record_type = count;
148 rd->data_size = count;
149 rd->data = (void *) &rd[1];
150 rd->flags = 0;
151 memset (&rd[1],
152 'a',
153 count);
154 return rd;
155}
156
157
158static void
159zone_end (void *cls)
160{
161 struct GNUNET_TIME_Relative delay;
162
163 zi = NULL;
164 delay = GNUNET_TIME_absolute_get_duration (start);
165 fprintf (stdout,
166 "Iterating over %u records took %s\n",
167 off,
168 GNUNET_STRINGS_relative_time_to_string (delay,
169 GNUNET_YES));
170 if (BENCHMARK_SIZE == off)
171 {
172 res = 0;
173 }
174 else
175 {
176 GNUNET_break (0);
177 res = 1;
178 }
179 GNUNET_SCHEDULER_shutdown ();
180}
181
182
183static void
184fail_cb (void *cls)
185{
186 zi = NULL;
187 res = 2;
188 GNUNET_break (0);
189 GNUNET_SCHEDULER_shutdown ();
190}
191
192
193static void
194zone_proc (void *cls,
195 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
196 const char *label,
197 unsigned int rd_count,
198 const struct GNUNET_GNSRECORD_Data *rd)
199{
200 struct GNUNET_GNSRECORD_Data *wrd;
201 unsigned int xoff;
202
203 GNUNET_assert (NULL != zone);
204 if (1 != sscanf (label,
205 "l%u",
206 &xoff))
207 {
208 res = 3;
209 GNUNET_break (0);
210 GNUNET_SCHEDULER_shutdown ();
211 return;
212 }
213 if ( (xoff > BENCHMARK_SIZE) ||
214 (0 != (seen[xoff / 8] & (1U << (xoff % 8)))) )
215 {
216 res = 3;
217 GNUNET_break (0);
218 GNUNET_SCHEDULER_shutdown ();
219 return;
220 }
221 seen[xoff / 8] |= (1U << (xoff % 8));
222 wrd = create_record (xoff % MAX_REC_SIZE);
223 if ( (rd->record_type != wrd->record_type) ||
224 (rd->data_size != wrd->data_size) ||
225 (rd->flags != wrd->flags) )
226 {
227 res = 4;
228 GNUNET_break (0);
229 GNUNET_SCHEDULER_shutdown ();
230 GNUNET_free (wrd);
231 return;
232 }
233 if (0 != memcmp (rd->data,
234 wrd->data,
235 wrd->data_size))
236 {
237 res = 4;
238 GNUNET_break (0);
239 GNUNET_SCHEDULER_shutdown ();
240 GNUNET_free (wrd);
241 return;
242 }
243 GNUNET_free (wrd);
244 if (0 != memcmp (zone,
245 privkey,
246 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
247 {
248 res = 5;
249 GNUNET_break (0);
250 GNUNET_SCHEDULER_shutdown ();
251 return;
252 }
253 off++;
254 left_until_next--;
255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
256 "Obtained record %u, expecting %u more until asking for mor explicitly\n",
257 off,
258 left_until_next);
259 if (0 == left_until_next)
260 {
261 left_until_next = BLOCK_SIZE;
262 GNUNET_NAMESTORE_zone_iterator_next (zi,
263 left_until_next);
264 }
265}
266
267
268static void
269publish_record (void *cls);
270
271
272static void
273put_cont (void *cls,
274 int32_t success,
275 const char *emsg)
276{
277 (void) cls;
278 qe = NULL;
279 GNUNET_assert (GNUNET_OK == success);
280 t = GNUNET_SCHEDULER_add_now (&publish_record,
281 NULL);
282}
283
284
285static void
286publish_record (void *cls)
287{
288 struct GNUNET_GNSRECORD_Data *rd;
289 char *label;
290
291 (void) cls;
292 t = NULL;
293 if (BENCHMARK_SIZE == off)
294 {
295 struct GNUNET_TIME_Relative delay;
296
297 delay = GNUNET_TIME_absolute_get_duration (start);
298 fprintf (stdout,
299 "Inserting %u records took %s\n",
300 off,
301 GNUNET_STRINGS_relative_time_to_string (delay,
302 GNUNET_YES));
303 start = GNUNET_TIME_absolute_get ();
304 off = 0;
305 left_until_next = 1;
306 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
307 NULL,
308 &fail_cb,
309 NULL,
310 &zone_proc,
311 NULL,
312 &zone_end,
313 NULL);
314 GNUNET_assert (NULL != zi);
315 return;
316 }
317 rd = create_record ((++off) % MAX_REC_SIZE);
318 GNUNET_asprintf (&label,
319 "l%u",
320 off);
321 qe = GNUNET_NAMESTORE_records_store (nsh,
322 privkey,
323 label,
324 1, rd,
325 &put_cont,
326 NULL);
327 GNUNET_free (label);
328 GNUNET_free (rd);
329}
330
331
332static void
333run (void *cls,
334 const struct GNUNET_CONFIGURATION_Handle *cfg,
335 struct GNUNET_TESTING_Peer *peer)
336{
337 directory = NULL;
338 GNUNET_assert (GNUNET_OK ==
339 GNUNET_CONFIGURATION_get_value_string(cfg,
340 "PATHS",
341 "GNUNET_TEST_HOME",
342 &directory));
343 GNUNET_DISK_directory_remove (directory);
344 GNUNET_SCHEDULER_add_shutdown (&end,
345 NULL);
346 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
347 &timeout,
348 NULL);
349 nsh = GNUNET_NAMESTORE_connect (cfg);
350 GNUNET_assert (NULL != nsh);
351 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
352 GNUNET_assert (NULL != privkey);
353 start = GNUNET_TIME_absolute_get ();
354 t = GNUNET_SCHEDULER_add_now (&publish_record,
355 NULL);
356}
357
358
359int
360main (int argc,
361 char *argv[])
362{
363 const char *plugin_name;
364 char *cfg_name;
365
366 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
367 GNUNET_asprintf (&cfg_name,
368 "test_namestore_api_%s.conf",
369 plugin_name);
370 res = 1;
371 if (0 !=
372 GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration",
373 cfg_name,
374 &run,
375 NULL))
376 {
377 res = 1;
378 }
379 GNUNET_free (cfg_name);
380 if (NULL != directory)
381 {
382 GNUNET_DISK_directory_remove (directory);
383 GNUNET_free (directory);
384 }
385 return res;
386}
387
388
389/* end of perf_namestore_api_zone_iteration.c */