X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fats-tests%2Fperf_ats.c;h=e0affb4f91a059c589c0bf7213a815e3645f1359;hb=4dcb414e2faabc800577c25dec3b63e3ceaaa84b;hp=daffb9f289539d84bc060b09ccf490cd753c62d3;hpb=f15624031417464fa72c659be7e0be8db55a909b;p=oweals%2Fgnunet.git diff --git a/src/ats-tests/perf_ats.c b/src/ats-tests/perf_ats.c index daffb9f28..e0affb4f9 100644 --- a/src/ats-tests/perf_ats.c +++ b/src/ats-tests/perf_ats.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2010-2013 Christian Grothoff (and other contributing authors) + Copyright (C) 2010-2013 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -14,8 +14,8 @@ You should have received a copy of the GNU General Public License along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ /** * @file ats/perf_ats.c @@ -35,21 +35,23 @@ #define TEST_ATS_PREFRENCE_START 1.0 #define TEST_ATS_PREFRENCE_DELTA 1.0 -#define TEST_MESSAGE_TYPE_PING 12345 -#define TEST_MESSAGE_TYPE_PONG 12346 -#define TEST_MESSAGE_SIZE 1000 #define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) - +#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) +#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) +#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500) +#define TESTNAME_PREFIX "perf_ats_" +#define DEFAULT_SLAVES_NUM 2 +#define DEFAULT_MASTERS_NUM 1 /** * Shutdown task */ -static GNUNET_SCHEDULER_TaskIdentifier shutdown_task; +static struct GNUNET_SCHEDULER_Task * shutdown_task; /** * Progress task */ -static GNUNET_SCHEDULER_TaskIdentifier progress_task; +static struct GNUNET_SCHEDULER_Task * progress_task; /** * Test result @@ -115,6 +117,8 @@ static unsigned int num_slaves; */ static struct BenchmarkPeer *sps; +static struct LoggingHandle *l; + static void evaluate () { @@ -124,6 +128,12 @@ evaluate () struct BenchmarkPeer *mp; struct BenchmarkPartner *p; + unsigned int kb_sent_sec; + double kb_sent_percent; + unsigned int kb_recv_sec; + double kb_recv_percent; + unsigned int rtt; + duration = (perf_duration.rel_value_us / (1000 * 1000)); for (c_m = 0; c_m < num_masters; c_m++) { @@ -138,19 +148,35 @@ evaluate () for (c_s = 0; c_s < num_slaves; c_s++) { p = &mp->partners[c_s]; + + kb_sent_sec = 0; + kb_recv_sec = 0; + kb_sent_percent = 0.0; + kb_recv_percent = 0.0; + rtt = 0; + + if (duration > 0) + { + kb_sent_sec = (p->bytes_sent / 1024) / duration; + kb_recv_sec = (p->bytes_received / 1024) / duration; + } + + if (mp->total_bytes_sent > 0) + kb_sent_percent = ((double) p->bytes_sent * 100) / mp->total_bytes_sent; + if (mp->total_bytes_received > 0) + kb_recv_percent = ((double) p->bytes_received * 100) / mp->total_bytes_received; + if (1000 * p->messages_sent > 0) + rtt = p->total_app_rtt / (1000 * p->messages_sent); fprintf (stderr, "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n", (mp->pref_partner == p->dest) ? '*' : ' ', mp->no, p->dest->no, - (p->bytes_sent / 1024) / duration, - ((double) p->bytes_sent * 100) / mp->total_bytes_sent, - (p->bytes_received / 1024) / duration, - ((double) p->bytes_received * 100) / mp->total_bytes_received ); + kb_sent_sec, kb_sent_percent, + kb_recv_sec, kb_recv_percent); fprintf (stderr, "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n", (mp->pref_partner == p->dest) ? '*' : ' ', - mp->no, p->dest->no, - p->total_app_rtt / (1000 * p->messages_sent)); + mp->no, p->dest->no, rtt); } } } @@ -164,17 +190,17 @@ evaluate () static void do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - /* + if (GNUNET_YES == logging) - perf_logging_stop(); -*/ - shutdown_task = GNUNET_SCHEDULER_NO_TASK; - if (GNUNET_SCHEDULER_NO_TASK != progress_task) + GNUNET_ATS_TEST_logging_clean_up(l); + + shutdown_task = NULL; + if (NULL != progress_task) { fprintf (stderr, "0\n"); GNUNET_SCHEDULER_cancel (progress_task); } - progress_task = GNUNET_SCHEDULER_NO_TASK; + progress_task = NULL; evaluate (); GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n")); @@ -182,69 +208,12 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_ATS_TEST_shutdown_topology(); } -static size_t -comm_send_ready (void *cls, size_t size, void *buf) -{ - static char msgbuf[TEST_MESSAGE_SIZE]; - struct BenchmarkPartner *p = cls; - struct GNUNET_MessageHeader *msg; - - if (GNUNET_YES == test_core) - p->cth = NULL; - else - p->tth = NULL; - - if (NULL == buf) - { - GNUNET_break (0); - return 0; - } - if (size < TEST_MESSAGE_SIZE) - { - GNUNET_break (0); - return 0; - } - - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Master [%u]: Sending PING to [%u]\n", - p->me->no, p->dest->no); - - p->messages_sent++; - p->bytes_sent += TEST_MESSAGE_SIZE; - p->me->total_messages_sent++; - p->me->total_bytes_sent += TEST_MESSAGE_SIZE; - - msg = (struct GNUNET_MessageHeader *) &msgbuf; - memset (&msgbuf, 'a', TEST_MESSAGE_SIZE); - msg->type = htons (TEST_MESSAGE_TYPE_PING); - msg->size = htons (TEST_MESSAGE_SIZE); - memcpy (buf, msg, TEST_MESSAGE_SIZE); - return TEST_MESSAGE_SIZE; -} - -static void -comm_schedule_send (struct BenchmarkPartner *p) -{ - p->last_message_sent = GNUNET_TIME_absolute_get(); - if (GNUNET_YES == test_core) - { - p->cth = GNUNET_CORE_notify_transmit_ready ( - p->me->ch, GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, &p->dest->id, - TEST_MESSAGE_SIZE, &comm_send_ready, p); - } - else - { - p->tth = GNUNET_TRANSPORT_notify_transmit_ready ( - p->me->th, &p->dest->id, TEST_MESSAGE_SIZE, 0,GNUNET_TIME_UNIT_MINUTES, - &comm_send_ready, p); - } - -} static void print_progress () { static int calls; - progress_task = GNUNET_SCHEDULER_NO_TASK; + progress_task = NULL; fprintf (stderr, "%llu..", (long long unsigned) perf_duration.rel_value_us / (1000 * 1000) - calls); @@ -259,7 +228,7 @@ ats_pref_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct BenchmarkPeer *me = cls; - me->ats_task = GNUNET_SCHEDULER_NO_TASK; + me->ats_task = NULL; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, " Master [%u] set preference for slave [%u] to %f\n", me->no, me->pref_partner->no, me->pref_value); @@ -272,66 +241,52 @@ ats_pref_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } static void -do_benchmark (void *cls, struct BenchmarkPeer *masters, struct BenchmarkPeer *slaves) +start_benchmark() { int c_m; int c_s; - mps = masters; - sps = slaves; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking start\n")); - if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) - GNUNET_SCHEDULER_cancel (shutdown_task); - shutdown_task = GNUNET_SCHEDULER_add_delayed (perf_duration, - &do_shutdown, NULL ); + if (NULL != shutdown_task) + GNUNET_SCHEDULER_cancel(shutdown_task); + shutdown_task = GNUNET_SCHEDULER_add_delayed(perf_duration, &do_shutdown, + NULL ); - progress_task = GNUNET_SCHEDULER_add_now (&print_progress, NULL ); + progress_task = GNUNET_SCHEDULER_add_now(&print_progress, NULL ); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Topology connected, start benchmarking...\n"); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Topology connected, start benchmarking...\n"); /* Start sending test messages */ for (c_m = 0; c_m < num_masters; c_m++) - { - for (c_s = 0; c_s < num_slaves; c_s++) - comm_schedule_send (&masters[c_m].partners[c_s]); - if (pref_val != GNUNET_ATS_PREFERENCE_END) - masters[c_m].ats_task = GNUNET_SCHEDULER_add_now (&ats_pref_task, &masters[c_m]); - } + { + for (c_s = 0; c_s < num_slaves; c_s++) + { + GNUNET_ATS_TEST_generate_traffic_start (&mps[c_m], &mps[c_m].partners[c_s], + GNUNET_ATS_TEST_TG_LINEAR, UINT32_MAX, UINT32_MAX, + GNUNET_TIME_UNIT_MINUTES, GNUNET_TIME_UNIT_FOREVER_REL); + } + if (pref_val != GNUNET_ATS_PREFERENCE_END) + mps[c_m].ats_task = GNUNET_SCHEDULER_add_now(&ats_pref_task, &mps[c_m]); + } - /* if (GNUNET_YES == logging) - perf_logging_start (log_frequency, testname, mps, num_masters); -*/ + l = GNUNET_ATS_TEST_logging_start (log_frequency, testname, mps, + num_masters, num_slaves, GNUNET_NO); } - -static size_t -comm_send_pong_ready (void *cls, size_t size, void *buf) +static void +do_benchmark (void *cls, struct BenchmarkPeer *masters, struct BenchmarkPeer *slaves) { - static char msgbuf[TEST_MESSAGE_SIZE]; - struct BenchmarkPartner *p = cls; - struct GNUNET_MessageHeader *msg; + mps = masters; + sps = slaves; - if (GNUNET_YES == test_core) - p->cth = NULL; - else - p->tth = NULL; + GNUNET_SCHEDULER_add_now(&start_benchmark, NULL); +} - p->messages_sent++; - p->bytes_sent += TEST_MESSAGE_SIZE; - p->me->total_messages_sent++; - p->me->total_bytes_sent += TEST_MESSAGE_SIZE; - msg = (struct GNUNET_MessageHeader *) &msgbuf; - memset (&msgbuf, 'a', TEST_MESSAGE_SIZE); - msg->type = htons (TEST_MESSAGE_TYPE_PONG); - msg->size = htons (TEST_MESSAGE_SIZE); - memcpy (buf, msg, TEST_MESSAGE_SIZE); - return TEST_MESSAGE_SIZE; -} static struct BenchmarkPartner * find_partner (struct BenchmarkPeer *me, const struct GNUNET_PeerIdentity * peer) @@ -349,113 +304,26 @@ find_partner (struct BenchmarkPeer *me, const struct GNUNET_PeerIdentity * peer) return &me->partners[c_m]; } } - return NULL; } -static int -comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other, - const struct GNUNET_MessageHeader *message) -{ - - struct BenchmarkPeer *me = cls; - struct BenchmarkPartner *p = NULL; - - if (NULL == (p = find_partner(me, other))) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Slave [%u]: Received PING from [%u], sending PONG\n", me->no, - p->dest->no); - - p->messages_received++; - p->bytes_received += TEST_MESSAGE_SIZE; - p->me->total_messages_received++; - p->me->total_bytes_received += TEST_MESSAGE_SIZE; - - if (GNUNET_YES == test_core) - { - GNUNET_assert (NULL == p->cth); - p->cth = GNUNET_CORE_notify_transmit_ready (me->ch, GNUNET_NO, 0, - GNUNET_TIME_UNIT_MINUTES, &p->dest->id, TEST_MESSAGE_SIZE, - &comm_send_pong_ready, p); - } - else - { - GNUNET_assert (NULL == p->tth); - p->tth = GNUNET_TRANSPORT_notify_transmit_ready (me->th, &p->dest->id, - TEST_MESSAGE_SIZE, 0, GNUNET_TIME_UNIT_MINUTES, &comm_send_pong_ready, - p); - } - return GNUNET_OK; -} - -static int -comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other, - const struct GNUNET_MessageHeader *message) -{ - struct BenchmarkPeer *me = cls; - struct BenchmarkPartner *p = NULL; - - if (NULL == (p = find_partner (me, other))) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } - - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Master [%u]: Received PONG from [%u], next message\n", me->no, - p->dest->no); - - p->messages_received++; - p->bytes_received += TEST_MESSAGE_SIZE; - p->me->total_messages_received++; - p->me->total_bytes_received += TEST_MESSAGE_SIZE; - p->total_app_rtt += GNUNET_TIME_absolute_get_difference(p->last_message_sent, - GNUNET_TIME_absolute_get()).rel_value_us; - - comm_schedule_send (p); - return GNUNET_OK; -} - - - static void -transport_recv_cb (void *cls, - const struct GNUNET_PeerIdentity * peer, - const struct GNUNET_MessageHeader * message) +test_recv_cb (void *cls, + const struct GNUNET_PeerIdentity * peer, + const struct GNUNET_MessageHeader * message) { - GNUNET_break (0); - if (TEST_MESSAGE_SIZE != ntohs (message->size) || - (TEST_MESSAGE_TYPE_PING != ntohs (message->type) && - TEST_MESSAGE_TYPE_PONG != ntohs (message->type))) - { - return; - } - if (TEST_MESSAGE_TYPE_PING == ntohs (message->type)) - comm_handle_ping (cls, peer, message); - if (TEST_MESSAGE_TYPE_PONG == ntohs (message->type)) - comm_handle_pong (cls, peer, message); } - - - static void -ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address, +log_request_cb (void *cls, const struct GNUNET_HELLO_Address *address, int address_active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - const struct GNUNET_ATS_Information *ats, uint32_t ats_count) + const struct GNUNET_ATS_Properties *ats) { struct BenchmarkPeer *me = cls; struct BenchmarkPartner *p; - int c_a; - int log; char *peer_id; p = find_partner (me, &address->peer); @@ -468,82 +336,25 @@ ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address, } peer_id = GNUNET_strdup (GNUNET_i2s (&me->id)); - log = GNUNET_NO; if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) || (p->bandwidth_out != ntohl (bandwidth_out.value__))) - log = GNUNET_YES; p->bandwidth_in = ntohl (bandwidth_in.value__); p->bandwidth_out = ntohl (bandwidth_out.value__); - for (c_a = 0; c_a < ats_count; c_a++) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s [%u] received ATS information: %s %s %u\n", - (GNUNET_YES == p->me->master) ? "Master" : "Slave", - p->me->no, - GNUNET_i2s (&p->dest->id), - GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)), - ntohl(ats[c_a].value)); - switch (ntohl (ats[c_a].type )) - { - case GNUNET_ATS_ARRAY_TERMINATOR: - break; - case GNUNET_ATS_UTILIZATION_OUT: - if (p->ats_utilization_up != ntohl (ats[c_a].value)) - log = GNUNET_YES; - p->ats_utilization_up = ntohl (ats[c_a].value); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s [%u] received ATS information for peers `%s'\n", + (GNUNET_YES == p->me->master) ? "Master" : "Slave", + p->me->no, + GNUNET_i2s (&p->dest->id)); - break; - case GNUNET_ATS_UTILIZATION_IN: - if (p->ats_utilization_down != ntohl (ats[c_a].value)) - log = GNUNET_YES; - p->ats_utilization_down = ntohl (ats[c_a].value); - break; - case GNUNET_ATS_NETWORK_TYPE: - if (p->ats_network_type != ntohl (ats[c_a].value)) - log = GNUNET_YES; - p->ats_network_type = ntohl (ats[c_a].value); - break; - case GNUNET_ATS_QUALITY_NET_DELAY: - if (p->ats_delay != ntohl (ats[c_a].value)) - log = GNUNET_YES; - p->ats_delay = ntohl (ats[c_a].value); - break; - case GNUNET_ATS_QUALITY_NET_DISTANCE: - if (p->ats_distance != ntohl (ats[c_a].value)) - log = GNUNET_YES; - p->ats_distance = ntohl (ats[c_a].value); - GNUNET_break (0); - break; - case GNUNET_ATS_COST_WAN: - if (p->ats_cost_wan != ntohl (ats[c_a].value)) - log = GNUNET_YES; - p->ats_cost_wan = ntohl (ats[c_a].value); - break; - case GNUNET_ATS_COST_LAN: - if (p->ats_cost_lan != ntohl (ats[c_a].value)) - log = GNUNET_YES; - p->ats_cost_lan = ntohl (ats[c_a].value); - break; - case GNUNET_ATS_COST_WLAN: - if (p->ats_cost_wlan != ntohl (ats[c_a].value)) - log = GNUNET_YES; - p->ats_cost_wlan = ntohl (ats[c_a].value); - break; - default: - break; - } - } - /* - if ((GNUNET_YES == logging) && (GNUNET_YES == log)) - collect_log_now(); - */ GNUNET_free(peer_id); + if (NULL != l) + GNUNET_ATS_TEST_logging_now (l); } - - - +/* + * Start the performance test case + */ int main (int argc, char *argv[]) { @@ -553,22 +364,32 @@ main (int argc, char *argv[]) char *conf_name; char *comm_name; char *dotexe; - char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString; + char *prefs[] = GNUNET_ATS_PreferenceTypeString; int c; result = 0; - /* figure out testname */ + /* Determine testname + * perf_ats___[.exe]*/ + + /* Find test prefix, store in temp */ tmp = strstr (argv[0], TESTNAME_PREFIX); if (NULL == tmp) { fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]); return GNUNET_SYSERR; } + + /* Set tmp to end of test name prefix */ tmp += strlen (TESTNAME_PREFIX); + + /* Determine solver name */ solver = GNUNET_strdup (tmp); + /* Remove .exe prefix */ if (NULL != (dotexe = strstr (solver, ".exe")) && dotexe[4] == '\0') dotexe[0] = '\0'; + + /* Determine first '_' after solver */ tmp_sep = strchr (solver, '_'); if (NULL == tmp_sep) { @@ -611,7 +432,7 @@ main (int argc, char *argv[]) if (0 != strcmp (pref_str, "NONE")) { - for (c = 1; c < GNUNET_ATS_PreferenceCount; c++) + for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++) { if (0 == strcmp (pref_str, prefs[c])) { @@ -721,14 +542,16 @@ main (int argc, char *argv[]) return GNUNET_SYSERR; } - static struct GNUNET_CORE_MessageHandler handlers[] = { - {&comm_handle_ping, TEST_MESSAGE_TYPE_PING, 0 }, - {&comm_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 }, - { NULL, 0, 0 } }; - + /** + * Setup the topology + */ GNUNET_ATS_TEST_create_topology ("perf-ats", conf_name, - num_slaves, num_masters, test_core, - &do_benchmark, NULL, handlers, &transport_recv_cb); + num_slaves, num_masters, + test_core, + &do_benchmark, + NULL, + &test_recv_cb, + &log_request_cb); return result; }