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 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., 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;
54 static const char *plugin_name;
73 struct GNUNET_TIME_Absolute start;
74 struct GNUNET_TIME_Absolute end;
75 struct GNUNET_SCHEDULER_Handle *sched;
76 const struct GNUNET_CONFIGURATION_Handle *cfg;
77 struct GNUNET_DATASTORE_PluginFunctions * api;
86 putValue (struct GNUNET_DATASTORE_PluginFunctions * api, int i, int k)
90 static GNUNET_HashCode key;
95 /* most content is 32k */
98 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */
99 size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
100 size = size - (size & 7); /* always multiple of 8 */
102 /* generate random key */
103 key.bits[0] = (unsigned int) GNUNET_TIME_absolute_get ().value;
104 GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &key);
105 memset (value, i, size);
107 memset (value, i - 255, size / 2);
110 prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
111 if (GNUNET_OK != api->put (api->cls,
118 GNUNET_TIME_relative_to_absolute
119 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
120 60 * 60 * 60 * 1000 +
121 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
124 fprintf (stderr, "ERROR: `%s'\n", msg);
125 GNUNET_free_non_null (msg);
129 stored_bytes += size;
136 const struct GNUNET_SCHEDULER_TaskContext *tc);
140 iterateDummy (void *cls,
142 const GNUNET_HashCode * key,
145 enum GNUNET_BLOCK_Type type,
148 struct GNUNET_TIME_Absolute
152 struct CpsRunContext *crc = cls;
156 crc->end = GNUNET_TIME_absolute_get();
159 (unsigned long long) (crc->end.value - crc->start.value),
161 if (crc->phase != RP_AN_GET)
167 if (crc->i == ITERATIONS)
168 crc->phase = RP_DONE;
172 GNUNET_SCHEDULER_add_after (crc->sched,
173 GNUNET_SCHEDULER_NO_TASK,
178 fprintf (stderr, "Found result type=%u, priority=%u, size=%u, expire=%llu\n",
179 type, priority, size,
180 (unsigned long long) expiration.value);
183 crc->api->next_request (next_cls,
191 * Function called when the service shuts
192 * down. Unloads our datastore plugin.
194 * @param api api to unload
195 * @param cfg configuration to use
198 unload_plugin (struct GNUNET_DATASTORE_PluginFunctions * api,
199 const struct GNUNET_CONFIGURATION_Handle *cfg)
205 GNUNET_CONFIGURATION_get_value_string (cfg,
206 "DATASTORE", "DATABASE", &name))
208 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
209 _("No `%s' specified for `%s' in configuration!\n"),
214 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
215 GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api));
216 GNUNET_free (libname);
223 * Last task run during shutdown. Disconnects us from
224 * the transport and core.
227 cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
229 struct CpsRunContext *crc = cls;
231 unload_plugin (crc->api, crc->cfg);
238 const struct GNUNET_SCHEDULER_TaskContext *tc)
240 struct CpsRunContext *crc = cls;
246 crc->start = GNUNET_TIME_absolute_get ();
247 for (j=0;j<PUT_10;j++)
248 putValue (crc->api, j, crc->i);
249 crc->end = GNUNET_TIME_absolute_get ();
250 printf ("%3u insertion took %20llums for %u\n",
252 (unsigned long long) (crc->end.value - crc->start.value),
253 (unsigned int) PUT_10);
255 crc->phase = RP_LP_GET;
256 GNUNET_SCHEDULER_add_after (crc->sched,
257 GNUNET_SCHEDULER_NO_TASK,
262 crc->start = GNUNET_TIME_absolute_get ();
263 crc->msg = "%3u low priority iteration took %20llums for %u\n";
264 crc->api->iter_low_priority (crc->api->cls, 0,
270 crc->start = GNUNET_TIME_absolute_get ();
271 crc->msg = "%3u ascending expiration iteration took %20llums for %u\n";
272 crc->api->iter_ascending_expiration (crc->api->cls, 0,
278 crc->start = GNUNET_TIME_absolute_get ();
279 crc->msg = "%3u zero anonymity iteration took %20llums for %u\n";
280 crc->api->iter_zero_anonymity (crc->api->cls, 0,
286 crc->start = GNUNET_TIME_absolute_get ();
287 crc->msg = "%3u migration order iteration took %20llums for %u\n";
288 crc->api->iter_migration_order (crc->api->cls, 0,
294 crc->start = GNUNET_TIME_absolute_get ();
295 crc->msg = "%3u all now iteration took %20llums for %u\n";
296 crc->api->iter_all_now (crc->api->cls, 0,
301 crc->api->drop (crc->api->cls);
302 GNUNET_SCHEDULER_add_with_priority (crc->sched,
303 GNUNET_SCHEDULER_PRIORITY_IDLE,
304 &cleaning_task, crc);
311 * Load the datastore plugin.
313 static struct GNUNET_DATASTORE_PluginFunctions *
314 load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg,
315 struct GNUNET_SCHEDULER_Handle *sched)
317 static struct GNUNET_DATASTORE_PluginEnvironment env;
318 struct GNUNET_DATASTORE_PluginFunctions * ret;
323 GNUNET_CONFIGURATION_get_value_string (cfg,
324 "DATASTORE", "DATABASE", &name))
326 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
327 _("No `%s' specified for `%s' in configuration!\n"),
334 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
335 _("Loading `%s' datastore plugin\n"), name);
336 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
337 GNUNET_assert (NULL != (ret = GNUNET_PLUGIN_load (libname, &env)));
338 GNUNET_free (libname);
346 struct GNUNET_SCHEDULER_Handle *s,
349 const struct GNUNET_CONFIGURATION_Handle *c)
351 struct GNUNET_DATASTORE_PluginFunctions *api;
352 struct CpsRunContext *crc;
354 api = load_plugin (c, s);
355 GNUNET_assert (api != NULL);
356 crc = GNUNET_malloc(sizeof(struct CpsRunContext));
361 GNUNET_SCHEDULER_add_after (s,
362 GNUNET_SCHEDULER_NO_TASK,
371 char *const argv[] = {
372 "perf-plugin-datastore",
380 struct GNUNET_GETOPT_CommandLineOption options[] = {
381 GNUNET_GETOPT_OPTION_END
384 GNUNET_snprintf (cfg_name,
386 "perf_plugin_datastore_data_%s.conf",
388 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
389 argv, "perf-plugin-datastore", "nohelp",
390 options, &run, NULL);
392 fprintf (stderr, "Missed some testcases: %u\n", ok);
398 main (int argc, char *argv[])
404 /* determine name of plugin to use */
405 plugin_name = argv[0];
406 while (NULL != (pos = strstr(plugin_name, "_")))
409 GNUNET_snprintf (dir_name,
411 "/tmp/perf-gnunet-datastore-%s",
413 GNUNET_DISK_directory_remove (dir_name);
414 GNUNET_log_setup ("perf-plugin-datastore",
422 GNUNET_DISK_directory_remove (dir_name);
427 /* end of perf_plugin_datastore.c */