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 perf_plugin_datastore.c
22 * @brief Profile database plugin directly, focusing on iterators.
23 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_protocols.h"
29 #include "plugin_datastore.h"
31 #define VERBOSE GNUNET_NO
34 * Target datastore size (in bytes). Realistic sizes are
35 * more like 16 GB (not the default of 16 MB); however,
36 * those take too long to run them in the usual "make check"
37 * sequence. Hence the value used for shipping is tiny.
39 #define MAX_SIZE 1024LL * 1024 * 128
44 * Number of put operations equivalent to 1/10th of MAX_SIZE
46 #define PUT_10 (MAX_SIZE / 32 / 1024 / ITERATIONS)
48 static unsigned long long stored_bytes;
50 static unsigned long long stored_entries;
52 static unsigned long long stored_ops;
71 struct GNUNET_TIME_Absolute start;
72 struct GNUNET_TIME_Absolute end;
73 struct GNUNET_SCHEDULER_Handle *sched;
74 struct GNUNET_CONFIGURATION_Handle *cfg;
75 struct GNUNET_DATASTORE_PluginFunctions * api;
84 putValue (struct GNUNET_DATASTORE_PluginFunctions * api, int i, int k)
88 static GNUNET_HashCode key;
92 /* most content is 32k */
95 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */
96 size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
97 size = size - (size & 7); /* always multiple of 8 */
99 /* generate random key */
100 key.bits[0] = (unsigned int) GNUNET_TIME_absolute_get ().value;
101 GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &key);
102 memset (value, i, size);
104 memset (value, i - 255, size / 2);
107 if (GNUNET_OK != api->put (api->cls,
112 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100),
114 GNUNET_TIME_relative_to_absolute
115 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
116 60 * 60 * 60 * 1000 +
117 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
120 fprintf (stderr, "ERROR: `%s'\n", msg);
121 GNUNET_free_non_null (msg);
125 stored_bytes += size;
132 const struct GNUNET_SCHEDULER_TaskContext *tc);
136 iterateDummy (void *cls,
138 const GNUNET_HashCode * key,
144 struct GNUNET_TIME_Absolute
148 struct CpsRunContext *crc = cls;
152 crc->end = GNUNET_TIME_absolute_get();
155 (unsigned long long) (crc->end.value - crc->start.value),
157 if (crc->phase != RP_AN_GET)
163 if (crc->i == ITERATIONS)
164 crc->phase = RP_DONE;
168 GNUNET_SCHEDULER_add_after (crc->sched,
170 GNUNET_SCHEDULER_PRIORITY_KEEP,
171 GNUNET_SCHEDULER_NO_PREREQUISITE_TASK,
176 crc->api->next_request (next_cls,
184 * Function called when the service shuts
185 * down. Unloads our datastore plugin.
187 * @param api api to unload
190 unload_plugin (struct GNUNET_DATASTORE_PluginFunctions * api,
191 struct GNUNET_CONFIGURATION_Handle *cfg)
197 GNUNET_CONFIGURATION_get_value_string (cfg,
198 "DATASTORE", "DATABASE", &name))
200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
201 _("No `%s' specified for `%s' in configuration!\n"),
206 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
207 GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api));
208 GNUNET_free (libname);
215 * Last task run during shutdown. Disconnects us from
216 * the transport and core.
219 cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
221 struct CpsRunContext *crc = cls;
223 unload_plugin (crc->api, crc->cfg);
230 const struct GNUNET_SCHEDULER_TaskContext *tc)
232 struct CpsRunContext *crc = cls;
238 crc->start = GNUNET_TIME_absolute_get ();
239 for (j=0;j<PUT_10;j++)
240 putValue (crc->api, j, crc->i);
241 crc->end = GNUNET_TIME_absolute_get ();
242 printf ("%3u insertion took %20llums for %u\n",
244 (unsigned long long) (crc->end.value - crc->start.value),
245 (unsigned int) PUT_10);
247 crc->phase = RP_LP_GET;
248 GNUNET_SCHEDULER_add_after (crc->sched,
250 GNUNET_SCHEDULER_PRIORITY_KEEP,
251 GNUNET_SCHEDULER_NO_PREREQUISITE_TASK,
256 crc->start = GNUNET_TIME_absolute_get ();
257 crc->msg = "%3u low priority iteration took %20llums for %u\n";
258 crc->api->iter_low_priority (crc->api->cls, 0,
264 crc->start = GNUNET_TIME_absolute_get ();
265 crc->msg = "%3u ascending expiration iteration took %20llums for %u\n";
266 crc->api->iter_ascending_expiration (crc->api->cls, 0,
272 crc->start = GNUNET_TIME_absolute_get ();
273 crc->msg = "%3u zero anonymity iteration took %20llums for %u\n";
274 crc->api->iter_zero_anonymity (crc->api->cls, 0,
280 crc->start = GNUNET_TIME_absolute_get ();
281 crc->msg = "%3u migration order iteration took %20llums for %u\n";
282 crc->api->iter_migration_order (crc->api->cls, 0,
288 crc->start = GNUNET_TIME_absolute_get ();
289 crc->msg = "%3u all now iteration took %20llums for %u\n";
290 crc->api->iter_all_now (crc->api->cls, 0,
295 crc->api->drop (crc->api->cls);
296 GNUNET_SCHEDULER_add_delayed (crc->sched,
298 GNUNET_SCHEDULER_PRIORITY_IDLE,
299 GNUNET_SCHEDULER_NO_PREREQUISITE_TASK,
300 GNUNET_TIME_UNIT_ZERO,
301 &cleaning_task, crc);
308 * Load the datastore plugin.
310 static struct GNUNET_DATASTORE_PluginFunctions *
311 load_plugin (struct GNUNET_CONFIGURATION_Handle *cfg,
312 struct GNUNET_SCHEDULER_Handle *sched)
314 static struct GNUNET_DATASTORE_PluginEnvironment env;
315 struct GNUNET_DATASTORE_PluginFunctions * ret;
320 GNUNET_CONFIGURATION_get_value_string (cfg,
321 "DATASTORE", "DATABASE", &name))
323 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
324 _("No `%s' specified for `%s' in configuration!\n"),
331 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
332 _("Loading `%s' datastore plugin\n"), name);
333 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
334 GNUNET_assert (NULL != (ret = GNUNET_PLUGIN_load (libname, &env)));
335 GNUNET_free (libname);
343 struct GNUNET_SCHEDULER_Handle *s,
346 struct GNUNET_CONFIGURATION_Handle *c)
348 struct GNUNET_DATASTORE_PluginFunctions *api;
349 struct CpsRunContext *crc;
351 api = load_plugin (c, s);
352 GNUNET_assert (api != NULL);
353 crc = GNUNET_malloc(sizeof(struct CpsRunContext));
358 GNUNET_SCHEDULER_add_after (s,
360 GNUNET_SCHEDULER_PRIORITY_KEEP,
361 GNUNET_SCHEDULER_NO_PREREQUISITE_TASK,
369 char *const argv[] = {
370 "perf-plugin-datastore",
372 "perf_plugin_datastore_data.conf",
378 struct GNUNET_GETOPT_CommandLineOption options[] = {
379 GNUNET_GETOPT_OPTION_END
381 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
382 argv, "perf-plugin-datastore", "nohelp",
383 options, &run, NULL);
385 fprintf (stderr, "Missed some testcases: %u\n", ok);
391 main (int argc, char *argv[])
395 GNUNET_log_setup ("perf-plugin-datastore",
408 /* end of perf_plugin_datastore.c */