aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport-profiler.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-04-28 19:32:10 +0200
committerChristian Grothoff <christian@grothoff.org>2019-04-28 19:32:20 +0200
commit3f945e6798d8d736ceb104b59ea1269a7abdfe8a (patch)
treeb93e3dc99deda0987e85cb256b3903de8bd74853 /src/transport/gnunet-transport-profiler.c
parent1227fc30369a55b82e77d35d8d128090e37dd437 (diff)
downloadgnunet-3f945e6798d8d736ceb104b59ea1269a7abdfe8a.tar.gz
gnunet-3f945e6798d8d736ceb104b59ea1269a7abdfe8a.zip
towards flow control in TNG
Diffstat (limited to 'src/transport/gnunet-transport-profiler.c')
-rw-r--r--src/transport/gnunet-transport-profiler.c232
1 files changed, 97 insertions, 135 deletions
diff --git a/src/transport/gnunet-transport-profiler.c b/src/transport/gnunet-transport-profiler.c
index 9160a78b2..89f5b4108 100644
--- a/src/transport/gnunet-transport-profiler.c
+++ b/src/transport/gnunet-transport-profiler.c
@@ -32,7 +32,6 @@
32#include "gnunet_protocols.h" 32#include "gnunet_protocols.h"
33#include "gnunet_ats_service.h" 33#include "gnunet_ats_service.h"
34#include "gnunet_transport_service.h" 34#include "gnunet_transport_service.h"
35#include "gnunet_transport_core_service.h"
36 35
37 36
38struct Iteration 37struct Iteration
@@ -54,7 +53,8 @@ struct Iteration
54/** 53/**
55 * Timeout for a connections 54 * Timeout for a connections
56 */ 55 */
57#define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 56#define CONNECT_TIMEOUT \
57 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
58 58
59/** 59/**
60 * Benchmarking block size in bye 60 * Benchmarking block size in bye
@@ -214,15 +214,16 @@ shutdown_task (void *cls)
214 { 214 {
215 inext = icur->next; 215 inext = icur->next;
216 icur->rate = ((benchmark_count * benchmark_size) / 1024) / 216 icur->rate = ((benchmark_count * benchmark_size) / 1024) /
217 ((float) icur->dur.rel_value_us / (1000 * 1000)); 217 ((float) icur->dur.rel_value_us / (1000 * 1000));
218 if (verbosity > 0) 218 if (verbosity > 0)
219 FPRINTF (stdout, _("%llu B in %llu ms == %.2f KB/s!\n"), 219 FPRINTF (stdout,
220 ((long long unsigned int) benchmark_count * benchmark_size), 220 _ ("%llu B in %llu ms == %.2f KB/s!\n"),
221 ((long long unsigned int) icur->dur.rel_value_us / 1000), 221 ((long long unsigned int) benchmark_count * benchmark_size),
222 (float) icur->rate); 222 ((long long unsigned int) icur->dur.rel_value_us / 1000),
223 (float) icur->rate);
223 224
224 avg_duration += icur->dur.rel_value_us / (1000); 225 avg_duration += icur->dur.rel_value_us / (1000);
225 avg_rate += icur->rate; 226 avg_rate += icur->rate;
226 iterations++; 227 iterations++;
227 } 228 }
228 if (0 == iterations) 229 if (0 == iterations)
@@ -238,19 +239,17 @@ shutdown_task (void *cls)
238 while (NULL != (icur = inext)) 239 while (NULL != (icur = inext))
239 { 240 {
240 inext = icur->next; 241 inext = icur->next;
241 stddev_rate += ((icur->rate-avg_rate) * 242 stddev_rate += ((icur->rate - avg_rate) * (icur->rate - avg_rate));
242 (icur->rate-avg_rate));
243 stddev_duration += (((icur->dur.rel_value_us / 1000) - avg_duration) * 243 stddev_duration += (((icur->dur.rel_value_us / 1000) - avg_duration) *
244 ((icur->dur.rel_value_us / 1000) - avg_duration)); 244 ((icur->dur.rel_value_us / 1000) - avg_duration));
245
246 } 245 }
247 /* Calculate standard deviation rate */ 246 /* Calculate standard deviation rate */
248 stddev_rate = stddev_rate / iterations; 247 stddev_rate = stddev_rate / iterations;
249 stddev_rate = sqrtf(stddev_rate); 248 stddev_rate = sqrtf (stddev_rate);
250 249
251 /* Calculate standard deviation duration */ 250 /* Calculate standard deviation duration */
252 stddev_duration = stddev_duration / iterations; 251 stddev_duration = stddev_duration / iterations;
253 stddev_duration = sqrtf(stddev_duration); 252 stddev_duration = sqrtf (stddev_duration);
254 253
255 /* Output */ 254 /* Output */
256 FPRINTF (stdout, 255 FPRINTF (stdout,
@@ -266,9 +265,7 @@ shutdown_task (void *cls)
266 while (NULL != (icur = inext)) 265 while (NULL != (icur = inext))
267 { 266 {
268 inext = icur->next; 267 inext = icur->next;
269 GNUNET_CONTAINER_DLL_remove (ihead, 268 GNUNET_CONTAINER_DLL_remove (ihead, itail, icur);
270 itail,
271 icur);
272 269
273 FPRINTF (stdout, 270 FPRINTF (stdout,
274 ";%llu;%.2f", 271 ";%llu;%.2f",
@@ -316,27 +313,19 @@ send_msg (void *cls)
316 313
317 if (NULL == mq) 314 if (NULL == mq)
318 return; 315 return;
319 env = GNUNET_MQ_msg_extra (m, 316 env = GNUNET_MQ_msg_extra (m, benchmark_size, GNUNET_MESSAGE_TYPE_DUMMY);
320 benchmark_size, 317 memset (&m[1], 52, benchmark_size - sizeof (struct GNUNET_MessageHeader));
321 GNUNET_MESSAGE_TYPE_DUMMY); 318
322 memset (&m[1],
323 52,
324 benchmark_size - sizeof(struct GNUNET_MessageHeader));
325
326 if (itail->msgs_sent < benchmark_count) 319 if (itail->msgs_sent < benchmark_count)
327 { 320 {
328 GNUNET_MQ_notify_sent (env, 321 GNUNET_MQ_notify_sent (env, &send_msg, NULL);
329 &send_msg,
330 NULL);
331 } 322 }
332 else 323 else
333 { 324 {
334 iteration_done (); 325 iteration_done ();
335 } 326 }
336 GNUNET_MQ_send (mq, 327 GNUNET_MQ_send (mq, env);
337 env); 328 if ((verbosity > 0) && (0 == itail->msgs_sent % 10))
338 if ( (verbosity > 0) &&
339 (0 == itail->msgs_sent % 10) )
340 FPRINTF (stdout, "."); 329 FPRINTF (stdout, ".");
341} 330}
342 331
@@ -351,15 +340,14 @@ iteration_start ()
351 return; 340 return;
352 benchmark_running = GNUNET_YES; 341 benchmark_running = GNUNET_YES;
353 icur = GNUNET_new (struct Iteration); 342 icur = GNUNET_new (struct Iteration);
354 GNUNET_CONTAINER_DLL_insert_tail (ihead, 343 GNUNET_CONTAINER_DLL_insert_tail (ihead, itail, icur);
355 itail, 344 icur->start = GNUNET_TIME_absolute_get ();
356 icur);
357 icur->start = GNUNET_TIME_absolute_get();
358 if (verbosity > 0) 345 if (verbosity > 0)
359 FPRINTF (stdout, 346 FPRINTF (
360 "\nStarting benchmark, starting to send %u messages in %u byte blocks\n", 347 stdout,
361 benchmark_count, 348 "\nStarting benchmark, starting to send %u messages in %u byte blocks\n",
362 benchmark_size); 349 benchmark_count,
350 benchmark_size);
363 send_msg (NULL); 351 send_msg (NULL);
364} 352}
365 353
@@ -393,22 +381,16 @@ iteration_done ()
393static void * 381static void *
394notify_connect (void *cls, 382notify_connect (void *cls,
395 const struct GNUNET_PeerIdentity *peer, 383 const struct GNUNET_PeerIdentity *peer,
396 struct GNUNET_MQ_Handle *m) 384 struct GNUNET_MQ_Handle *m)
397{ 385{
398 if (0 != memcmp (&pid, 386 if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity)))
399 peer,
400 sizeof(struct GNUNET_PeerIdentity)))
401 { 387 {
402 FPRINTF (stdout, 388 FPRINTF (stdout, "Connected to different peer `%s'\n", GNUNET_i2s (&pid));
403 "Connected to different peer `%s'\n",
404 GNUNET_i2s (&pid));
405 return NULL; 389 return NULL;
406 } 390 }
407 391
408 if (verbosity > 0) 392 if (verbosity > 0)
409 FPRINTF (stdout, 393 FPRINTF (stdout, "Successfully connected to `%s'\n", GNUNET_i2s (&pid));
410 "Successfully connected to `%s'\n",
411 GNUNET_i2s (&pid));
412 mq = m; 394 mq = m;
413 iteration_start (); 395 iteration_start ();
414 return NULL; 396 return NULL;
@@ -426,18 +408,16 @@ notify_connect (void *cls,
426static void 408static void
427notify_disconnect (void *cls, 409notify_disconnect (void *cls,
428 const struct GNUNET_PeerIdentity *peer, 410 const struct GNUNET_PeerIdentity *peer,
429 void *internal_cls) 411 void *internal_cls)
430{ 412{
431 if (0 != memcmp (&pid, 413 if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity)))
432 peer,
433 sizeof(struct GNUNET_PeerIdentity)))
434 return; 414 return;
435 mq = NULL; 415 mq = NULL;
436 if (GNUNET_YES == benchmark_running) 416 if (GNUNET_YES == benchmark_running)
437 { 417 {
438 FPRINTF (stdout, 418 FPRINTF (stdout,
439 "Disconnected from peer `%s' while benchmarking\n", 419 "Disconnected from peer `%s' while benchmarking\n",
440 GNUNET_i2s (&pid)); 420 GNUNET_i2s (&pid));
441 return; 421 return;
442 } 422 }
443} 423}
@@ -451,8 +431,7 @@ notify_disconnect (void *cls,
451 * @return #GNUNET_OK 431 * @return #GNUNET_OK
452 */ 432 */
453static int 433static int
454check_dummy (void *cls, 434check_dummy (void *cls, const struct GNUNET_MessageHeader *message)
455 const struct GNUNET_MessageHeader *message)
456{ 435{
457 return GNUNET_OK; /* all messages are fine */ 436 return GNUNET_OK; /* all messages are fine */
458} 437}
@@ -465,30 +444,24 @@ check_dummy (void *cls,
465 * @param message the message 444 * @param message the message
466 */ 445 */
467static void 446static void
468handle_dummy (void *cls, 447handle_dummy (void *cls, const struct GNUNET_MessageHeader *message)
469 const struct GNUNET_MessageHeader *message)
470{ 448{
471 if (! benchmark_receive) 449 if (! benchmark_receive)
472 return; 450 return;
473 if (verbosity > 0) 451 if (verbosity > 0)
474 FPRINTF (stdout, 452 FPRINTF (stdout,
475 "Received %u bytes\n", 453 "Received %u bytes\n",
476 (unsigned int) ntohs (message->size)); 454 (unsigned int) ntohs (message->size));
477} 455}
478 456
479 457
480static int 458static int
481blacklist_cb (void *cls, 459blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
482 const struct GNUNET_PeerIdentity *peer)
483{ 460{
484 if (0 != memcmp (&pid, 461 if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity)))
485 peer,
486 sizeof(struct GNUNET_PeerIdentity)))
487 { 462 {
488 if (verbosity > 0) 463 if (verbosity > 0)
489 FPRINTF (stdout, 464 FPRINTF (stdout, "Denying connection to `%s'\n", GNUNET_i2s (peer));
490 "Denying connection to `%s'\n",
491 GNUNET_i2s (peer));
492 return GNUNET_SYSERR; 465 return GNUNET_SYSERR;
493 } 466 }
494 return GNUNET_OK; 467 return GNUNET_OK;
@@ -509,38 +482,32 @@ run (void *cls,
509 const char *cfgfile, 482 const char *cfgfile,
510 const struct GNUNET_CONFIGURATION_Handle *mycfg) 483 const struct GNUNET_CONFIGURATION_Handle *mycfg)
511{ 484{
512 struct GNUNET_MQ_MessageHandler handlers[] = { 485 struct GNUNET_MQ_MessageHandler handlers[] =
513 GNUNET_MQ_hd_var_size (dummy, 486 {GNUNET_MQ_hd_var_size (dummy,
514 GNUNET_MESSAGE_TYPE_DUMMY, 487 GNUNET_MESSAGE_TYPE_DUMMY,
515 struct GNUNET_MessageHeader, 488 struct GNUNET_MessageHeader,
516 NULL), 489 NULL),
517 GNUNET_MQ_handler_end () 490 GNUNET_MQ_handler_end ()};
518 }; 491
519
520 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; 492 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
521 493
522 ret = 1; 494 ret = 1;
523 if (GNUNET_MAX_MESSAGE_SIZE <= benchmark_size) 495 if (GNUNET_MAX_MESSAGE_SIZE <= benchmark_size)
524 { 496 {
525 FPRINTF (stderr, 497 FPRINTF (stderr, "Message size too big!\n");
526 "Message size too big!\n");
527 return; 498 return;
528 } 499 }
529 500
530 if (NULL == cpid) 501 if (NULL == cpid)
531 { 502 {
532 FPRINTF (stderr, 503 FPRINTF (stderr, "No peer identity given\n");
533 "No peer identity given\n");
534 return; 504 return;
535 } 505 }
536 if (GNUNET_OK != 506 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (cpid,
537 GNUNET_CRYPTO_eddsa_public_key_from_string (cpid, 507 strlen (cpid),
538 strlen (cpid), 508 &pid.public_key))
539 &pid.public_key))
540 { 509 {
541 FPRINTF (stderr, 510 FPRINTF (stderr, "Failed to parse peer identity `%s'\n", cpid);
542 "Failed to parse peer identity `%s'\n",
543 cpid);
544 return; 511 return;
545 } 512 }
546 if (1 == benchmark_send) 513 if (1 == benchmark_send)
@@ -548,7 +515,8 @@ run (void *cls,
548 if (verbosity > 0) 515 if (verbosity > 0)
549 FPRINTF (stderr, 516 FPRINTF (stderr,
550 "Trying to send %u messages with size %u to peer `%s'\n", 517 "Trying to send %u messages with size %u to peer `%s'\n",
551 benchmark_count, benchmark_size, 518 benchmark_count,
519 benchmark_size,
552 GNUNET_i2s (&pid)); 520 GNUNET_i2s (&pid));
553 } 521 }
554 else if (1 == benchmark_receive) 522 else if (1 == benchmark_receive)
@@ -559,50 +527,42 @@ run (void *cls,
559 } 527 }
560 else 528 else
561 { 529 {
562 FPRINTF (stderr, 530 FPRINTF (stderr, "No operation given\n");
563 "No operation given\n");
564 return; 531 return;
565 } 532 }
566 533
567 ats = GNUNET_ATS_connectivity_init (cfg); 534 ats = GNUNET_ATS_connectivity_init (cfg);
568 if (NULL == ats) 535 if (NULL == ats)
569 { 536 {
570 FPRINTF (stderr, 537 FPRINTF (stderr, "Failed to connect to ATS service\n");
571 "Failed to connect to ATS service\n");
572 ret = 1; 538 ret = 1;
573 return; 539 return;
574 } 540 }
575 541
576 handle = GNUNET_TRANSPORT_core_connect (cfg, 542 handle = GNUNET_TRANSPORT_core_connect (cfg,
577 NULL, 543 NULL,
578 handlers, 544 handlers,
579 NULL, 545 NULL,
580 &notify_connect, 546 &notify_connect,
581 &notify_disconnect, 547 &notify_disconnect,
582 NULL); 548 NULL);
583 if (NULL == handle) 549 if (NULL == handle)
584 { 550 {
585 FPRINTF (stderr, 551 FPRINTF (stderr, "Failed to connect to transport service\n");
586 "Failed to connect to transport service\n");
587 GNUNET_ATS_connectivity_done (ats); 552 GNUNET_ATS_connectivity_done (ats);
588 ats = NULL; 553 ats = NULL;
589 ret = 1; 554 ret = 1;
590 return; 555 return;
591 } 556 }
592 557
593 bl_handle = GNUNET_TRANSPORT_blacklist (cfg, 558 bl_handle = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL);
594 &blacklist_cb, 559 ats_sh = GNUNET_ATS_connectivity_suggest (ats, &pid, 1);
595 NULL); 560 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
596 ats_sh = GNUNET_ATS_connectivity_suggest (ats,
597 &pid,
598 1);
599 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
600 NULL);
601} 561}
602 562
603 563
604int 564int
605main (int argc, char * const *argv) 565main (int argc, char *const *argv)
606{ 566{
607 int res; 567 int res;
608 benchmark_count = DEFAULT_MESSAGE_COUNT; 568 benchmark_count = DEFAULT_MESSAGE_COUNT;
@@ -613,46 +573,48 @@ main (int argc, char * const *argv)
613 struct GNUNET_GETOPT_CommandLineOption options[] = { 573 struct GNUNET_GETOPT_CommandLineOption options[] = {
614 574
615 GNUNET_GETOPT_option_flag ('s', 575 GNUNET_GETOPT_option_flag ('s',
616 "send", 576 "send",
617 gettext_noop ("send data to peer"), 577 gettext_noop ("send data to peer"),
618 &benchmark_send), 578 &benchmark_send),
619 GNUNET_GETOPT_option_flag ('r', 579 GNUNET_GETOPT_option_flag ('r',
620 "receive", 580 "receive",
621 gettext_noop ("receive data from peer"), 581 gettext_noop ("receive data from peer"),
622 &benchmark_receive), 582 &benchmark_receive),
623 GNUNET_GETOPT_option_uint ('i', 583 GNUNET_GETOPT_option_uint ('i',
624 "iterations", 584 "iterations",
625 NULL, 585 NULL,
626 gettext_noop ("iterations"), 586 gettext_noop ("iterations"),
627 &benchmark_iterations), 587 &benchmark_iterations),
628 GNUNET_GETOPT_option_uint ('n', 588 GNUNET_GETOPT_option_uint ('n',
629 "number", 589 "number",
630 NULL, 590 NULL,
631 gettext_noop ("number of messages to send"), 591 gettext_noop ("number of messages to send"),
632 &benchmark_count), 592 &benchmark_count),
633 GNUNET_GETOPT_option_uint ('m', 593 GNUNET_GETOPT_option_uint ('m',
634 "messagesize", 594 "messagesize",
635 NULL, 595 NULL,
636 gettext_noop ("message size to use"), 596 gettext_noop ("message size to use"),
637 &benchmark_size), 597 &benchmark_size),
638 GNUNET_GETOPT_option_string ('p', 598 GNUNET_GETOPT_option_string ('p',
639 "peer", 599 "peer",
640 "PEER", 600 "PEER",
641 gettext_noop ("peer identity"), 601 gettext_noop ("peer identity"),
642 &cpid), 602 &cpid),
643 GNUNET_GETOPT_option_verbose (&verbosity), 603 GNUNET_GETOPT_option_verbose (&verbosity),
644 GNUNET_GETOPT_OPTION_END 604 GNUNET_GETOPT_OPTION_END};
645 };
646 605
647 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 606 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
648 return 2; 607 return 2;
649 608
650 res = GNUNET_PROGRAM_run (argc, argv, 609 res =
651 "gnunet-transport", 610 GNUNET_PROGRAM_run (argc,
652 gettext_noop ("Direct access to transport service."), 611 argv,
653 options, 612 "gnunet-transport",
654 &run, NULL); 613 gettext_noop ("Direct access to transport service."),
655 GNUNET_free((void *) argv); 614 options,
615 &run,
616 NULL);
617 GNUNET_free ((void *) argv);
656 if (GNUNET_OK == res) 618 if (GNUNET_OK == res)
657 return ret; 619 return ret;
658 return 1; 620 return 1;