aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/perf_datastore_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/datastore/perf_datastore_api.c')
-rw-r--r--src/datastore/perf_datastore_api.c486
1 files changed, 247 insertions, 239 deletions
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c
index e7eff0e6a..f353d0452 100644
--- a/src/datastore/perf_datastore_api.c
+++ b/src/datastore/perf_datastore_api.c
@@ -41,7 +41,7 @@
41/** 41/**
42 * How long until we give up on transmitting the message? 42 * How long until we give up on transmitting the message?
43 */ 43 */
44#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) 44#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
45 45
46/** 46/**
47 * Target datastore size (in bytes). 47 * Target datastore size (in bytes).
@@ -114,7 +114,8 @@ static int ok;
114/** 114/**
115 * Which phase of the process are we in? 115 * Which phase of the process are we in?
116 */ 116 */
117enum RunPhase { 117enum RunPhase
118{
118 /** 119 /**
119 * We are done (shutting down normally). 120 * We are done (shutting down normally).
120 */ 121 */
@@ -153,7 +154,8 @@ enum RunPhase {
153 * benchmark. Could right now be global, but this allows 154 * benchmark. Could right now be global, but this allows
154 * us to theoretically run multiple clients "in parallel". 155 * us to theoretically run multiple clients "in parallel".
155 */ 156 */
156struct CpsRunContext { 157struct CpsRunContext
158{
157 /** 159 /**
158 * Execution phase we are in. 160 * Execution phase we are in.
159 */ 161 */
@@ -186,7 +188,7 @@ struct CpsRunContext {
186 * @param cls the `struct CpsRunContext` 188 * @param cls the `struct CpsRunContext`
187 */ 189 */
188static void 190static void
189run_continuation(void *cls); 191run_continuation (void *cls);
190 192
191 193
192/** 194/**
@@ -201,57 +203,57 @@ run_continuation(void *cls);
201 * @param msg NULL on success, otherwise an error message 203 * @param msg NULL on success, otherwise an error message
202 */ 204 */
203static void 205static void
204check_success(void *cls, 206check_success (void *cls,
205 int success, 207 int success,
206 struct GNUNET_TIME_Absolute min_expiration, 208 struct GNUNET_TIME_Absolute min_expiration,
207 const char *msg) 209 const char *msg)
208{ 210{
209 struct CpsRunContext *crc = cls; 211 struct CpsRunContext *crc = cls;
210 212
211#if REPORT_ID 213#if REPORT_ID
212 fprintf(stderr, "%s", (GNUNET_OK == success) ? "I" : "i"); 214 fprintf (stderr, "%s", (GNUNET_OK == success) ? "I" : "i");
213#endif 215#endif
214 if (GNUNET_OK != success) 216 if (GNUNET_OK != success)
215 { 217 {
216 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 218 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
217 "Check success failed: `%s'\n", 219 "Check success failed: `%s'\n",
218 msg); 220 msg);
219 crc->phase = RP_ERROR; 221 crc->phase = RP_ERROR;
220 GNUNET_SCHEDULER_add_now(&run_continuation, 222 GNUNET_SCHEDULER_add_now (&run_continuation,
221 crc); 223 crc);
222 return; 224 return;
223 } 225 }
224 stored_bytes += crc->size; 226 stored_bytes += crc->size;
225 stored_ops++; 227 stored_ops++;
226 stored_entries++; 228 stored_entries++;
227 crc->j++; 229 crc->j++;
228 switch (crc->phase) 230 switch (crc->phase)
231 {
232 case RP_PUT:
233 if (crc->j >= PUT_10)
234 {
235 crc->j = 0;
236 crc->i++;
237 if (crc->i == ITERATIONS)
238 crc->phase = RP_PUT_QUOTA;
239 else
240 crc->phase = RP_CUT;
241 }
242 break;
243
244 case RP_PUT_QUOTA:
245 if (crc->j >= QUOTA_PUTS)
229 { 246 {
230 case RP_PUT: 247 crc->j = 0;
231 if (crc->j >= PUT_10) 248 crc->phase = RP_DONE;
232 {
233 crc->j = 0;
234 crc->i++;
235 if (crc->i == ITERATIONS)
236 crc->phase = RP_PUT_QUOTA;
237 else
238 crc->phase = RP_CUT;
239 }
240 break;
241
242 case RP_PUT_QUOTA:
243 if (crc->j >= QUOTA_PUTS)
244 {
245 crc->j = 0;
246 crc->phase = RP_DONE;
247 }
248 break;
249
250 default:
251 GNUNET_assert(0);
252 } 249 }
253 GNUNET_SCHEDULER_add_now(&run_continuation, 250 break;
254 crc); 251
252 default:
253 GNUNET_assert (0);
254 }
255 GNUNET_SCHEDULER_add_now (&run_continuation,
256 crc);
255} 257}
256 258
257 259
@@ -267,29 +269,29 @@ check_success(void *cls,
267 * @param msg NULL on success, otherwise an error message 269 * @param msg NULL on success, otherwise an error message
268 */ 270 */
269static void 271static void
270remove_next(void *cls, 272remove_next (void *cls,
271 int success, 273 int success,
272 struct GNUNET_TIME_Absolute min_expiration, 274 struct GNUNET_TIME_Absolute min_expiration,
273 const char *msg) 275 const char *msg)
274{ 276{
275 struct CpsRunContext *crc = cls; 277 struct CpsRunContext *crc = cls;
276 278
277 if (GNUNET_OK != success) 279 if (GNUNET_OK != success)
278 { 280 {
279 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 281 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
280 "remove_next failed: `%s'\n", 282 "remove_next failed: `%s'\n",
281 msg); 283 msg);
282 crc->phase = RP_ERROR; 284 crc->phase = RP_ERROR;
283 GNUNET_SCHEDULER_add_now(&run_continuation, 285 GNUNET_SCHEDULER_add_now (&run_continuation,
284 crc); 286 crc);
285 return; 287 return;
286 } 288 }
287#if REPORT_ID 289#if REPORT_ID
288 fprintf(stderr, "%s", "D"); 290 fprintf (stderr, "%s", "D");
289#endif 291#endif
290 GNUNET_assert(GNUNET_OK == success); 292 GNUNET_assert (GNUNET_OK == success);
291 GNUNET_SCHEDULER_add_now(&run_continuation, 293 GNUNET_SCHEDULER_add_now (&run_continuation,
292 crc); 294 crc);
293} 295}
294 296
295 297
@@ -309,32 +311,32 @@ remove_next(void *cls,
309 * maybe 0 if no unique identifier is available 311 * maybe 0 if no unique identifier is available
310 */ 312 */
311static void 313static void
312delete_value(void *cls, 314delete_value (void *cls,
313 const struct GNUNET_HashCode *key, 315 const struct GNUNET_HashCode *key,
314 size_t size, 316 size_t size,
315 const void *data, 317 const void *data,
316 enum GNUNET_BLOCK_Type type, 318 enum GNUNET_BLOCK_Type type,
317 uint32_t priority, 319 uint32_t priority,
318 uint32_t anonymity, 320 uint32_t anonymity,
319 uint32_t replication, 321 uint32_t replication,
320 struct GNUNET_TIME_Absolute expiration, 322 struct GNUNET_TIME_Absolute expiration,
321 uint64_t uid) 323 uint64_t uid)
322{ 324{
323 struct CpsRunContext *crc = cls; 325 struct CpsRunContext *crc = cls;
324 326
325 GNUNET_assert(NULL != key); 327 GNUNET_assert (NULL != key);
326 stored_ops++; 328 stored_ops++;
327 stored_bytes -= size; 329 stored_bytes -= size;
328 stored_entries--; 330 stored_entries--;
329 stored_ops++; 331 stored_ops++;
330 if (stored_bytes < MAX_SIZE) 332 if (stored_bytes < MAX_SIZE)
331 crc->phase = RP_PUT; 333 crc->phase = RP_PUT;
332 GNUNET_assert(NULL != 334 GNUNET_assert (NULL !=
333 GNUNET_DATASTORE_remove(datastore, 335 GNUNET_DATASTORE_remove (datastore,
334 key, 336 key,
335 size, 337 size,
336 data, 1, 1, 338 data, 1, 1,
337 &remove_next, crc)); 339 &remove_next, crc));
338} 340}
339 341
340 342
@@ -345,7 +347,7 @@ delete_value(void *cls,
345 * @param cls the `struct CpsRunContext` 347 * @param cls the `struct CpsRunContext`
346 */ 348 */
347static void 349static void
348run_continuation(void *cls) 350run_continuation (void *cls)
349{ 351{
350 struct CpsRunContext *crc = cls; 352 struct CpsRunContext *crc = cls;
351 size_t size; 353 size_t size;
@@ -353,34 +355,34 @@ run_continuation(void *cls)
353 static char data[65536]; 355 static char data[65536];
354 char gstr[128]; 356 char gstr[128];
355 357
356 ok = (int)crc->phase; 358 ok = (int) crc->phase;
357 switch (crc->phase) 359 switch (crc->phase)
358 { 360 {
359 case RP_PUT: 361 case RP_PUT:
360 memset(&key, 362 memset (&key,
361 256 - crc->i, 363 256 - crc->i,
362 sizeof(struct GNUNET_HashCode)); 364 sizeof(struct GNUNET_HashCode));
363 /* most content is 32k */ 365 /* most content is 32k */
364 size = 32 * 1024; 366 size = 32 * 1024;
365 if (0 == 367 if (0 ==
366 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 368 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
367 16)) /* but some of it is less! */ 369 16)) /* but some of it is less! */
368 size = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 370 size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
369 32 * 1024); 371 32 * 1024);
370 crc->size = size = size - (size & 7); /* always multiple of 8 */ 372 crc->size = size = size - (size & 7); /* always multiple of 8 */
371 GNUNET_CRYPTO_hash(&key, 373 GNUNET_CRYPTO_hash (&key,
372 sizeof(struct GNUNET_HashCode), 374 sizeof(struct GNUNET_HashCode),
373 &key); 375 &key);
374 memset(data, 376 memset (data,
375 (int)crc->j, 377 (int) crc->j,
376 size); 378 size);
377 if (crc->j > 255) 379 if (crc->j > 255)
378 memset(data, 380 memset (data,
379 (int)(crc->j - 255), 381 (int) (crc->j - 255),
380 size / 2); 382 size / 2);
381 data[0] = crc->i; 383 data[0] = crc->i;
382 GNUNET_assert(NULL != 384 GNUNET_assert (NULL !=
383 GNUNET_DATASTORE_put(datastore, 385 GNUNET_DATASTORE_put (datastore,
384 0, 386 0,
385 &key, 387 &key,
386 size, 388 size,
@@ -394,63 +396,64 @@ run_continuation(void *cls)
394 (GNUNET_TIME_relative_multiply 396 (GNUNET_TIME_relative_multiply
395 (GNUNET_TIME_UNIT_SECONDS, 397 (GNUNET_TIME_UNIT_SECONDS,
396 GNUNET_CRYPTO_random_u32 398 GNUNET_CRYPTO_random_u32
397 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), 399 (GNUNET_CRYPTO_QUALITY_WEAK,
400 1000))),
398 1, 401 1,
399 1, 402 1,
400 &check_success, crc)); 403 &check_success, crc));
401 break; 404 break;
402 405
403 case RP_CUT: 406 case RP_CUT:
404 /* trim down below MAX_SIZE again */ 407 /* trim down below MAX_SIZE again */
405 GNUNET_assert(NULL != 408 GNUNET_assert (NULL !=
406 GNUNET_DATASTORE_get_for_replication(datastore, 409 GNUNET_DATASTORE_get_for_replication (datastore,
407 1, 1, 410 1, 1,
408 &delete_value, 411 &delete_value,
409 crc)); 412 crc));
410 break; 413 break;
411 414
412 case RP_REPORT: 415 case RP_REPORT:
413 printf( 416 printf (
414#if REPORT_ID 417#if REPORT_ID
415 "\n" 418 "\n"
416#endif 419#endif
417 "Stored %llu kB / %lluk ops / %llu ops/s\n", 420 "Stored %llu kB / %lluk ops / %llu ops/s\n",
418 stored_bytes / 1024, /* used size in k */ 421 stored_bytes / 1024, /* used size in k */
419 stored_ops / 1024, /* total operations (in k) */ 422 stored_ops / 1024, /* total operations (in k) */
420 1000LL * 1000LL * stored_ops / (1 + 423 1000LL * 1000LL * stored_ops / (1
421 GNUNET_TIME_absolute_get_duration 424 + GNUNET_TIME_absolute_get_duration
422 (start_time).rel_value_us)); 425 (start_time).rel_value_us));
423 crc->phase = RP_PUT; 426 crc->phase = RP_PUT;
424 crc->j = 0; 427 crc->j = 0;
425 GNUNET_SCHEDULER_add_now(&run_continuation, 428 GNUNET_SCHEDULER_add_now (&run_continuation,
426 crc); 429 crc);
427 break; 430 break;
428 431
429 case RP_PUT_QUOTA: 432 case RP_PUT_QUOTA:
430 memset(&key, 433 memset (&key,
431 256 - crc->i, 434 256 - crc->i,
432 sizeof(struct GNUNET_HashCode)); 435 sizeof(struct GNUNET_HashCode));
433 /* most content is 32k */ 436 /* most content is 32k */
434 size = 32 * 1024; 437 size = 32 * 1024;
435 if (0 == 438 if (0 ==
436 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 439 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
437 16)) /* but some of it is less! */ 440 16)) /* but some of it is less! */
438 size = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 441 size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
439 32 * 1024); 442 32 * 1024);
440 crc->size = size = size - (size & 7); /* always multiple of 8 */ 443 crc->size = size = size - (size & 7); /* always multiple of 8 */
441 GNUNET_CRYPTO_hash(&key, 444 GNUNET_CRYPTO_hash (&key,
442 sizeof(struct GNUNET_HashCode), 445 sizeof(struct GNUNET_HashCode),
443 &key); 446 &key);
444 memset(data, 447 memset (data,
445 (int)crc->j, 448 (int) crc->j,
446 size); 449 size);
447 if (crc->j > 255) 450 if (crc->j > 255)
448 memset(data, 451 memset (data,
449 (int)(crc->j - 255), 452 (int) (crc->j - 255),
450 size / 2); 453 size / 2);
451 data[0] = crc->i; 454 data[0] = crc->i;
452 GNUNET_assert(NULL != 455 GNUNET_assert (NULL !=
453 GNUNET_DATASTORE_put(datastore, 456 GNUNET_DATASTORE_put (datastore,
454 0, /* reservation ID */ 457 0, /* reservation ID */
455 &key, 458 &key,
456 size, 459 size,
@@ -465,49 +468,53 @@ run_continuation(void *cls)
465 (GNUNET_TIME_relative_multiply 468 (GNUNET_TIME_relative_multiply
466 (GNUNET_TIME_UNIT_SECONDS, 469 (GNUNET_TIME_UNIT_SECONDS,
467 GNUNET_CRYPTO_random_u32 470 GNUNET_CRYPTO_random_u32
468 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), 471 (GNUNET_CRYPTO_QUALITY_WEAK,
472 1000))),
469 1, 473 1,
470 1, 474 1,
471 &check_success, crc)); 475 &check_success, crc));
472 break; 476 break;
473 477
474 case RP_DONE: 478 case RP_DONE:
475 GNUNET_snprintf(gstr, 479 GNUNET_snprintf (gstr,
476 sizeof(gstr), 480 sizeof(gstr),
477 "DATASTORE-%s", 481 "DATASTORE-%s",
478 plugin_name); 482 plugin_name);
479 if ((crc->i == ITERATIONS) && (stored_ops > 0)) 483 if ((crc->i == ITERATIONS) && (stored_ops > 0))
480 { 484 {
481 GAUGER(gstr, 485 GAUGER (gstr,
482 "PUT operation duration", 486 "PUT operation duration",
483 GNUNET_TIME_absolute_get_duration(start_time).rel_value_us / 1000LL / 487 GNUNET_TIME_absolute_get_duration (start_time).rel_value_us
484 stored_ops, 488 / 1000LL
485 "ms/operation"); 489 / stored_ops,
486 fprintf(stdout, 490 "ms/operation");
487 "\nPUT performance: %s for %llu operations\n", 491 fprintf (stdout,
488 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(start_time), 492 "\nPUT performance: %s for %llu operations\n",
489 GNUNET_YES), 493 GNUNET_STRINGS_relative_time_to_string (
490 stored_ops); 494 GNUNET_TIME_absolute_get_duration (start_time),
491 fprintf(stdout, 495 GNUNET_YES),
492 "PUT performance: %llu ms/operation\n", 496 stored_ops);
493 GNUNET_TIME_absolute_get_duration(start_time).rel_value_us / 1000LL / 497 fprintf (stdout,
494 stored_ops); 498 "PUT performance: %llu ms/operation\n",
495 } 499 GNUNET_TIME_absolute_get_duration (start_time).rel_value_us
496 GNUNET_DATASTORE_disconnect(datastore, 500 / 1000LL
497 GNUNET_YES); 501 / stored_ops);
498 GNUNET_free(crc);
499 ok = 0;
500 break;
501
502 case RP_ERROR:
503 GNUNET_DATASTORE_disconnect(datastore, GNUNET_YES);
504 GNUNET_free(crc);
505 ok = 1;
506 break;
507
508 default:
509 GNUNET_assert(0);
510 } 502 }
503 GNUNET_DATASTORE_disconnect (datastore,
504 GNUNET_YES);
505 GNUNET_free (crc);
506 ok = 0;
507 break;
508
509 case RP_ERROR:
510 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
511 GNUNET_free (crc);
512 ok = 1;
513 break;
514
515 default:
516 GNUNET_assert (0);
517 }
511} 518}
512 519
513 520
@@ -524,25 +531,25 @@ run_continuation(void *cls)
524 * @param msg NULL on success, otherwise an error message 531 * @param msg NULL on success, otherwise an error message
525 */ 532 */
526static void 533static void
527run_tests(void *cls, 534run_tests (void *cls,
528 int success, 535 int success,
529 struct GNUNET_TIME_Absolute min_expiration, 536 struct GNUNET_TIME_Absolute min_expiration,
530 const char *msg) 537 const char *msg)
531{ 538{
532 struct CpsRunContext *crc = cls; 539 struct CpsRunContext *crc = cls;
533 540
534 if (success != GNUNET_YES) 541 if (success != GNUNET_YES)
535 { 542 {
536 fprintf(stderr, 543 fprintf (stderr,
537 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", 544 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n",
538 msg); 545 msg);
539 GNUNET_DATASTORE_disconnect(datastore, 546 GNUNET_DATASTORE_disconnect (datastore,
540 GNUNET_YES); 547 GNUNET_YES);
541 GNUNET_free(crc); 548 GNUNET_free (crc);
542 return; 549 return;
543 } 550 }
544 GNUNET_SCHEDULER_add_now(&run_continuation, 551 GNUNET_SCHEDULER_add_now (&run_continuation,
545 crc); 552 crc);
546} 553}
547 554
548 555
@@ -556,34 +563,35 @@ run_tests(void *cls,
556 * @param peer peer handle (unused) 563 * @param peer peer handle (unused)
557 */ 564 */
558static void 565static void
559run(void *cls, 566run (void *cls,
560 const struct GNUNET_CONFIGURATION_Handle *cfg, 567 const struct GNUNET_CONFIGURATION_Handle *cfg,
561 struct GNUNET_TESTING_Peer *peer) 568 struct GNUNET_TESTING_Peer *peer)
562{ 569{
563 struct CpsRunContext *crc; 570 struct CpsRunContext *crc;
564 static struct GNUNET_HashCode zkey; 571 static struct GNUNET_HashCode zkey;
565 572
566 datastore = GNUNET_DATASTORE_connect(cfg); 573 datastore = GNUNET_DATASTORE_connect (cfg);
567 start_time = GNUNET_TIME_absolute_get(); 574 start_time = GNUNET_TIME_absolute_get ();
568 crc = GNUNET_new(struct CpsRunContext); 575 crc = GNUNET_new (struct CpsRunContext);
569 crc->phase = RP_PUT; 576 crc->phase = RP_PUT;
570 if (NULL == 577 if (NULL ==
571 GNUNET_DATASTORE_put(datastore, 578 GNUNET_DATASTORE_put (datastore,
572 0, 579 0,
573 &zkey, 580 &zkey,
574 4, "TEST", 581 4, "TEST",
575 GNUNET_BLOCK_TYPE_TEST, 582 GNUNET_BLOCK_TYPE_TEST,
576 0, 0, 0, 583 0, 0, 0,
577 GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_SECONDS), 584 GNUNET_TIME_relative_to_absolute (
578 0, 1, 585 GNUNET_TIME_UNIT_SECONDS),
579 &run_tests, crc)) 586 0, 1,
580 { 587 &run_tests, crc))
581 fprintf(stderr, 588 {
582 "%s", 589 fprintf (stderr,
583 "Test 'put' operation failed.\n"); 590 "%s",
584 ok = 1; 591 "Test 'put' operation failed.\n");
585 GNUNET_free(crc); 592 ok = 1;
586 } 593 GNUNET_free (crc);
594 }
587} 595}
588 596
589 597
@@ -597,23 +605,23 @@ run(void *cls,
597 * @return 0 on success 605 * @return 0 on success
598 */ 606 */
599int 607int
600main(int argc, 608main (int argc,
601 char *argv[]) 609 char *argv[])
602{ 610{
603 char cfg_name[PATH_MAX]; 611 char cfg_name[PATH_MAX];
604 612
605 plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); 613 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
606 GNUNET_snprintf(cfg_name, 614 GNUNET_snprintf (cfg_name,
607 sizeof(cfg_name), 615 sizeof(cfg_name),
608 "test_datastore_api_data_%s.conf", 616 "test_datastore_api_data_%s.conf",
609 plugin_name); 617 plugin_name);
610 if (0 != 618 if (0 !=
611 GNUNET_TESTING_peer_run("perf-gnunet-datastore", 619 GNUNET_TESTING_peer_run ("perf-gnunet-datastore",
612 cfg_name, 620 cfg_name,
613 &run, 621 &run,
614 NULL)) 622 NULL))
615 return 1; 623 return 1;
616 fprintf(stderr, "%s", "\n"); 624 fprintf (stderr, "%s", "\n");
617 return ok; 625 return ok;
618} 626}
619 627