aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-06-17 02:50:43 +0000
committerChristian Grothoff <christian@grothoff.org>2009-06-17 02:50:43 +0000
commit440bab102fc945dd51bd98f07e25f9375f58fa21 (patch)
tree7acd470a20d934ab0638aba602b1f5c0918d81a8
parent4ac29e4a039e4f403a03f3bfb959c1bef4501846 (diff)
downloadgnunet-440bab102fc945dd51bd98f07e25f9375f58fa21.tar.gz
gnunet-440bab102fc945dd51bd98f07e25f9375f58fa21.zip
making tests compile
-rw-r--r--src/datastore/gnunet-service-datastore.c3
-rw-r--r--src/datastore/perf_datastore_api.c37
-rw-r--r--src/datastore/perf_datastore_api_iterators.c327
-rw-r--r--src/datastore/test_datastore_api_data.conf1
4 files changed, 225 insertions, 143 deletions
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c
index 98905dbd4..bdb8458e7 100644
--- a/src/datastore/gnunet-service-datastore.c
+++ b/src/datastore/gnunet-service-datastore.c
@@ -789,8 +789,7 @@ load_plugin (struct GNUNET_CONFIGURATION_Handle *cfg,
789 * Function called when the service shuts 789 * Function called when the service shuts
790 * down. Unloads our datastore plugin. 790 * down. Unloads our datastore plugin.
791 * 791 *
792 * @param cls closure 792 * @param plug plugin to unload
793 * @param cfg configuration to use
794 */ 793 */
795static void 794static void
796unload_plugin (struct DatastorePlugin *plug) 795unload_plugin (struct DatastorePlugin *plug)
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c
index 7b3b6cfff..95ee18dad 100644
--- a/src/datastore/perf_datastore_api.c
+++ b/src/datastore/perf_datastore_api.c
@@ -31,14 +31,6 @@
31 * strategy alternates between "lowest priority" and "earliest expiration". 31 * strategy alternates between "lowest priority" and "earliest expiration".
32 * Priorities and expiration dates are set using a pseudo-random value 32 * Priorities and expiration dates are set using a pseudo-random value
33 * within a realistic range. 33 * within a realistic range.
34 * <p>
35 *
36 * Note that the disk overhead calculations are not very sane for
37 * MySQL: we take the entire /var/lib/mysql directory (best we can
38 * do for ISAM), which may contain other data and which never
39 * shrinks. The scanning of the entire mysql directory during
40 * each report is also likely to be the cause of a minor
41 * slowdown compared to sqlite.<p>
42 */ 34 */
43 35
44#include "platform.h" 36#include "platform.h"
@@ -103,13 +95,6 @@ static struct GNUNET_DATASTORE_Handle *datastore;
103 */ 95 */
104#define ITERATIONS 100 96#define ITERATIONS 100
105 97
106/**
107 * Name of the database on disk.
108 * You may have to adjust this path and the access
109 * permission to the respective directory in order
110 * to obtain all of the performance information.
111 */
112#define DB_NAME "/tmp/gnunet-datastore-test/data/fs/"
113 98
114static unsigned long long stored_bytes; 99static unsigned long long stored_bytes;
115 100
@@ -186,12 +171,12 @@ run (void *cls,
186{ 171{
187 int j; 172 int j;
188 unsigned long long size; 173 unsigned long long size;
189 int have_file;
190 struct stat sbuf;
191 int i; 174 int i;
192 175
193 datastore = GNUNET_DATASTORE_connect (cfg, sched); 176 datastore = GNUNET_DATASTORE_connect (cfg, sched);
194 have_file = 0 == stat (DB_NAME, &sbuf); 177 /* FIXME: change loop to use CPS; current
178 datastore API will likely react negative to
179 us ignoring the callbacks... */
195 for (i = 0; i < ITERATIONS; i++) 180 for (i = 0; i < ITERATIONS; i++)
196 { 181 {
197#if REPORT_ID 182#if REPORT_ID
@@ -205,22 +190,15 @@ run (void *cls,
205 if ((i % 2) == 0) 190 if ((i % 2) == 0)
206 GNUNET_DATASTORE_get_random (datastore, &iterate_delete, NULL); 191 GNUNET_DATASTORE_get_random (datastore, &iterate_delete, NULL);
207 size = 0; 192 size = 0;
208 if (have_file)
209 GNUNET_disk_file_size (NULL, DB_NAME, &size, GNUNET_NO);
210 printf ( 193 printf (
211#if REPORT_ID 194#if REPORT_ID
212 "\n" 195 "\n"
213#endif 196#endif
214 "Useful %llu, disk %llu (%.2f%%) / %lluk ops / %llu ops/s\n", 197 "Stored %llu kB / %lluk ops / %llu ops/s\n",
215 stored_bytes / 1024, /* used size in k */ 198 stored_bytes / 1024, /* used size in k */
216 size / 1024, /* disk size in kb */
217 (100.0 * size / stored_bytes) - 100, /* overhead */
218 (stored_ops * 2 - stored_entries) / 1024, /* total operations (in k) */ 199 (stored_ops * 2 - stored_entries) / 1024, /* total operations (in k) */
219 1000 * (stored_ops * 2 - stored_entries) / (1 + GNUNET_get_time () - start_time)); /* operations per second */ 200 1000 * (stored_ops * 2 - stored_entries) / (1 + GNUNET_TIME_absolute_get_duration(start_time).value)); /* operations per second */
220 if (GNUNET_shutdown_test () == GNUNET_YES)
221 break;
222 } 201 }
223
224 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); 202 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
225} 203}
226 204
@@ -246,7 +224,7 @@ check ()
246#if VERBOSE 224#if VERBOSE
247 "-L", "DEBUG", 225 "-L", "DEBUG",
248#endif 226#endif
249 "-c", "perf_datastore_api_data.conf", NULL); 227 "-c", "test_datastore_api_data.conf", NULL);
250 sleep (1); 228 sleep (1);
251 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 229 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
252 argv, "perf-datastore-api", "nohelp", 230 argv, "perf-datastore-api", "nohelp",
@@ -281,7 +259,4 @@ main (int argc, char *argv[])
281} 259}
282 260
283 261
284
285
286
287/* end of perf_datastore_api.c */ 262/* end of perf_datastore_api.c */
diff --git a/src/datastore/perf_datastore_api_iterators.c b/src/datastore/perf_datastore_api_iterators.c
index 115112faf..328cceb75 100644
--- a/src/datastore/perf_datastore_api_iterators.c
+++ b/src/datastore/perf_datastore_api_iterators.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2004, 2005, 2006, 2007 Christian Grothoff (and other contributing authors) 3 (C) 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -18,16 +18,15 @@
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20/* 20/*
21 * @file applications/sqstore_sqlite/sqlitetest3.c 21 * @file perf_datastore_api_iterators.c
22 * @brief Profile sqstore iterators. 22 * @brief Profile database plugin directly, focusing on iterators.
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 */ 24 */
25 25
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_protocols.h" 28#include "gnunet_protocols.h"
29#include "gnunet_sqstore_service.h" 29#include "plugin_datastore.h"
30#include "core.h"
31 30
32/** 31/**
33 * Target datastore size (in bytes). Realistic sizes are 32 * Target datastore size (in bytes). Realistic sizes are
@@ -50,159 +49,267 @@ static unsigned long long stored_entries;
50 49
51static unsigned long long stored_ops; 50static unsigned long long stored_ops;
52 51
53static GNUNET_CronTime start_time; 52static struct GNUNET_CONFIGURATION_Handle *cfg;
54 53
54static struct GNUNET_SCHEDULER_Handle *sched;
55
55static int 56static int
56putValue (GNUNET_SQstore_ServiceAPI * api, int i, int k) 57putValue (struct GNUNET_DATASTORE_PluginFunctions * api, int i, int k)
57{ 58{
58 GNUNET_DatastoreValue *value; 59 char value[65536];
59 size_t size; 60 size_t size;
60 static GNUNET_HashCode key; 61 static GNUNET_HashCode key;
61 static int ic; 62 static int ic;
63 char *msg;
62 64
63 /* most content is 32k */ 65 /* most content is 32k */
64 size = sizeof (GNUNET_DatastoreValue) + 32 * 1024; 66 size = 32 * 1024;
65 67
66 if (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 16) == 0) /* but some of it is less! */ 68 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */
67 size = 69 size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
68 sizeof (GNUNET_DatastoreValue) +
69 GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 32 * 1024);
70 size = size - (size & 7); /* always multiple of 8 */ 70 size = size - (size & 7); /* always multiple of 8 */
71 71
72 /* generate random key */ 72 /* generate random key */
73 key.bits[0] = (unsigned int) GNUNET_get_time (); 73 key.bits[0] = (unsigned int) GNUNET_TIME_absolute_get ().value;
74 GNUNET_hash (&key, sizeof (GNUNET_HashCode), &key); 74 GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &key);
75 value = GNUNET_malloc (size); 75 memset (value, i, size);
76 value->size = htonl (size);
77 value->type = htonl (i);
78 value->priority =
79 htonl (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 100));
80 value->anonymity_level = htonl (i);
81 value->expiration_time =
82 GNUNET_htonll (GNUNET_get_time () + 60 * GNUNET_CRON_HOURS +
83 GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 1000));
84 memset (&value[1], i, size - sizeof (GNUNET_DatastoreValue));
85 if (i > 255) 76 if (i > 255)
86 memset (&value[1], i - 255, (size - sizeof (GNUNET_DatastoreValue)) / 2); 77 memset (value, i - 255, size / 2);
87 ((char *) &value[1])[0] = k; 78 value[0] = k;
88 if (GNUNET_OK != api->put (&key, value)) 79 msg = NULL;
80 if (GNUNET_OK != api->put (api->cls,
81 &key,
82 size,
83 value,
84 i,
85 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100),
86 i,
87 GNUNET_TIME_relative_to_absolute
88 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
89 60 * 60 * 60 * 1000 +
90 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
91 &msg));
89 { 92 {
90 GNUNET_free (value); 93 fprintf (stderr, "E: `%s'", msg);
91 fprintf (stderr, "E"); 94 GNUNET_free_non_null (msg);
92 return GNUNET_SYSERR; 95 return GNUNET_SYSERR;
93 } 96 }
94 ic++; 97 ic++;
95 stored_bytes += ntohl (value->size); 98 stored_bytes += size;
96 stored_ops++; 99 stored_ops++;
97 stored_entries++; 100 stored_entries++;
98 GNUNET_free (value); 101 GNUNET_free (value);
99 return GNUNET_OK; 102 return GNUNET_OK;
100} 103}
101 104
105
102static int 106static int
103iterateDummy (const GNUNET_HashCode * key, const GNUNET_DatastoreValue * val, 107iterateDummy (void *cls,
104 void *cls, unsigned long long uid) 108 void *next_cls,
109 const GNUNET_HashCode * key,
110 uint32_t size,
111 const void *data,
112 uint32_t type,
113 uint32_t priority,
114 uint32_t anonymity,
115 struct GNUNET_TIME_Absolute
116 expiration,
117 uint64_t uid)
105{ 118{
106 if (GNUNET_shutdown_test () == GNUNET_YES)
107 return GNUNET_SYSERR;
108 return GNUNET_OK; 119 return GNUNET_OK;
109} 120}
110 121
111static int 122static int
112test (GNUNET_SQstore_ServiceAPI * api) 123test (struct GNUNET_DATASTORE_PluginFunctions * api)
113{ 124{
114 int i; 125 int i;
115 int j; 126 int j;
116 int ret; 127 struct GNUNET_TIME_Absolute start;
117 GNUNET_CronTime start; 128 struct GNUNET_TIME_Absolute end;
118 GNUNET_CronTime end;
119 129
130 /* FIXME: CPS the loop! */
120 for (i = 0; i < ITERATIONS; i++) 131 for (i = 0; i < ITERATIONS; i++)
121 { 132 {
122 /* insert data equivalent to 1/10th of MAX_SIZE */ 133 /* insert data equivalent to 1/10th of MAX_SIZE */
123 start = GNUNET_get_time (); 134 start = GNUNET_TIME_absolute_get ();
124 for (j = 0; j < PUT_10; j++) 135 for (j = 0; j < PUT_10; j++)
125 { 136 {
126 if (GNUNET_OK != putValue (api, j, i)) 137 if (GNUNET_OK != putValue (api, j, i))
127 break; 138 break;
128 if (GNUNET_shutdown_test () == GNUNET_YES)
129 break;
130 } 139 }
131 end = GNUNET_get_time (); 140 end = GNUNET_TIME_absolute_get ();
132 printf ("%3u insertion took %20llums\n", i, end - start); 141 printf ("%3u insertion took %20llums\n", i, end.value - start.value);
133 if (GNUNET_shutdown_test () == GNUNET_YES) 142 start = end;
134 break; 143 api->iter_low_priority (api->cls, 0, &iterateDummy, api);
135 start = GNUNET_get_time (); 144 end = GNUNET_TIME_absolute_get ();
136 ret = api->iterateLowPriority (0, &iterateDummy, api); 145 printf ("%3u low priority iteration took %20llums\n", i,
137 end = GNUNET_get_time (); 146 end.value - start.value);
138 printf ("%3u low priority iteration took %20llums (%d)\n", i, 147 start = end;
139 end - start, ret); 148 api->iter_ascending_expiration (api->cls, 0, &iterateDummy, api);
140 if (GNUNET_shutdown_test () == GNUNET_YES) 149 end = GNUNET_TIME_absolute_get ();
141 break; 150 printf ("%3u expiration t iteration took %20llums\n", i,
142 start = GNUNET_get_time (); 151 end.value - start.value);
143 ret = api->iterateExpirationTime (0, &iterateDummy, api); 152 start = end;
144 end = GNUNET_get_time (); 153 api->iter_zero_anonymity (api->cls, 0, &iterateDummy, api);
145 printf ("%3u expiration t iteration took %20llums (%d)\n", i, 154 end = GNUNET_TIME_absolute_get ();
146 end - start, ret); 155 printf ("%3u non anonymou iteration took %20llums\n", i,
147 if (GNUNET_shutdown_test () == GNUNET_YES) 156 end.value - start.value);
148 break; 157 start = end;
149 start = GNUNET_get_time (); 158 api->iter_migration_order (api->cls, 0, &iterateDummy, api);
150 ret = api->iterateNonAnonymous (0, &iterateDummy, api); 159 end = GNUNET_TIME_absolute_get ();
151 end = GNUNET_get_time (); 160 printf ("%3u migration or iteration took %20llums\n", i,
152 printf ("%3u non anonymou iteration took %20llums (%d)\n", i, 161 end.value - start.value);
153 end - start, ret); 162 start = end;
154 if (GNUNET_shutdown_test () == GNUNET_YES) 163 api->iter_all_now (api->cls, 0, &iterateDummy, api);
155 break; 164 end = GNUNET_TIME_absolute_get ();
156 start = GNUNET_get_time (); 165 printf ("%3u all now iteration took %20llums\n", i,
157 ret = api->iterateMigrationOrder (&iterateDummy, api); 166 end.value - start.value);
158 end = GNUNET_get_time ();
159 printf ("%3u migration or iteration took %20llums (%d)\n", i,
160 end - start, ret);
161 if (GNUNET_shutdown_test () == GNUNET_YES)
162 break;
163 start = GNUNET_get_time ();
164 ret = api->iterateAllNow (&iterateDummy, api);
165 end = GNUNET_get_time ();
166 printf ("%3u all now iteration took %20llums (%d)\n", i,
167 end - start, ret);
168 if (GNUNET_shutdown_test () == GNUNET_YES)
169 break;
170 } 167 }
171 api->drop (); 168 api->drop (api->cls);
172 return GNUNET_OK; 169 return GNUNET_OK;
173} 170}
174 171
175int 172
176main (int argc, char *argv[]) 173/**
174 * Load the datastore plugin.
175 */
176static struct GNUNET_DATASTORE_PluginFunctions *
177load_plugin ()
177{ 178{
178 GNUNET_SQstore_ServiceAPI *api; 179 static struct GNUNET_DATASTORE_PluginEnvironment env;
179 int ok; 180 struct GNUNET_DATASTORE_PluginFunctions * ret;
180 struct GNUNET_GC_Configuration *cfg; 181 char *name;
181 struct GNUNET_CronManager *cron; 182 char *libname;
182 183
183 cfg = GNUNET_GC_create (); 184 if (GNUNET_OK !=
184 if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf")) 185 GNUNET_CONFIGURATION_get_value_string (cfg,
186 "DATASTORE", "DATABASE", &name))
185 { 187 {
186 GNUNET_GC_free (cfg); 188 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
187 return -1; 189 _("No `%s' specified for `%s' in configuration!\n"),
190 "DATABASE",
191 "DATASTORE");
192 return NULL;
188 } 193 }
189 cron = GNUNET_cron_create (NULL); 194 env.cfg = cfg;
190 GNUNET_CORE_init (NULL, cfg, cron, NULL); 195 env.sched = sched;
191 api = GNUNET_CORE_request_service ("sqstore"); 196 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
192 if (api != NULL) 197 _("Loading `%s' datastore plugin\n"), name);
198 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
199 GNUNET_assert (NULL != (ret = GNUNET_PLUGIN_load (libname, &env)));
200 GNUNET_free (libname);
201 GNUNET_free (name);
202 return ret;
203}
204
205
206/**
207 * Function called when the service shuts
208 * down. Unloads our datastore plugin.
209 *
210 * @param api api to unload
211 */
212static void
213unload_plugin (struct GNUNET_DATASTORE_PluginFunctions * api)
214{
215 char *name;
216 char *libname;
217
218 if (GNUNET_OK !=
219 GNUNET_CONFIGURATION_get_value_string (cfg,
220 "DATASTORE", "DATABASE", &name))
193 { 221 {
194 start_time = GNUNET_get_time (); 222 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
195 ok = test (api); 223 _("No `%s' specified for `%s' in configuration!\n"),
196 GNUNET_CORE_release_service (api); 224 "DATABASE",
225 "DATASTORE");
226 return;
197 } 227 }
198 else 228 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
199 ok = GNUNET_SYSERR; 229 GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api));
200 GNUNET_CORE_done (); 230 GNUNET_free (libname);
201 GNUNET_cron_destroy (cron); 231 GNUNET_free (name);
202 GNUNET_GC_free (cfg); 232}
203 if (ok == GNUNET_SYSERR) 233
204 return 1; 234
205 return 0; 235
236/**
237 * Last task run during shutdown. Disconnects us from
238 * the transport and core.
239 */
240static void
241cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
242{
243 struct GNUNET_DATASTORE_PluginFunctions *api = cls;
244
245 unload_plugin (api);
206} 246}
207 247
208/* end of sqlitetest3.c */ 248
249
250static void
251run (void *cls,
252 struct GNUNET_SCHEDULER_Handle *s,
253 char *const *args,
254 const char *cfgfile, struct GNUNET_CONFIGURATION_Handle *c)
255{
256 struct GNUNET_DATASTORE_PluginFunctions *api;
257
258 cfg = c;
259 sched = s;
260 api = load_plugin ();
261 test(api);
262 GNUNET_SCHEDULER_add_delayed (sched,
263 GNUNET_YES,
264 GNUNET_SCHEDULER_PRIORITY_IDLE,
265 GNUNET_SCHEDULER_NO_PREREQUISITE_TASK,
266 GNUNET_TIME_UNIT_FOREVER_REL,
267 &cleaning_task, api);
268}
269
270
271static int
272check ()
273{
274 int ok = 1 + 2 + 4 + 8;
275 char *const argv[] = { "perf-datastore-api-iterators",
276 "-c",
277 "test_datastore_api_data.conf",
278#if VERBOSE
279 "-L", "DEBUG",
280#endif
281 NULL
282 };
283 struct GNUNET_GETOPT_CommandLineOption options[] = {
284 GNUNET_GETOPT_OPTION_END
285 };
286 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
287 argv, "perf-datastore-api-iterators", "nohelp",
288 options, &run, &ok);
289 if (ok != 0)
290 fprintf (stderr, "Missed some testcases: %u\n", ok);
291 return ok;
292}
293
294
295int
296main (int argc, char *argv[])
297{
298 int ret;
299
300 GNUNET_log_setup ("perf-datastore-api-iterators",
301#if VERBOSE
302 "DEBUG",
303#else
304 "WARNING",
305#endif
306 NULL);
307 ret = check ();
308
309 return ret;
310}
311
312
313/* end of perf_datastore_api_iterators.c */
314
315
diff --git a/src/datastore/test_datastore_api_data.conf b/src/datastore/test_datastore_api_data.conf
index 9a419f4d1..849c322c9 100644
--- a/src/datastore/test_datastore_api_data.conf
+++ b/src/datastore/test_datastore_api_data.conf
@@ -12,6 +12,7 @@ ACCEPT_FROM6 = ::1;
12ALLOW_SHUTDOWN = YES 12ALLOW_SHUTDOWN = YES
13QUOTA = 1000000 13QUOTA = 1000000
14BLOOMFILTER = $SERVICEHOME/fs/bloomfilter 14BLOOMFILTER = $SERVICEHOME/fs/bloomfilter
15DATABASE = sqlite
15# USERNAME = 16# USERNAME =
16# MAXBUF = 17# MAXBUF =
17# TIMEOUT = 18# TIMEOUT =