diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-08-23 09:26:09 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-08-23 09:26:09 +0000 |
commit | 5fcf6899e09d5fb3276e9af5bac4d15fecbc3fec (patch) | |
tree | db2d03eda0563b78541395d844dfaac3f386a403 /src/ats/perf_ats.c | |
parent | 1b29841f56357fbb35cf377f1fb951ce74a7ba2a (diff) | |
download | gnunet-5fcf6899e09d5fb3276e9af5bac4d15fecbc3fec.tar.gz gnunet-5fcf6899e09d5fb3276e9af5bac4d15fecbc3fec.zip |
load balancing for partner selection
Diffstat (limited to 'src/ats/perf_ats.c')
-rw-r--r-- | src/ats/perf_ats.c | 52 |
1 files changed, 44 insertions, 8 deletions
diff --git a/src/ats/perf_ats.c b/src/ats/perf_ats.c index 208e08b0a..b7cdeecff 100644 --- a/src/ats/perf_ats.c +++ b/src/ats/perf_ats.c | |||
@@ -87,7 +87,8 @@ struct BenchmarkPeer | |||
87 | struct PendingMessages *p_head; | 87 | struct PendingMessages *p_head; |
88 | struct PendingMessages *p_tail; | 88 | struct PendingMessages *p_tail; |
89 | 89 | ||
90 | int last_slave; | 90 | /* Bit-mask for next partner selection */ |
91 | uint32_t send_mask; | ||
91 | 92 | ||
92 | int core_connections; | 93 | int core_connections; |
93 | 94 | ||
@@ -397,11 +398,46 @@ core_send_ready (void *cls, size_t size, void *buf) | |||
397 | return TEST_MESSAGE_SIZE; | 398 | return TEST_MESSAGE_SIZE; |
398 | } | 399 | } |
399 | 400 | ||
401 | static struct BenchmarkPeer * | ||
402 | get_next (struct BenchmarkPeer *p) | ||
403 | { | ||
404 | uint32_t b_index; | ||
405 | uint32_t index; | ||
406 | int counter; | ||
407 | |||
408 | if (0 == p->send_mask) | ||
409 | p->send_mask = (1 << c_slave_peers) - 1; /* Next round */ | ||
410 | |||
411 | GNUNET_assert (p->send_mask <= (1 << c_slave_peers) - 1); | ||
412 | counter = 0; | ||
413 | do | ||
414 | { | ||
415 | index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, c_slave_peers); | ||
416 | b_index = 1 << index; | ||
417 | counter++; | ||
418 | } | ||
419 | while ((b_index != (p->send_mask & b_index)) && (counter < c_slave_peers)); | ||
420 | if ((b_index != (p->send_mask & b_index)) && (counter == c_slave_peers)) | ||
421 | { | ||
422 | /* To many random attempts use fcfs */ | ||
423 | for (index = 0; index < c_slave_peers - 1; index ++) | ||
424 | { | ||
425 | b_index = 1 << index; | ||
426 | if (b_index == (p->send_mask & b_index)) | ||
427 | break; | ||
428 | } | ||
429 | } | ||
430 | p->send_mask ^= b_index; /* Remove bit */ | ||
431 | return &bp_slaves[index]; | ||
432 | |||
433 | } | ||
434 | |||
400 | 435 | ||
401 | static void | 436 | static void |
402 | do_benchmark () | 437 | do_benchmark () |
403 | { | 438 | { |
404 | int c_m; | 439 | int c_m; |
440 | struct BenchmarkPeer *s; | ||
405 | 441 | ||
406 | if ((state.connected_ATS_service == GNUNET_NO) || | 442 | if ((state.connected_ATS_service == GNUNET_NO) || |
407 | (state.connected_CORE_service == GNUNET_NO) || | 443 | (state.connected_CORE_service == GNUNET_NO) || |
@@ -420,10 +456,10 @@ do_benchmark () | |||
420 | /* Start sending test messages */ | 456 | /* Start sending test messages */ |
421 | for (c_m = 0; c_m < c_master_peers; c_m ++) | 457 | for (c_m = 0; c_m < c_master_peers; c_m ++) |
422 | { | 458 | { |
423 | bp_master[c_m].last_slave = 0; | 459 | s = get_next (&bp_master[c_m]); |
424 | bp_master[c_m].cth = GNUNET_CORE_notify_transmit_ready (bp_master[c_m].ch, | 460 | bp_master[c_m].cth = GNUNET_CORE_notify_transmit_ready (bp_master[c_m].ch, |
425 | GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, | 461 | GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, |
426 | &bp_slaves[bp_master[c_m].last_slave].id, | 462 | &s->id, |
427 | TEST_MESSAGE_SIZE, &core_send_ready, &bp_master[c_m]); | 463 | TEST_MESSAGE_SIZE, &core_send_ready, &bp_master[c_m]); |
428 | } | 464 | } |
429 | 465 | ||
@@ -725,6 +761,7 @@ core_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other, | |||
725 | { | 761 | { |
726 | struct BenchmarkPeer *me = cls; | 762 | struct BenchmarkPeer *me = cls; |
727 | struct BenchmarkPeer *remote; | 763 | struct BenchmarkPeer *remote; |
764 | struct BenchmarkPeer *next; | ||
728 | 765 | ||
729 | remote = find_peer (other); | 766 | remote = find_peer (other); |
730 | 767 | ||
@@ -746,12 +783,10 @@ core_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other, | |||
746 | return GNUNET_OK; | 783 | return GNUNET_OK; |
747 | } | 784 | } |
748 | me->messages_received ++; | 785 | me->messages_received ++; |
749 | me->last_slave++; | 786 | next = get_next (me); |
750 | if (me->last_slave == c_slave_peers) | ||
751 | me->last_slave = 0; | ||
752 | me->cth = GNUNET_CORE_notify_transmit_ready (me->ch, | 787 | me->cth = GNUNET_CORE_notify_transmit_ready (me->ch, |
753 | GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, | 788 | GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, |
754 | &bp_slaves[me->last_slave].id, | 789 | &next->id, |
755 | TEST_MESSAGE_SIZE, &core_send_ready, me); | 790 | TEST_MESSAGE_SIZE, &core_send_ready, me); |
756 | 791 | ||
757 | return GNUNET_OK; | 792 | return GNUNET_OK; |
@@ -1056,6 +1091,7 @@ test_main (void *cls, unsigned int num_peers, | |||
1056 | { | 1091 | { |
1057 | GNUNET_assert (NULL != peers_[c_p]); | 1092 | GNUNET_assert (NULL != peers_[c_p]); |
1058 | bp_master[c_p].no = c_p; | 1093 | bp_master[c_p].no = c_p; |
1094 | bp_master[c_p].send_mask = (1 << c_slave_peers) - 1; | ||
1059 | bp_master[c_p].master = GNUNET_YES; | 1095 | bp_master[c_p].master = GNUNET_YES; |
1060 | bp_master[c_p].peer = peers_[c_p]; | 1096 | bp_master[c_p].peer = peers_[c_p]; |
1061 | bp_master[c_p].info_op = GNUNET_TESTBED_peer_get_information (bp_master[c_p].peer, | 1097 | bp_master[c_p].info_op = GNUNET_TESTBED_peer_get_information (bp_master[c_p].peer, |
@@ -1121,7 +1157,7 @@ main (int argc, char *argv[]) | |||
1121 | } | 1157 | } |
1122 | if (c < argc-1) | 1158 | if (c < argc-1) |
1123 | { | 1159 | { |
1124 | if ((0L != (c_slave_peers = strtol (argv[c + 1], NULL, 10))) && (c_slave_peers >= 2)) | 1160 | if ((0L != (c_slave_peers = strtol (argv[c + 1], NULL, 10))) && (c_slave_peers >= 1)) |
1125 | fprintf (stderr, "Starting %u slave peers\n", c_slave_peers); | 1161 | fprintf (stderr, "Starting %u slave peers\n", c_slave_peers); |
1126 | else | 1162 | else |
1127 | c_slave_peers = DEFAULT_SLAVES_NUM; | 1163 | c_slave_peers = DEFAULT_SLAVES_NUM; |