diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
commit | 502af2167f7c218366666ca4944bd7cc54b5b19a (patch) | |
tree | a91fec5cc9769d260640bd91c6633cb9cf395524 /src/datastore/perf_datastore_api.c | |
parent | 03af5a603b7cc53432249d5854cd412aa90dde0d (diff) | |
download | gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip |
indentation
Diffstat (limited to 'src/datastore/perf_datastore_api.c')
-rw-r--r-- | src/datastore/perf_datastore_api.c | 340 |
1 files changed, 159 insertions, 181 deletions
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c index 9d7755342..9d567aacd 100644 --- a/src/datastore/perf_datastore_api.c +++ b/src/datastore/perf_datastore_api.c | |||
@@ -84,13 +84,13 @@ static struct GNUNET_TIME_Absolute start_time; | |||
84 | static int ok; | 84 | static int ok; |
85 | 85 | ||
86 | enum RunPhase | 86 | enum RunPhase |
87 | { | 87 | { |
88 | RP_DONE = 0, | 88 | RP_DONE = 0, |
89 | RP_PUT, | 89 | RP_PUT, |
90 | RP_CUT, | 90 | RP_CUT, |
91 | RP_REPORT, | 91 | RP_REPORT, |
92 | RP_ERROR | 92 | RP_ERROR |
93 | }; | 93 | }; |
94 | 94 | ||
95 | 95 | ||
96 | struct CpsRunContext | 96 | struct CpsRunContext |
@@ -105,28 +105,23 @@ struct CpsRunContext | |||
105 | 105 | ||
106 | 106 | ||
107 | static void | 107 | static void |
108 | run_continuation (void *cls, | 108 | run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
109 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
110 | 109 | ||
111 | 110 | ||
112 | 111 | ||
113 | 112 | ||
114 | static void | 113 | static void |
115 | check_success (void *cls, | 114 | check_success (void *cls, int success, const char *msg) |
116 | int success, | ||
117 | const char *msg) | ||
118 | { | 115 | { |
119 | struct CpsRunContext *crc = cls; | 116 | struct CpsRunContext *crc = cls; |
120 | 117 | ||
121 | if (GNUNET_OK != success) | 118 | if (GNUNET_OK != success) |
122 | { | 119 | { |
123 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 120 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Check success failed: `%s'\n", msg); |
124 | "Check success failed: `%s'\n", msg); | 121 | crc->phase = RP_ERROR; |
125 | crc->phase = RP_ERROR; | 122 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); |
126 | GNUNET_SCHEDULER_add_now (&run_continuation, | 123 | return; |
127 | crc); | 124 | } |
128 | return; | ||
129 | } | ||
130 | #if REPORT_ID | 125 | #if REPORT_ID |
131 | fprintf (stderr, "I"); | 126 | fprintf (stderr, "I"); |
132 | #endif | 127 | #endif |
@@ -135,17 +130,16 @@ check_success (void *cls, | |||
135 | stored_entries++; | 130 | stored_entries++; |
136 | crc->j++; | 131 | crc->j++; |
137 | if (crc->j >= PUT_10) | 132 | if (crc->j >= PUT_10) |
138 | { | 133 | { |
139 | crc->j = 0; | 134 | crc->j = 0; |
140 | crc->i++; | 135 | crc->i++; |
141 | if (crc->i == ITERATIONS) | 136 | if (crc->i == ITERATIONS) |
142 | crc->phase = RP_DONE; | 137 | crc->phase = RP_DONE; |
143 | else | 138 | else |
144 | crc->phase = RP_CUT; | 139 | crc->phase = RP_CUT; |
145 | } | 140 | } |
146 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 141 | GNUNET_SCHEDULER_add_continuation (&run_continuation, |
147 | crc, | 142 | crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
148 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
149 | } | 143 | } |
150 | 144 | ||
151 | 145 | ||
@@ -157,41 +151,35 @@ check_success (void *cls, | |||
157 | * @param success GNUNET_SYSERR on failure | 151 | * @param success GNUNET_SYSERR on failure |
158 | * @param msg NULL on success, otherwise an error message | 152 | * @param msg NULL on success, otherwise an error message |
159 | */ | 153 | */ |
160 | static void | 154 | static void |
161 | remove_next(void *cls, | 155 | remove_next (void *cls, int success, const char *msg) |
162 | int success, | ||
163 | const char *msg) | ||
164 | { | 156 | { |
165 | struct CpsRunContext *crc = cls; | 157 | struct CpsRunContext *crc = cls; |
166 | 158 | ||
167 | if (GNUNET_OK != success) | 159 | if (GNUNET_OK != success) |
168 | { | 160 | { |
169 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 161 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "remove_next failed: `%s'\n", msg); |
170 | "remove_next failed: `%s'\n", msg); | 162 | crc->phase = RP_ERROR; |
171 | crc->phase = RP_ERROR; | 163 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); |
172 | GNUNET_SCHEDULER_add_now (&run_continuation, | 164 | return; |
173 | crc); | 165 | } |
174 | return; | ||
175 | } | ||
176 | #if REPORT_ID | 166 | #if REPORT_ID |
177 | fprintf (stderr, "D"); | 167 | fprintf (stderr, "D"); |
178 | #endif | 168 | #endif |
179 | GNUNET_assert (GNUNET_OK == success); | 169 | GNUNET_assert (GNUNET_OK == success); |
180 | GNUNET_SCHEDULER_add_now (&run_continuation, | 170 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); |
181 | crc); | ||
182 | } | 171 | } |
183 | 172 | ||
184 | 173 | ||
185 | static void | 174 | static void |
186 | delete_value (void *cls, | 175 | delete_value (void *cls, |
187 | const GNUNET_HashCode *key, | 176 | const GNUNET_HashCode * key, |
188 | size_t size, | 177 | size_t size, |
189 | const void *data, | 178 | const void *data, |
190 | enum GNUNET_BLOCK_Type type, | 179 | enum GNUNET_BLOCK_Type type, |
191 | uint32_t priority, | 180 | uint32_t priority, |
192 | uint32_t anonymity, | 181 | uint32_t anonymity, |
193 | struct GNUNET_TIME_Absolute | 182 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) |
194 | expiration, uint64_t uid) | ||
195 | { | 183 | { |
196 | struct CpsRunContext *crc = cls; | 184 | struct CpsRunContext *crc = cls; |
197 | 185 | ||
@@ -203,19 +191,16 @@ delete_value (void *cls, | |||
203 | if (stored_bytes < MAX_SIZE) | 191 | if (stored_bytes < MAX_SIZE) |
204 | crc->phase = RP_PUT; | 192 | crc->phase = RP_PUT; |
205 | GNUNET_assert (NULL != | 193 | GNUNET_assert (NULL != |
206 | GNUNET_DATASTORE_remove (datastore, | 194 | GNUNET_DATASTORE_remove (datastore, |
207 | key, | 195 | key, |
208 | size, | 196 | size, |
209 | data, | 197 | data, |
210 | 1, 1, TIMEOUT, | 198 | 1, 1, TIMEOUT, &remove_next, crc)); |
211 | &remove_next, | ||
212 | crc)); | ||
213 | } | 199 | } |
214 | 200 | ||
215 | 201 | ||
216 | static void | 202 | static void |
217 | run_continuation (void *cls, | 203 | run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
218 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
219 | { | 204 | { |
220 | struct CpsRunContext *crc = cls; | 205 | struct CpsRunContext *crc = cls; |
221 | size_t size; | 206 | size_t size; |
@@ -227,133 +212,127 @@ run_continuation (void *cls, | |||
227 | 212 | ||
228 | ok = (int) crc->phase; | 213 | ok = (int) crc->phase; |
229 | switch (crc->phase) | 214 | switch (crc->phase) |
230 | { | 215 | { |
231 | case RP_PUT: | 216 | case RP_PUT: |
232 | memset (&key, 256 - crc->i, sizeof (GNUNET_HashCode)); | 217 | memset (&key, 256 - crc->i, sizeof (GNUNET_HashCode)); |
233 | i = crc->j; | 218 | i = crc->j; |
234 | k = crc->i; | 219 | k = crc->i; |
235 | /* most content is 32k */ | 220 | /* most content is 32k */ |
236 | size = 32 * 1024; | 221 | size = 32 * 1024; |
237 | if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */ | 222 | if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */ |
238 | size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024); | 223 | size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024); |
239 | crc->size = size = size - (size & 7); /* always multiple of 8 */ | 224 | crc->size = size = size - (size & 7); /* always multiple of 8 */ |
240 | GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &key); | 225 | GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &key); |
241 | memset (data, i, size); | 226 | memset (data, i, size); |
242 | if (i > 255) | 227 | if (i > 255) |
243 | memset (data, i - 255, size / 2); | 228 | memset (data, i - 255, size / 2); |
244 | data[0] = k; | 229 | data[0] = k; |
245 | GNUNET_assert (NULL != | 230 | GNUNET_assert (NULL != |
246 | GNUNET_DATASTORE_put (datastore, | 231 | GNUNET_DATASTORE_put (datastore, |
247 | 0, | 232 | 0, |
248 | &key, | 233 | &key, |
249 | size, | 234 | size, |
250 | data, | 235 | data, |
251 | i+1, | 236 | i + 1, |
252 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100), | 237 | GNUNET_CRYPTO_random_u32 |
253 | i, 0, | 238 | (GNUNET_CRYPTO_QUALITY_WEAK, 100), i, |
254 | GNUNET_TIME_relative_to_absolute | 239 | 0, |
255 | (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 240 | GNUNET_TIME_relative_to_absolute |
256 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), | 241 | (GNUNET_TIME_relative_multiply |
257 | 1, 1, TIMEOUT, | 242 | (GNUNET_TIME_UNIT_SECONDS, |
258 | &check_success, | 243 | GNUNET_CRYPTO_random_u32 |
259 | crc)); | 244 | (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), |
260 | break; | 245 | 1, 1, TIMEOUT, &check_success, crc)); |
261 | case RP_CUT: | 246 | break; |
262 | /* trim down below MAX_SIZE again */ | 247 | case RP_CUT: |
263 | GNUNET_assert (NULL != | 248 | /* trim down below MAX_SIZE again */ |
264 | GNUNET_DATASTORE_get_for_replication (datastore, | 249 | GNUNET_assert (NULL != |
265 | 1, 1, TIMEOUT, | 250 | GNUNET_DATASTORE_get_for_replication (datastore, |
266 | &delete_value, | 251 | 1, 1, TIMEOUT, |
267 | crc)); | 252 | &delete_value, crc)); |
268 | break; | 253 | break; |
269 | case RP_REPORT: | 254 | case RP_REPORT: |
270 | printf ( | 255 | printf ( |
271 | #if REPORT_ID | 256 | #if REPORT_ID |
272 | "\n" | 257 | "\n" |
273 | #endif | 258 | #endif |
274 | "Stored %llu kB / %lluk ops / %llu ops/s\n", | 259 | "Stored %llu kB / %lluk ops / %llu ops/s\n", stored_bytes / 1024, /* used size in k */ |
275 | stored_bytes / 1024, /* used size in k */ | 260 | stored_ops / 1024, /* total operations (in k) */ |
276 | stored_ops / 1024, /* total operations (in k) */ | 261 | 1000 * stored_ops / (1 + |
277 | 1000 * stored_ops / (1 + GNUNET_TIME_absolute_get_duration(start_time).rel_value)); | 262 | GNUNET_TIME_absolute_get_duration |
278 | crc->phase = RP_PUT; | 263 | (start_time).rel_value)); |
279 | crc->j = 0; | 264 | crc->phase = RP_PUT; |
280 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 265 | crc->j = 0; |
281 | crc, | 266 | GNUNET_SCHEDULER_add_continuation (&run_continuation, |
282 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 267 | crc, |
283 | break; | 268 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
284 | case RP_DONE: | 269 | break; |
285 | GNUNET_snprintf (gstr, sizeof (gstr), | 270 | case RP_DONE: |
286 | "DATASTORE-%s", | 271 | GNUNET_snprintf (gstr, sizeof (gstr), "DATASTORE-%s", plugin_name); |
287 | plugin_name); | 272 | if ((crc->i == ITERATIONS) && (stored_ops > 0)) |
288 | if ( (crc->i == ITERATIONS) && | 273 | GAUGER (gstr, |
289 | (stored_ops > 0) ) | 274 | "PUT operation duration", |
290 | GAUGER (gstr, | 275 | GNUNET_TIME_absolute_get_duration (start_time).rel_value / |
291 | "PUT operation duration", | 276 | stored_ops, "ms/operation"); |
292 | GNUNET_TIME_absolute_get_duration(start_time).rel_value / stored_ops, | 277 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); |
293 | "ms/operation"); | 278 | GNUNET_free (crc); |
294 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); | 279 | ok = 0; |
295 | GNUNET_free (crc); | 280 | break; |
296 | ok = 0; | 281 | case RP_ERROR: |
297 | break; | 282 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); |
298 | case RP_ERROR: | 283 | GNUNET_free (crc); |
299 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); | 284 | ok = 1; |
300 | GNUNET_free (crc); | 285 | break; |
301 | ok = 1; | 286 | default: |
302 | break; | 287 | GNUNET_assert (0); |
303 | default: | 288 | } |
304 | GNUNET_assert (0); | ||
305 | } | ||
306 | } | 289 | } |
307 | 290 | ||
308 | 291 | ||
309 | static void | 292 | static void |
310 | run_tests (void *cls, | 293 | run_tests (void *cls, int success, const char *msg) |
311 | int success, | ||
312 | const char *msg) | ||
313 | { | 294 | { |
314 | struct CpsRunContext *crc = cls; | 295 | struct CpsRunContext *crc = cls; |
315 | 296 | ||
316 | if (success != GNUNET_YES) | 297 | if (success != GNUNET_YES) |
317 | { | 298 | { |
318 | fprintf (stderr, | 299 | fprintf (stderr, |
319 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.", | 300 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.", |
320 | msg); | 301 | msg); |
321 | GNUNET_free (crc); | 302 | GNUNET_free (crc); |
322 | return; | 303 | return; |
323 | } | 304 | } |
324 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 305 | GNUNET_SCHEDULER_add_continuation (&run_continuation, |
325 | crc, | 306 | crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
326 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
327 | } | 307 | } |
328 | 308 | ||
329 | 309 | ||
330 | static void | 310 | static void |
331 | run (void *cls, | 311 | run (void *cls, |
332 | char *const *args, | 312 | char *const *args, |
333 | const char *cfgfile, | 313 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
334 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
335 | { | 314 | { |
336 | struct CpsRunContext *crc; | 315 | struct CpsRunContext *crc; |
337 | static GNUNET_HashCode zkey; | 316 | static GNUNET_HashCode zkey; |
338 | 317 | ||
339 | datastore = GNUNET_DATASTORE_connect (cfg); | 318 | datastore = GNUNET_DATASTORE_connect (cfg); |
340 | start_time = GNUNET_TIME_absolute_get (); | 319 | start_time = GNUNET_TIME_absolute_get (); |
341 | crc = GNUNET_malloc(sizeof(struct CpsRunContext)); | 320 | crc = GNUNET_malloc (sizeof (struct CpsRunContext)); |
342 | crc->cfg = cfg; | 321 | crc->cfg = cfg; |
343 | crc->phase = RP_PUT; | 322 | crc->phase = RP_PUT; |
344 | if (NULL == | 323 | if (NULL == |
345 | GNUNET_DATASTORE_put (datastore, 0, | 324 | GNUNET_DATASTORE_put (datastore, 0, |
346 | &zkey, 4, "TEST", | 325 | &zkey, 4, "TEST", |
347 | GNUNET_BLOCK_TYPE_TEST, | 326 | GNUNET_BLOCK_TYPE_TEST, |
348 | 0, 0, 0, GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS), | 327 | 0, 0, 0, |
349 | 0, 1, GNUNET_TIME_UNIT_MINUTES, | 328 | GNUNET_TIME_relative_to_absolute |
350 | &run_tests, crc)) | 329 | (GNUNET_TIME_UNIT_SECONDS), 0, 1, |
351 | { | 330 | GNUNET_TIME_UNIT_MINUTES, &run_tests, crc)) |
352 | fprintf (stderr, | 331 | { |
353 | "Test 'put' operation failed.\n"); | 332 | fprintf (stderr, "Test 'put' operation failed.\n"); |
354 | ok = 1; | 333 | ok = 1; |
355 | GNUNET_free (crc); | 334 | GNUNET_free (crc); |
356 | } | 335 | } |
357 | } | 336 | } |
358 | 337 | ||
359 | 338 | ||
@@ -362,7 +341,8 @@ check () | |||
362 | { | 341 | { |
363 | struct GNUNET_OS_Process *proc; | 342 | struct GNUNET_OS_Process *proc; |
364 | char cfg_name[128]; | 343 | char cfg_name[128]; |
365 | char *const argv[] = { | 344 | |
345 | char *const argv[] = { | ||
366 | "perf-datastore-api", | 346 | "perf-datastore-api", |
367 | "-c", | 347 | "-c", |
368 | cfg_name, | 348 | cfg_name, |
@@ -376,25 +356,24 @@ check () | |||
376 | }; | 356 | }; |
377 | 357 | ||
378 | GNUNET_snprintf (cfg_name, | 358 | GNUNET_snprintf (cfg_name, |
379 | sizeof (cfg_name), | 359 | sizeof (cfg_name), |
380 | "test_datastore_api_data_%s.conf", | 360 | "test_datastore_api_data_%s.conf", plugin_name); |
381 | plugin_name); | ||
382 | proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 361 | proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
383 | "gnunet-service-arm", | 362 | "gnunet-service-arm", |
384 | #if VERBOSE | 363 | #if VERBOSE |
385 | "-L", "DEBUG", | 364 | "-L", "DEBUG", |
386 | #endif | 365 | #endif |
387 | "-c", cfg_name, NULL); | 366 | "-c", cfg_name, NULL); |
388 | GNUNET_assert (NULL != proc); | 367 | GNUNET_assert (NULL != proc); |
389 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 368 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
390 | argv, "perf-datastore-api", "nohelp", | 369 | argv, "perf-datastore-api", "nohelp", |
391 | options, &run, NULL); | 370 | options, &run, NULL); |
392 | sleep (1); /* give datastore chance to process 'DROP' */ | 371 | sleep (1); /* give datastore chance to process 'DROP' */ |
393 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 372 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
394 | { | 373 | { |
395 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 374 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
396 | ok = 1; | 375 | ok = 1; |
397 | } | 376 | } |
398 | GNUNET_OS_process_wait (proc); | 377 | GNUNET_OS_process_wait (proc); |
399 | GNUNET_OS_process_close (proc); | 378 | GNUNET_OS_process_close (proc); |
400 | proc = NULL; | 379 | proc = NULL; |
@@ -412,21 +391,20 @@ main (int argc, char *argv[]) | |||
412 | sleep (1); | 391 | sleep (1); |
413 | /* determine name of plugin to use */ | 392 | /* determine name of plugin to use */ |
414 | plugin_name = argv[0]; | 393 | plugin_name = argv[0]; |
415 | while (NULL != (pos = strstr(plugin_name, "_"))) | 394 | while (NULL != (pos = strstr (plugin_name, "_"))) |
416 | plugin_name = pos+1; | 395 | plugin_name = pos + 1; |
417 | if (NULL != (pos = strstr(plugin_name, "."))) | 396 | if (NULL != (pos = strstr (plugin_name, "."))) |
418 | pos[0] = 0; | 397 | pos[0] = 0; |
419 | else | 398 | else |
420 | pos = (char *) plugin_name; | 399 | pos = (char *) plugin_name; |
421 | 400 | ||
422 | GNUNET_snprintf (dir_name, | 401 | GNUNET_snprintf (dir_name, |
423 | sizeof (dir_name), | 402 | sizeof (dir_name), |
424 | "/tmp/test-gnunet-datastore-%s", | 403 | "/tmp/test-gnunet-datastore-%s", plugin_name); |
425 | plugin_name); | ||
426 | GNUNET_DISK_directory_remove (dir_name); | 404 | GNUNET_DISK_directory_remove (dir_name); |
427 | GNUNET_log_setup ("perf-datastore-api", | 405 | GNUNET_log_setup ("perf-datastore-api", |
428 | #if VERBOSE | 406 | #if VERBOSE |
429 | "DEBUG", | 407 | "DEBUG", |
430 | #else | 408 | #else |
431 | "WARNING", | 409 | "WARNING", |
432 | #endif | 410 | #endif |