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 "gnunet_datastore_plugin.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 const struct GNUNET_CONFIGURATION_Handle *cfg;
76 struct GNUNET_DATASTORE_PluginFunctions * api;
84 * Function called by plugins to notify us about a
85 * change in their disk utilization.
87 * @param cls closure (NULL)
88 * @param delta change in disk utilization,
89 * 0 for "reset to empty"
92 disk_utilization_change_cb (void *cls,
99 putValue (struct GNUNET_DATASTORE_PluginFunctions * api, int i, int k)
103 static GNUNET_HashCode key;
108 /* most content is 32k */
111 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */
112 size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
113 size = size - (size & 7); /* always multiple of 8 */
115 /* generate random key */
116 key.bits[0] = (unsigned int) GNUNET_TIME_absolute_get ().abs_value;
117 GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &key);
118 memset (value, i, size);
120 memset (value, i - 255, size / 2);
123 prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
124 if (GNUNET_OK != api->put (api->cls,
132 GNUNET_TIME_relative_to_absolute
133 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
134 60 * 60 * 60 * 1000 +
135 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
138 fprintf (stderr, "ERROR: `%s'\n", msg);
139 GNUNET_free_non_null (msg);
143 stored_bytes += size;
150 const struct GNUNET_SCHEDULER_TaskContext *tc);
154 iterateDummy (void *cls,
156 const GNUNET_HashCode * key,
159 enum GNUNET_BLOCK_Type type,
162 struct GNUNET_TIME_Absolute
166 struct CpsRunContext *crc = cls;
170 crc->end = GNUNET_TIME_absolute_get();
173 (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
175 if (crc->phase != RP_AN_GET)
181 if (crc->i == ITERATIONS)
182 crc->phase = RP_DONE;
186 GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_NO_TASK,
191 fprintf (stderr, "Found result type=%u, priority=%u, size=%u, expire=%llu\n",
192 type, priority, size,
193 (unsigned long long) expiration.abs_value);
196 crc->api->next_request (next_cls,
204 * Function called when the service shuts
205 * down. Unloads our datastore plugin.
207 * @param api api to unload
208 * @param cfg configuration to use
211 unload_plugin (struct GNUNET_DATASTORE_PluginFunctions * api,
212 const struct GNUNET_CONFIGURATION_Handle *cfg)
218 GNUNET_CONFIGURATION_get_value_string (cfg,
219 "DATASTORE", "DATABASE", &name))
221 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
222 _("No `%s' specified for `%s' in configuration!\n"),
227 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
228 GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api));
229 GNUNET_free (libname);
236 * Last task run during shutdown. Disconnects us from
237 * the transport and core.
240 cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
242 struct CpsRunContext *crc = cls;
244 unload_plugin (crc->api, crc->cfg);
251 const struct GNUNET_SCHEDULER_TaskContext *tc)
253 struct CpsRunContext *crc = cls;
259 crc->start = GNUNET_TIME_absolute_get ();
260 for (j=0;j<PUT_10;j++)
261 putValue (crc->api, j, crc->i);
262 crc->end = GNUNET_TIME_absolute_get ();
263 printf ("%3u insertion took %20llums for %u\n",
265 (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
266 (unsigned int) PUT_10);
268 crc->phase = RP_LP_GET;
269 GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_NO_TASK,
274 crc->start = GNUNET_TIME_absolute_get ();
275 crc->msg = "%3u low priority iteration took %20llums for %u\n";
276 crc->api->iter_low_priority (crc->api->cls, 0,
282 crc->start = GNUNET_TIME_absolute_get ();
283 crc->msg = "%3u ascending expiration iteration took %20llums for %u\n";
284 crc->api->iter_ascending_expiration (crc->api->cls, 0,
290 crc->start = GNUNET_TIME_absolute_get ();
291 crc->msg = "%3u zero anonymity iteration took %20llums for %u\n";
292 crc->api->iter_zero_anonymity (crc->api->cls, 0,
298 crc->start = GNUNET_TIME_absolute_get ();
299 crc->msg = "%3u migration order iteration took %20llums for %u\n";
300 crc->api->iter_migration_order (crc->api->cls, 0,
306 crc->start = GNUNET_TIME_absolute_get ();
307 crc->msg = "%3u all now iteration took %20llums for %u\n";
308 crc->api->iter_all_now (crc->api->cls, 0,
313 crc->api->drop (crc->api->cls);
314 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
315 &cleaning_task, crc);
322 * Load the datastore plugin.
324 static struct GNUNET_DATASTORE_PluginFunctions *
325 load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
327 static struct GNUNET_DATASTORE_PluginEnvironment env;
328 struct GNUNET_DATASTORE_PluginFunctions * ret;
333 GNUNET_CONFIGURATION_get_value_string (cfg,
334 "DATASTORE", "DATABASE", &name))
336 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
337 _("No `%s' specified for `%s' in configuration!\n"),
343 env.duc = &disk_utilization_change_cb;
345 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
346 _("Loading `%s' datastore plugin\n"), name);
347 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
348 if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env)))
351 "Failed to load plugin `%s'!\n",
355 GNUNET_free (libname);
365 const struct GNUNET_CONFIGURATION_Handle *c)
367 struct GNUNET_DATASTORE_PluginFunctions *api;
368 struct CpsRunContext *crc;
370 api = load_plugin (c);
374 "Could not initialize plugin, assuming database not configured. Test not run!\n");
377 crc = GNUNET_malloc(sizeof(struct CpsRunContext));
381 GNUNET_SCHEDULER_add_now (&test, crc);
389 char *const argv[] = {
390 "perf-plugin-datastore",
398 struct GNUNET_GETOPT_CommandLineOption options[] = {
399 GNUNET_GETOPT_OPTION_END
402 GNUNET_snprintf (cfg_name,
404 "perf_plugin_datastore_data_%s.conf",
406 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
407 argv, "perf-plugin-datastore", "nohelp",
408 options, &run, NULL);
410 fprintf (stderr, "Missed some testcases: %u\n", ok);
416 main (int argc, char *argv[])
422 /* determine name of plugin to use */
423 plugin_name = argv[0];
424 while (NULL != (pos = strstr(plugin_name, "_")))
426 if (NULL != (pos = strstr(plugin_name, ".")))
429 pos = (char *) plugin_name;
431 GNUNET_snprintf (dir_name,
433 "/tmp/perf-gnunet-datastore-%s",
435 GNUNET_DISK_directory_remove (dir_name);
436 GNUNET_log_setup ("perf-plugin-datastore",
444 if (pos != plugin_name)
446 GNUNET_DISK_directory_remove (dir_name);
451 /* end of perf_plugin_datastore.c */