2 This file is part of GNUnet.
3 (C) 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors)
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 2, 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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file datastore/perf_datastore_api.c
22 * @brief performance measurement for the datastore implementation
23 * @author Christian Grothoff
25 * This testcase inserts a bunch of (variable size) data and then
26 * deletes data until the (reported) database size drops below a given
27 * threshold. This is iterated 10 times, with the actual size of the
28 * content stored and the number of operations performed being printed
29 * for each iteration. The code also prints a "I" for every 40 blocks
30 * inserted and a "D" for every 40 blocks deleted. The deletion
31 * strategy uses the "random" iterator. Priorities and expiration
32 * dates are set using a pseudo-random value within a realistic range.
36 #include "gnunet_util_lib.h"
37 #include "gnunet_protocols.h"
38 #include "gnunet_datastore_service.h"
40 #define VERBOSE GNUNET_NO
43 * How long until we give up on transmitting the message?
45 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
48 static struct GNUNET_DATASTORE_Handle *datastore;
51 * Target datastore size (in bytes).
53 #define MAX_SIZE 1024LL * 1024 * 4
56 * Report progress outside of major reports? Should probably be GNUNET_YES if
59 #define REPORT_ID GNUNET_YES
62 * Number of put operations equivalent to 1/3rd of MAX_SIZE
64 #define PUT_10 MAX_SIZE / 32 / 1024 / 3
67 * Total number of iterations (each iteration doing
68 * PUT_10 put operations); we report full status every
69 * 10 iterations. Abort with CTRL-C.
74 static unsigned long long stored_bytes;
76 static unsigned long long stored_entries;
78 static unsigned long long stored_ops;
80 static struct GNUNET_TIME_Absolute start_time;
95 struct GNUNET_SCHEDULER_Handle *sched;
96 const struct GNUNET_CONFIGURATION_Handle *cfg;
99 unsigned long long size;
110 run_continuation (void *cls,
111 const struct GNUNET_SCHEDULER_TaskContext *tc);
117 check_success (void *cls,
121 struct CpsRunContext *crc = cls;
122 if (GNUNET_OK != success)
123 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
125 GNUNET_assert (GNUNET_OK == success);
127 fprintf (stderr, "I");
129 stored_bytes += crc->size;
133 if (crc->j == PUT_10)
137 if (crc->i == ITERATIONS)
138 crc->phase = RP_DONE;
142 GNUNET_SCHEDULER_add_continuation (crc->sched,
146 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
151 * Continuation called to notify client about result of the
155 * @param success GNUNET_SYSERR on failure
156 * @param msg NULL on success, otherwise an error message
159 remove_next(void *cls,
163 struct CpsRunContext *crc = cls;
166 fprintf (stderr, "D");
168 GNUNET_assert (GNUNET_OK == success);
169 GNUNET_SCHEDULER_add_continuation (crc->sched,
173 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
179 do_delete (void *cls,
180 const struct GNUNET_SCHEDULER_TaskContext *tc)
182 struct CpsRunContext *crc = cls;
184 stored_bytes -= crc->esize;
187 GNUNET_DATASTORE_remove (datastore,
199 delete_value (void *cls,
200 const GNUNET_HashCode * key,
206 struct GNUNET_TIME_Absolute
207 expiration, uint64_t uid)
209 struct CpsRunContext *crc = cls;
213 if (stored_bytes < MAX_SIZE)
215 crc->phase = RP_REPORT;
216 GNUNET_SCHEDULER_add_continuation (crc->sched,
220 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
223 GNUNET_SCHEDULER_add_after (crc->sched,
225 GNUNET_SCHEDULER_PRIORITY_HIGH,
226 GNUNET_SCHEDULER_NO_TASK,
232 if (stored_bytes < MAX_SIZE)
234 GNUNET_DATASTORE_get_next (datastore, GNUNET_YES);
239 memcpy (crc->data, data, size);
240 GNUNET_DATASTORE_get_next (datastore, GNUNET_YES);
245 run_continuation (void *cls,
246 const struct GNUNET_SCHEDULER_TaskContext *tc)
248 struct CpsRunContext *crc = cls;
250 static GNUNET_HashCode key;
251 static char data[65536];
255 ok = (int) crc->phase;
259 memset (&key, 256 - crc->i, sizeof (GNUNET_HashCode));
262 /* most content is 32k */
264 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */
265 size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
266 crc->size = size = size - (size & 7); /* always multiple of 8 */
267 GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &key);
268 memset (data, i, size);
270 memset (data, i - 255, size / 2);
272 GNUNET_DATASTORE_put (datastore,
278 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100),
280 GNUNET_TIME_relative_to_absolute
281 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
282 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
288 /* trim down below MAX_SIZE again */
289 GNUNET_DATASTORE_get_random (datastore,
299 "Stored %llu kB / %lluk ops / %llu ops/s\n",
300 stored_bytes / 1024, /* used size in k */
301 stored_ops / 1024, /* total operations (in k) */
302 1000 * stored_ops / (1 + GNUNET_TIME_absolute_get_duration(start_time).value));
305 GNUNET_SCHEDULER_add_continuation (crc->sched,
309 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
312 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
324 struct GNUNET_SCHEDULER_Handle *sched,
327 const struct GNUNET_CONFIGURATION_Handle *cfg)
329 struct CpsRunContext *crc;
331 datastore = GNUNET_DATASTORE_connect (cfg, sched);
332 start_time = GNUNET_TIME_absolute_get ();
333 crc = GNUNET_malloc(sizeof(struct CpsRunContext));
337 GNUNET_SCHEDULER_add_continuation (crc->sched,
341 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
349 char *const argv[] = {
350 "perf-datastore-api",
352 "test_datastore_api_data.conf",
358 struct GNUNET_GETOPT_CommandLineOption options[] = {
359 GNUNET_GETOPT_OPTION_END
361 pid = GNUNET_OS_start_process ("gnunet-service-arm",
362 "gnunet-service-arm",
366 "-c", "test_datastore_api_data.conf", NULL);
368 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
369 argv, "perf-datastore-api", "nohelp",
370 options, &run, NULL);
371 if (0 != PLIBC_KILL (pid, SIGTERM))
373 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
376 GNUNET_OS_process_wait(pid);
382 main (int argc, char *argv[])
386 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-datastore");
387 GNUNET_log_setup ("perf-datastore-api",
396 fprintf (stderr, "\n");
398 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-datastore");
403 /* end of perf_datastore_api.c */