2 This file is part of GNUnet.
3 (C) 2010,2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file ats/perf_ats_solver.c
22 * @brief generic performance test for ATS solvers
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 #include "gnunet_util_lib.h"
28 #include "gnunet_statistics_service.h"
29 #include "gnunet-service-ats_addresses.h"
30 #include "gnunet-service-ats_normalization.h"
31 #include "gnunet_ats_service.h"
32 #include "gnunet_ats_plugin.h"
33 #include "test_ats_api_common.h"
35 #define DEFAULT_UPDATE_PERCENTAGE 20
36 #define DEFAULT_PEERS_START 10
37 #define DEFAULT_PEERS_END 10
38 #define DEFAULT_ADDRESSES 10
39 #define DEFAULT_ATS_COUNT 2
41 #define GNUPLOT_PROP_TEMPLATE "#!/usr/bin/gnuplot \n" \
42 "set datafile separator ';' \n" \
43 "set title \"Execution time Proportional solver \" \n" \
44 "set xlabel \"Number of peers\" \n" \
45 "set ylabel \"Execution time in us\" \n" \
48 #define GNUPLOT_PROP_UPDATE_TEMPLATE "#!/usr/bin/gnuplot \n" \
49 "set datafile separator ';' \n" \
50 "set title \"Execution time Proportional solver with updated problem\" \n" \
51 "set xlabel \"Number of peers\" \n" \
52 "set ylabel \"Execution time in us\" \n" \
55 #define GNUPLOT_MLP_TEMPLATE "#!/usr/bin/gnuplot \n" \
56 "set datafile separator ';' \n" \
57 "set title \"Execution time MLP solver \" \n" \
58 "set xlabel \"Number of peers\" \n" \
59 "set ylabel \"Execution time in us\" \n" \
62 #define GNUPLOT_MLP_UPDATE_TEMPLATE "#!/usr/bin/gnuplot \n" \
63 "set datafile separator ';' \n" \
64 "set title \"Execution time MLP solver with updated problem\" \n" \
65 "set xlabel \"Number of peers\" \n" \
66 "set ylabel \"Execution time in us\" \n" \
69 #define GNUPLOT_RIL_TEMPLATE "#!/usr/bin/gnuplot \n" \
70 "set datafile separator ';' \n" \
71 "set title \"Execution time RIL solver \" \n" \
72 "set xlabel \"Number of peers\" \n" \
73 "set ylabel \"Execution time in us\" \n" \
76 #define GNUPLOT_RIL_UPDATE_TEMPLATE "#!/usr/bin/gnuplot \n" \
77 "set datafile separator ';' \n" \
78 "set title \"Execution time RIL solver with updated problem\" \n" \
79 "set xlabel \"Number of peers\" \n" \
80 "set ylabel \"Execution time in us\" \n" \
84 * Handle for ATS address component
91 struct PerfPeer *peers;
101 struct GNUNET_STATISTICS_Handle *stat;
104 * A multihashmap to store all addresses
106 struct GNUNET_CONTAINER_MultiPeerMap *addresses;
111 struct GNUNET_ATS_PluginEnvironment env;
114 * Array for results for each iteration with length iterations
116 struct Iteration *iterations_results;
119 * Array to store averaged full solution result with length #peers
121 struct Result *averaged_full_result;
124 * Array to store averaged updated solution result with length #peers
126 struct Result *averaged_update_result;
131 struct Result *current_result;
134 * Current number of peers benchmarked
139 * Current number of addresses benchmarked
144 * Solver description as string
149 * Configured ATS solver
154 * #peers to start benchmarking with
159 * #peers to end benchmarking with
164 * #addresses to benchmarking with
169 * Percentage of peers to update
171 int opt_update_percent;
174 * Create gnuplot file
184 * Number of iterations
191 int current_iteration;
194 * Is a bulk operation running?
199 * Is a bulk operation running?
201 int expecting_solution;
205 * Data structure to store results for a single iteration
210 * Head of the linked list
212 struct Result *result_head;
215 * Tail of the linked list
217 struct Result *result_tail;
222 * Result for a solver calculcation
227 * Previous element in the linked list
232 * Next element in the linked list
237 * Number of peers this solution included
242 * Number of addresses per peer this solution included
247 * Is this an update or a full solution
252 * Was the solution valid or did the solver fail
257 * Result of the solver
259 enum GAS_Solver_Additional_Information info;
262 * Duration of setting up the problem in the solver
264 struct GNUNET_TIME_Relative d_setup;
267 * Duration of solving the LP problem in the solver
270 struct GNUNET_TIME_Relative d_lp;
273 * Duration of solving the MLP problem in the solver
276 struct GNUNET_TIME_Relative d_mlp;
279 * Duration of solving whole problem in the solver
281 struct GNUNET_TIME_Relative d_total;
284 * Start time of setting up the problem in the solver
286 struct GNUNET_TIME_Absolute s_setup;
289 * Start time of solving the LP problem in the solver
292 struct GNUNET_TIME_Absolute s_lp;
295 * Start time of solving the MLP problem in the solver
298 struct GNUNET_TIME_Absolute s_mlp;
301 * Start time of solving whole problem in the solver
303 struct GNUNET_TIME_Absolute s_total;
306 * End time of setting up the problem in the solver
308 struct GNUNET_TIME_Absolute e_setup;
311 * End time of solving the LP problem in the solver
314 struct GNUNET_TIME_Absolute e_lp;
317 * End time of solving the MLP problem in the solver
320 struct GNUNET_TIME_Absolute e_mlp;
323 * End time of solving whole problem in the solver
325 struct GNUNET_TIME_Absolute e_total;
329 * Peer used for the benchmarking
336 struct GNUNET_PeerIdentity id;
339 * Head of linked list of addresses used with this peer
341 struct ATS_Address *head;
344 * Head of linked list of addresses used with this peer
346 struct ATS_Address *tail;
351 * ATS performance handle
353 static struct PerfHandle ph;
369 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
373 GNUNET_free_non_null (ph.peers);
374 GNUNET_free_non_null (ph.iterations_results);
375 GNUNET_free_non_null (ph.averaged_full_result);
376 GNUNET_free_non_null (ph.averaged_update_result);
378 GAS_normalization_stop ();
384 * Create a peer used for benchmarking
386 * @param cp the number of the peer
389 perf_create_peer (int cp)
392 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
393 &ph.peers[cp].id, sizeof (struct GNUNET_PeerIdentity));
394 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp,
395 GNUNET_i2s (&ph.peers[cp].id));
400 * Perform an update for an address
402 * @param cur the address to update
405 perf_update_address (struct ATS_Address *cur)
410 r_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2);
414 r_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
415 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
416 "Updating peer `%s' address %p type %s val %u\n",
417 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DELAY", r_val);
418 ph.env.sf.s_address_update_property (ph.solver, cur,
419 GNUNET_ATS_QUALITY_NET_DELAY,
420 r_val, (double) (100 + r_val / 100));
423 r_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10);
425 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
426 "Updating peer `%s' address %p type %s val %u\n",
427 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE", r_val);
428 ph.env.sf.s_address_update_property (ph.solver, cur,
429 GNUNET_ATS_QUALITY_NET_DISTANCE,
430 r_val, (double) (100 + r_val) / 100);
435 ph.env.sf.s_address_update_inuse (ph.solver, cur, GNUNET_YES);
440 bandwidth_changed_cb (void *cls,
441 struct ATS_Address *address)
443 if ( (0 == ntohl (address->assigned_bw_out.value__)) &&
444 (0 == ntohl (address->assigned_bw_in.value__)) )
447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
448 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
449 GNUNET_i2s (&address->peer),
451 (unsigned int) ntohl (address->assigned_bw_out.value__),
452 (unsigned int) ntohl (address->assigned_bw_in.value__));
453 if (GNUNET_YES == ph.bulk_running)
460 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
462 return GAS_normalization_get_preferences_by_peer (id);
467 get_property_cb (void *cls, const struct ATS_Address *address)
469 return GAS_normalization_get_properties ((struct ATS_Address *) address);
473 normalized_property_changed_cb (void *cls, struct ATS_Address *peer,
474 uint32_t type, double prop_rel)
480 perf_address_initial_update (void *solver,
481 struct GNUNET_CONTAINER_MultiPeerMap * addresses,
482 struct ATS_Address *address)
484 ph.env.sf.s_address_update_property (solver, address, GNUNET_ATS_QUALITY_NET_DELAY,
486 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100))
489 ph.env.sf.s_address_update_property (solver, address,
490 GNUNET_ATS_QUALITY_NET_DISTANCE, 10,
491 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100))
496 * Update a certain percentage of peers
498 * @param cp the current number of peers
499 * @param ca the current number of addresses
500 * @param percentage_peers the percentage of peers to update
504 perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percentage_peers)
506 struct ATS_Address *cur_address;
515 count = cp * ((double) percentage_peers / 100);
516 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
517 "Updating %u of %u peers \n", count, cp);
519 for (c_peer = 0; c_peer < cp; c_peer++)
524 while (c_select < count)
526 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, cp);
530 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
531 "Updating peer [%u] \n", r);
535 for (c_cur_p = 0; c_cur_p < cp; c_cur_p++)
539 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca);
540 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
541 "Updating peer [%u] address [%u]\n", c_cur_p, r);
544 for (cur_address = ph.peers[c_cur_p].head; NULL != cur_address; cur_address = cur_address->next)
547 perf_update_address (cur_address);
555 * Create an address for a peer
557 * @param cp index of the peer
558 * @param ca index of the address
559 * @return the address
561 static struct ATS_Address *
562 perf_create_address (int cp, int ca)
564 struct ATS_Address *a;
565 a = create_address (&ph.peers[cp].id,
566 "Test 1", "test 1", strlen ("test 1") + 1, 0);
567 GNUNET_CONTAINER_DLL_insert (ph.peers[cp].head, ph.peers[cp].tail, a);
568 GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a,
569 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
575 * Information callback for the solver
577 * @param op the solver operation
578 * @param stat status of the solver operation
579 * @param add additional solver information
582 solver_info_cb (void *cls,
583 enum GAS_Solver_Operation op,
584 enum GAS_Solver_Status stat,
585 enum GAS_Solver_Additional_Information add)
590 add_info = "GAS_INFO_NONE";
593 add_info = "GAS_INFO_MLP_FULL";
595 case GAS_INFO_UPDATED:
596 add_info = "GAS_INFO_MLP_UPDATED";
598 case GAS_INFO_PROP_ALL:
599 add_info = "GAS_INFO_PROP_ALL";
601 case GAS_INFO_PROP_SINGLE:
602 add_info = "GAS_INFO_PROP_SINGLE";
605 add_info = "INVALID";
612 case GAS_OP_SOLVE_START:
613 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
614 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
615 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
616 if (GNUNET_NO == ph.expecting_solution)
618 /* We do not expect a solution at the moment */
623 if ((GAS_STAT_SUCCESS == stat) && (NULL == ph.current_result))
625 /* Create new result */
626 tmp = GNUNET_new (struct Result);
627 ph.current_result = tmp;
628 GNUNET_CONTAINER_DLL_insert_tail(ph.iterations_results[ph.current_iteration-1].result_head,
629 ph.iterations_results[ph.current_iteration-1].result_tail, tmp);
630 ph.current_result->addresses = ph.current_a;
631 ph.current_result->peers = ph.current_p;
632 ph.current_result->s_total = GNUNET_TIME_absolute_get();
633 ph.current_result->d_total = GNUNET_TIME_UNIT_FOREVER_REL;
634 ph.current_result->d_setup = GNUNET_TIME_UNIT_FOREVER_REL;
635 ph.current_result->d_lp = GNUNET_TIME_UNIT_FOREVER_REL;
636 ph.current_result->d_mlp = GNUNET_TIME_UNIT_FOREVER_REL;
637 ph.current_result->info = add;
638 if (add == GAS_INFO_UPDATED)
639 ph.current_result->update = GNUNET_YES;
641 ph.current_result->update = GNUNET_NO;
644 case GAS_OP_SOLVE_STOP:
645 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
646 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
647 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
648 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
650 /* We do not expect a solution at the moment */
655 if (GAS_STAT_SUCCESS == stat)
656 ph.current_result->valid = GNUNET_YES;
658 ph.current_result->valid = GNUNET_NO;
660 if (NULL != ph.current_result)
662 /* Finalize result */
663 ph.current_result->e_total = GNUNET_TIME_absolute_get ();
664 ph.current_result->d_total = GNUNET_TIME_absolute_get_difference (
665 ph.current_result->s_total, ph.current_result->e_total);
667 ph.current_result = NULL;
670 case GAS_OP_SOLVE_SETUP_START:
671 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
672 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
673 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
674 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
680 if (GAS_STAT_SUCCESS == stat)
681 ph.current_result->valid = GNUNET_YES;
683 ph.current_result->valid = GNUNET_NO;
685 ph.current_result->s_setup = GNUNET_TIME_absolute_get ();
688 case GAS_OP_SOLVE_SETUP_STOP:
689 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
690 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
691 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
692 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
698 if (GAS_STAT_SUCCESS == stat)
699 ph.current_result->valid = GNUNET_YES;
701 ph.current_result->valid = GNUNET_NO;
703 ph.current_result->e_setup = GNUNET_TIME_absolute_get ();
704 ph.current_result->d_setup = GNUNET_TIME_absolute_get_difference (
705 ph.current_result->s_setup, ph.current_result->e_setup);
708 case GAS_OP_SOLVE_MLP_LP_START:
709 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
710 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
711 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
712 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
718 if (GAS_STAT_SUCCESS == stat)
719 ph.current_result->valid = GNUNET_YES;
721 ph.current_result->valid = GNUNET_NO;
723 ph.current_result->s_lp = GNUNET_TIME_absolute_get ();
725 case GAS_OP_SOLVE_MLP_LP_STOP:
726 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
727 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
728 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
729 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
735 if (GAS_STAT_SUCCESS == stat)
736 ph.current_result->valid = GNUNET_YES;
738 ph.current_result->valid = GNUNET_NO;
740 ph.current_result->e_lp = GNUNET_TIME_absolute_get ();
741 ph.current_result->d_lp = GNUNET_TIME_absolute_get_difference (
742 ph.current_result->s_lp, ph.current_result->e_lp);
745 case GAS_OP_SOLVE_MLP_MLP_START:
746 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
747 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
748 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
749 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
755 if (GAS_STAT_SUCCESS == stat)
756 ph.current_result->valid = GNUNET_YES;
758 ph.current_result->valid = GNUNET_NO;
760 ph.current_result->s_mlp = GNUNET_TIME_absolute_get ();
762 case GAS_OP_SOLVE_MLP_MLP_STOP:
763 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
764 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
765 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
766 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
772 if (GAS_STAT_SUCCESS == stat)
773 ph.current_result->valid = GNUNET_YES;
775 ph.current_result->valid = GNUNET_NO;
777 ph.current_result->e_mlp = GNUNET_TIME_absolute_get ();
778 ph.current_result->d_mlp = GNUNET_TIME_absolute_get_difference (
779 ph.current_result->s_mlp, ph.current_result->e_mlp);
781 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
782 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
783 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
784 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
786 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
787 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
788 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
789 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
790 if (GAS_STAT_SUCCESS != stat)
792 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
793 "Solver `%s' failed to update problem with %u peers and %u address!\n",
794 ph.ats_string, ph.current_p, ph.current_a);
804 write_gnuplot_script (char * data_fn, int iteration, int full)
806 struct GNUNET_DISK_FileHandle *f;
813 switch (ph.ats_mode) {
814 case MODE_PROPORTIONAL:
815 if (GNUNET_YES == full)
816 template = GNUPLOT_PROP_TEMPLATE;
818 template = GNUPLOT_PROP_UPDATE_TEMPLATE;
821 if (GNUNET_YES == full)
822 template = GNUPLOT_MLP_TEMPLATE;
824 template = GNUPLOT_MLP_UPDATE_TEMPLATE;
827 if (GNUNET_YES == full)
828 template = GNUPLOT_RIL_TEMPLATE;
830 template = GNUPLOT_RIL_UPDATE_TEMPLATE;
837 GNUNET_asprintf (&iter_text, "%s_%u", "avg",ph.iterations);
839 GNUNET_asprintf (&iter_text, "%u", iteration);
840 if (GNUNET_YES == full)
842 GNUNET_asprintf (&gfn, "perf_%s_full_%s-%u_%u_%u.gnuplot",
851 GNUNET_asprintf (&gfn, "perf_%s_updat_%s-%u_%u_%u.gnuplot",
858 GNUNET_free (iter_text);
860 f = GNUNET_DISK_file_open (gfn,
861 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
862 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
865 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
870 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, template, strlen(template)))
871 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
874 if (MODE_PROPORTIONAL == ph.ats_mode)
876 GNUNET_asprintf (&data, "plot '%s' using 1:%u with lines title 'Total time to solve'\n" \
880 else if (MODE_MLP == ph.ats_mode)
882 GNUNET_asprintf (&data, "plot '%s' using 1:%u with lines title 'Total time to solve',\\\n" \
883 "'%s' using 1:%u with lines title 'Time to setup',\\\n"
884 "'%s' using 1:%u with lines title 'Time to solve LP',\\\n"
885 "'%s' using 1:%u with lines title 'Total time to solve MLP'\n" \
892 else if (MODE_RIL == ph.ats_mode)
894 GNUNET_asprintf (&data,
895 "plot '%s' using 1:%u with lines title 'Total time to solve'\n" \
900 if ((NULL != data) &&
901 (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen(data))))
902 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
903 "Cannot write data to plot file `%s'\n",
905 GNUNET_free_non_null (data);
907 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
908 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
909 "Cannot close gnuplot file `%s'\n",
912 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
913 "Data successfully written to plot file `%s'\n",
920 * Evaluate results for a specific iteration
922 * @param iteration the iteration to evaluate
925 evaluate (int iteration)
927 struct GNUNET_DISK_FileHandle *f_full;
928 struct GNUNET_DISK_FileHandle *f_update;
930 char * data_fn_update;
934 struct Result *cur_res;
949 GNUNET_asprintf (&iter_text, "%s", "avg");
951 GNUNET_asprintf (&iter_text, "%u", iteration);
952 GNUNET_asprintf (&data_fn_full,
953 "perf_%s_full_%s_%u_%u_%u.data",
959 GNUNET_free (iter_text);
960 f_full = GNUNET_DISK_file_open (data_fn_full,
961 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
962 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
965 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
966 "Cannot open gnuplot file `%s'\n",
968 GNUNET_free (data_fn_full);
971 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
972 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_full, data, strlen(data)))
973 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
974 "Cannot write data to log file `%s'\n",
976 write_gnuplot_script (data_fn_full, iteration, GNUNET_YES);
979 data_fn_update = NULL;
980 if ((ph.create_plot) && (GNUNET_YES == ph.measure_updates))
983 GNUNET_asprintf (&iter_text, "%s", "avg");
985 GNUNET_asprintf (&iter_text, "%u", iteration);
986 GNUNET_asprintf (&data_fn_update, "perf_%s_update_i%u_%u_%u_%u.data",
992 GNUNET_free (iter_text);
993 f_update = GNUNET_DISK_file_open (data_fn_update,
994 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
995 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
996 if (NULL == f_update)
998 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
999 "Cannot open gnuplot file `%s'\n", data_fn_update);
1000 GNUNET_free (data_fn_update);
1002 GNUNET_DISK_file_close (f_full);
1003 GNUNET_free (data_fn_full);
1006 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
1007 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data)))
1008 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1009 "Cannot write data to log file `%s'\n",
1011 write_gnuplot_script (data_fn_update, iteration, GNUNET_NO);
1014 next = ph.iterations_results[ph.current_iteration -1].result_head;
1015 while (NULL != (cur = next))
1024 if (GNUNET_NO == cur->update)
1025 cur_res = &ph.averaged_full_result[cur->peers - ph.N_peers_start];
1027 cur_res = &ph.averaged_update_result[cur->peers - ph.N_peers_start];
1029 cur_res->peers = cur->peers;
1030 cur_res->addresses = cur->addresses;
1031 cur_res->update = cur->update;
1033 if (GNUNET_NO == cur->valid)
1036 "Total time to solve %s for %u peers %u addresses: %s\n",
1037 (GNUNET_YES == cur->update) ? "updated" : "full",
1038 cur->peers, cur->addresses, "Failed to solve!");
1044 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_total.rel_value_us)
1046 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == cur_res->d_total.rel_value_us)
1047 cur_res->d_total.rel_value_us = 0;
1048 if (GNUNET_YES == cur->valid)
1049 cur_res->d_total.rel_value_us += cur->d_total.rel_value_us;
1051 "Total time to solve %s for %u peers %u addresses: %llu us\n",
1052 (GNUNET_YES == cur->update) ? "updated" : "full",
1053 cur->peers, cur->addresses, (unsigned long long) cur->d_total.rel_value_us);
1054 GNUNET_asprintf(&str_d_total,
1056 (unsigned long long) cur->d_total.rel_value_us);
1059 GNUNET_asprintf(&str_d_total, "-1");
1060 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_setup.rel_value_us)
1062 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == cur_res->d_setup.rel_value_us)
1063 cur_res->d_setup.rel_value_us = 0;
1064 if (GNUNET_YES == cur->valid)
1065 cur_res->d_setup.rel_value_us += cur->d_setup.rel_value_us;
1066 fprintf (stderr, "Total time to setup %s %u peers %u addresses: %llu us\n",
1067 (GNUNET_YES == cur->update) ? "updated" : "full",
1068 cur->peers, cur->addresses, (unsigned long long )cur->d_setup.rel_value_us);
1069 GNUNET_asprintf(&str_d_setup, "%llu", (unsigned long long )cur->d_setup.rel_value_us);
1072 GNUNET_asprintf(&str_d_setup, "-1");
1073 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_lp.rel_value_us)
1075 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == cur_res->d_lp.rel_value_us)
1076 cur_res->d_lp.rel_value_us = 0;
1077 if (GNUNET_YES == cur->valid)
1078 cur_res->d_lp.rel_value_us += cur->d_lp.rel_value_us;
1080 "Total time to solve %s LP for %u peers %u addresses: %llu us\n",
1081 (GNUNET_YES == cur->update) ? "updated" : "full",
1084 (unsigned long long )cur->d_lp.rel_value_us);
1085 GNUNET_asprintf (&str_d_lp,
1087 (unsigned long long )cur->d_lp.rel_value_us);
1090 GNUNET_asprintf (&str_d_lp, "-1");
1091 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_mlp.rel_value_us)
1093 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == cur_res->d_mlp.rel_value_us)
1094 cur_res->d_mlp.rel_value_us = 0;
1095 if (GNUNET_YES == cur->valid)
1096 cur_res->d_mlp.rel_value_us += cur->d_mlp.rel_value_us;
1098 fprintf (stderr, "Total time to solve %s MLP for %u peers %u addresses: %llu us\n",
1099 (GNUNET_YES == cur->update) ? "updated" : "full",
1100 cur->peers, cur->addresses, (unsigned long long )cur->d_mlp.rel_value_us);
1101 GNUNET_asprintf (&str_d_mlp,
1103 (unsigned long long )cur->d_mlp.rel_value_us);
1106 GNUNET_asprintf (&str_d_mlp, "-1");
1109 if (GNUNET_YES == ph.create_plot)
1112 GNUNET_asprintf (&data,
1113 "%u;%u;%s;%s;%s;%s\n",
1114 cur->peers, cur->addresses,
1119 if (cur->update == GNUNET_NO)
1121 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_full, data, strlen(data)))
1122 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1123 "Cannot write data to log file `%s'\n",
1126 if ((cur->update == GNUNET_YES) && (NULL != f_update))
1128 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data)))
1129 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1130 "Cannot write data to log file `%s'\n",
1135 GNUNET_free_non_null (str_d_total);
1136 GNUNET_free_non_null (str_d_setup);
1137 GNUNET_free_non_null (str_d_lp);
1138 GNUNET_free_non_null (str_d_mlp);
1140 GNUNET_CONTAINER_DLL_remove (ph.iterations_results[ph.current_iteration-1].result_head,
1141 ph.iterations_results[ph.current_iteration-1].result_tail, cur);
1145 if ((NULL != f_full) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_full)))
1146 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1148 GNUNET_free_non_null (data_fn_full);
1150 if ((NULL != f_update) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_update)))
1151 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1153 GNUNET_free_non_null (data_fn_update);
1157 * Evaluate average results for all iterations
1160 evaluate_average (void)
1164 struct GNUNET_DISK_FileHandle *f_full;
1165 struct GNUNET_DISK_FileHandle *f_update;
1166 char * data_fn_full;
1167 char * data_fn_update;
1177 data_fn_full = NULL;
1181 GNUNET_asprintf (&data_fn_full,
1182 "perf_%s_full_avg_%u-%u_%u_%u.data",
1188 f_full = GNUNET_DISK_file_open (data_fn_full,
1189 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
1190 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
1193 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1194 "Cannot open gnuplot file `%s'\n",
1196 GNUNET_free (data_fn_full);
1199 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
1200 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_full, data, strlen(data)))
1201 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1202 "Cannot write data to log file `%s'\n",
1204 write_gnuplot_script (data_fn_full, -1, GNUNET_YES);
1207 data_fn_update = NULL;
1208 if ((ph.create_plot) && (GNUNET_YES == ph.measure_updates))
1210 GNUNET_asprintf (&data_fn_update, "perf_%s_update_avg_%u-%u_%u_%u.data",
1216 f_update = GNUNET_DISK_file_open (data_fn_update,
1217 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
1218 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
1219 if (NULL == f_update)
1221 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1222 "Cannot open gnuplot file `%s'\n", data_fn_update);
1223 GNUNET_free (data_fn_update);
1225 GNUNET_DISK_file_close (f_full);
1226 GNUNET_free (data_fn_full);
1229 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
1230 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data)))
1231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1232 "Cannot write data to log file `%s'\n",
1234 write_gnuplot_script (data_fn_update, -1, GNUNET_NO);
1237 for (c = 0; c <= ph.N_peers_end - ph.N_peers_start; c++)
1239 struct Result *cur = &ph.averaged_full_result[c];
1246 if (0 >= cur->valid)
1249 "No valid results for %s for %u peers %u addresses!\n",
1250 (GNUNET_YES == cur->update) ? "updated" : "full",
1251 cur->peers, cur->addresses);
1255 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_total.rel_value_us)
1258 "Average total time from %u iterations to solve %s for %u peers %u addresses: %llu us\n",
1260 (GNUNET_YES == cur->update) ? "updated" : "full",
1261 cur->peers, cur->addresses,
1262 (unsigned long long) cur->d_total.rel_value_us / cur->valid);
1263 GNUNET_asprintf(&str_d_total, "%llu",
1264 (unsigned long long) cur->d_total.rel_value_us / cur->valid);
1267 GNUNET_asprintf (&str_d_total, "-1");
1269 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_setup.rel_value_us)
1272 "Average total time from %u iterations to setup for %u peers %u addresses: %llu us\n",
1273 cur->valid, cur->peers, cur->addresses,
1274 (unsigned long long) cur->d_setup.rel_value_us / cur->valid);
1275 GNUNET_asprintf(&str_d_setup, "%llu",
1276 (unsigned long long) cur->d_setup.rel_value_us / cur->valid);
1280 GNUNET_asprintf (&str_d_setup, "-1");
1282 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_lp.rel_value_us)
1285 "Average total time from %u iterations to solve lp %s for %u peers %u addresses: %llu us\n",
1287 (GNUNET_YES == cur->update) ? "updated" : "full",
1288 cur->peers, cur->addresses,
1289 (unsigned long long) cur->d_lp.rel_value_us / cur->valid);
1290 GNUNET_asprintf(&str_d_lp, "%llu",
1291 (unsigned long long) cur->d_lp.rel_value_us / ph.iterations);
1294 GNUNET_asprintf (&str_d_lp, "-1");
1296 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_mlp.rel_value_us)
1299 "Average total time from %u iterations to solve mlp %s for %u peers %u addresses: %llu us\n",
1301 (GNUNET_YES == cur->update) ? "updated" : "full",
1302 cur->peers, cur->addresses,
1303 (unsigned long long) cur->d_mlp.rel_value_us / cur->valid);
1304 GNUNET_asprintf(&str_d_mlp, "%llu",
1305 (unsigned long long) cur->d_mlp.rel_value_us / cur->valid);
1308 GNUNET_asprintf (&str_d_mlp, "-1");
1311 if (GNUNET_YES == ph.create_plot)
1313 GNUNET_asprintf (&data,
1314 "%u;%u;%s;%s;%s;%s\n",
1315 cur->peers, cur->addresses,
1320 if (cur->update == GNUNET_NO)
1322 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_full, data, strlen(data)))
1323 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1324 "Cannot write data to log file `%s'\n",
1327 if ((cur->update == GNUNET_YES) && (NULL != f_update))
1329 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data)))
1330 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1331 "Cannot write data to log file `%s'\n",
1337 GNUNET_free_non_null (str_d_total);
1338 GNUNET_free_non_null (str_d_setup);
1339 GNUNET_free_non_null (str_d_lp);
1340 GNUNET_free_non_null (str_d_mlp);
1343 if ((NULL != f_full) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_full)))
1344 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1346 GNUNET_free_non_null (data_fn_full);
1348 if ((NULL != f_update) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_update)))
1349 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1351 GNUNET_free_non_null (data_fn_update);
1355 * Run a performance iteration
1359 perf_run_iteration (void)
1361 struct ATS_Address *cur;
1362 struct ATS_Address *next;
1365 int count_p = ph.N_peers_end;
1366 int count_a = ph.N_address;
1367 struct ATS_Address * cur_addr;
1370 ph.peers = GNUNET_malloc ((count_p) * sizeof (struct PerfPeer));
1371 for (cp = 0; cp < count_p; cp++)
1372 perf_create_peer (cp);
1373 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1374 "Iteration %u of %u, added %u peers\n", ph.current_iteration, ph.iterations, cp);
1376 for (cp = 0; cp < count_p; cp++)
1378 if (GNUNET_NO == ph.bulk_running)
1380 ph.bulk_running = GNUNET_YES;
1381 ph.env.sf.s_bulk_start (ph.solver);
1383 ph.current_p = cp + 1;
1384 for (ca = 0; ca < count_a; ca++)
1386 cur_addr = perf_create_address (cp, ca);
1388 ph.env.sf.s_add (ph.solver, cur_addr, GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_ATS_NetworkTypeCount));
1389 ph.current_a = ca + 1;
1390 perf_address_initial_update (ph.solver, ph.addresses, cur_addr);
1391 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1392 "Adding address for peer %u address %u\n", cp, ca);
1394 /* Notify solver about request */
1395 ph.env.sf.s_get (ph.solver, &ph.peers[cp].id);
1397 if (cp + 1 >= ph.N_peers_start)
1399 /* Disable bulk to solve the problem */
1400 if (GNUNET_YES == ph.bulk_running)
1402 ph.expecting_solution = GNUNET_YES;
1403 ph.bulk_running = GNUNET_NO;
1404 ph.env.sf.s_bulk_stop (ph.solver);
1409 /* Problem is solved by the solver here due to unlocking */
1410 ph.expecting_solution = GNUNET_NO;
1412 /* Update the problem */
1413 if ((0 < ph.opt_update_percent) && (GNUNET_YES == ph.measure_updates))
1416 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1417 "Updating problem with %u peers and %u addresses\n", cp + 1, ca);
1419 ph.expecting_solution = GNUNET_YES;
1420 if (GNUNET_NO == ph.bulk_running)
1422 ph.bulk_running = GNUNET_YES;
1423 ph.env.sf.s_bulk_start (ph.solver);
1425 perf_update_all_addresses (cp + 1, ca, ph.opt_update_percent);
1426 ph.bulk_running = GNUNET_NO;
1427 ph.env.sf.s_bulk_stop (ph.solver);
1428 /* Problem is solved by the solver here due to unlocking */
1429 ph.expecting_solution = GNUNET_NO;
1431 GNUNET_assert (GNUNET_NO == ph.bulk_running);
1435 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1436 "Done, cleaning up addresses\n");
1437 if (GNUNET_NO == ph.bulk_running)
1439 ph.env.sf.s_bulk_start (ph.solver);
1440 ph.bulk_running = GNUNET_YES;
1443 for (cp = 0; cp < count_p; cp++)
1445 for (cur = ph.peers[cp].head; cur != NULL ; cur = next)
1447 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1448 "Deleting addresses for peer %u\n", cp);
1449 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (ph.addresses,
1450 &ph.peers[cp].id, cur));
1451 ph.env.sf.s_del (ph.solver, cur, GNUNET_NO);
1453 GNUNET_CONTAINER_DLL_remove(ph.peers[cp].head, ph.peers[cp].tail, cur);
1458 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1459 "Iteration done\n");
1460 GNUNET_free(ph.peers);
1465 run (void *cls, char * const *args, const char *cfgfile,
1466 const struct GNUNET_CONFIGURATION_Handle *cfg)
1468 GNUNET_log_setup ("perf-ats-solver", "WARNING", NULL);
1470 char *src_filename = GNUNET_strdup (__FILE__);
1471 char *test_filename = cls;
1474 struct GNUNET_CONFIGURATION_Handle *solver_cfg;
1475 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
1476 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
1479 /* Extract test name */
1480 if (NULL == (sep = (strstr (src_filename,".c"))))
1482 GNUNET_free (src_filename);
1489 if (NULL != (sep = strstr (test_filename, ".exe")))
1492 if (NULL == (solver = strstr (test_filename, src_filename)))
1494 GNUNET_free (src_filename);
1499 solver += strlen (src_filename) +1;
1501 if (0 == strcmp(solver, "proportional"))
1503 ph.ats_mode = MODE_PROPORTIONAL;
1504 ph.ats_string = "proportional";
1506 else if (0 == strcmp(solver, "mlp"))
1508 ph.ats_mode = MODE_MLP;
1509 ph.ats_string = "mlp";
1511 else if ((0 == strcmp(solver, "ril")))
1513 ph.ats_mode = MODE_RIL;
1514 ph.ats_string = "ril";
1518 GNUNET_free (src_filename);
1523 GNUNET_free (src_filename);
1525 /* Calculcate peers */
1526 if ((0 == ph.N_peers_start) && (0 == ph.N_peers_end))
1528 ph.N_peers_start = DEFAULT_PEERS_START;
1529 ph.N_peers_end = DEFAULT_PEERS_END;
1531 if (0 == ph.N_address)
1532 ph.N_address = DEFAULT_ADDRESSES;
1534 if (ph.N_peers_start != ph.N_peers_end)
1535 fprintf (stderr, "Benchmarking solver `%s' with %u to %u peers and %u addresses in %u iterations\n",
1536 ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address, ph.iterations);
1538 fprintf (stderr, "Benchmarking solver `%s' with %u peers and %u addresses in %u iterations\n",
1539 ph.ats_string, ph.N_peers_end, ph.N_address, ph.iterations);
1541 if (0 == ph.opt_update_percent)
1542 ph.opt_update_percent = DEFAULT_UPDATE_PERCENTAGE;
1545 solver_cfg = GNUNET_CONFIGURATION_create();
1546 if ((NULL == solver_cfg) || (GNUNET_SYSERR == (GNUNET_CONFIGURATION_load ( solver_cfg, "perf_ats_solver.conf"))))
1552 if (GNUNET_ATS_NetworkTypeCount != load_quotas (solver_cfg,
1553 quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount))
1560 /* Create array of DLL to store results for iterations */
1561 ph.iterations_results = GNUNET_malloc (sizeof (struct Iteration) * ph.iterations);
1562 ph.averaged_full_result = GNUNET_malloc (sizeof (struct Result) * ((ph.N_peers_end + 1) - ph.N_peers_start));
1563 ph.averaged_update_result = GNUNET_malloc (sizeof (struct Result) * ((ph.N_peers_end + 1) - ph.N_peers_start));
1564 for (c = 0; c <= ph.N_peers_end - ph.N_peers_start; c++)
1566 ph.averaged_full_result[c].d_setup = GNUNET_TIME_UNIT_FOREVER_REL;
1567 ph.averaged_full_result[c].d_total = GNUNET_TIME_UNIT_FOREVER_REL;
1568 ph.averaged_full_result[c].d_lp = GNUNET_TIME_UNIT_FOREVER_REL;
1569 ph.averaged_full_result[c].d_mlp = GNUNET_TIME_UNIT_FOREVER_REL;
1573 ph.env.cfg = solver_cfg;
1574 ph.stat = GNUNET_STATISTICS_create ("ats", cfg);
1575 ph.env.stats = ph.stat;
1576 ph.addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
1577 ph.env.addresses = ph.addresses;
1578 ph.env.bandwidth_changed_cb = bandwidth_changed_cb;
1579 ph.env.get_preferences = &get_preferences_cb;
1580 ph.env.get_property = &get_property_cb;
1581 ph.env.network_count = GNUNET_ATS_NetworkTypeCount;
1582 ph.env.info_cb = &solver_info_cb;
1583 ph.env.info_cb_cls = NULL;
1585 int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
1586 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
1588 ph.env.networks[c] = networks[c];
1589 ph.env.out_quota[c] = quotas_out[c];
1590 ph.env.in_quota[c] = quotas_in[c];
1591 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loading network quotas: `%s' %llu %llu \n",
1592 GNUNET_ATS_print_network_type(ph.env.networks[c]),
1593 ph.env.out_quota[c],
1594 ph.env.in_quota[c]);
1596 GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL );
1598 GNUNET_asprintf (&plugin, "libgnunet_plugin_ats_%s", ph.ats_string);
1599 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initializing solver `%s'\n"), ph.ats_string);
1600 if (NULL == (ph.solver = GNUNET_PLUGIN_load (plugin, &ph.env)))
1602 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver `%s'!\n"), plugin);
1607 /* Do the benchmark */
1608 for (ph.current_iteration = 1; ph.current_iteration <= ph.iterations; ph.current_iteration++)
1610 perf_run_iteration ();
1611 evaluate (ph.current_iteration);
1613 evaluate_average ();
1616 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Unloading solver `%s'\n"), ph.ats_string);
1617 GNUNET_PLUGIN_unload (plugin, ph.solver);
1618 GNUNET_free (plugin);
1619 GNUNET_free (ph.iterations_results);
1620 GNUNET_free (ph.averaged_full_result);
1621 GNUNET_free (ph.averaged_update_result);
1622 GNUNET_CONFIGURATION_destroy (solver_cfg);
1623 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
1628 * Main function of the benchmark
1630 * @param argc argument count
1631 * @param argv argument values
1634 main (int argc, char *argv[])
1636 /* extract command line arguments */
1637 ph.opt_update_percent = 0;
1638 ph.N_peers_start = 0;
1641 ph.ats_string = NULL;
1642 ph.create_plot = GNUNET_NO;
1643 ph.measure_updates = GNUNET_NO;
1646 static struct GNUNET_GETOPT_CommandLineOption options[] = {
1647 { 'a', "addresses", NULL,
1648 gettext_noop ("addresses to use"),
1649 1, &GNUNET_GETOPT_set_uint, &ph.N_address },
1650 { 's', "start", NULL,
1651 gettext_noop ("start with peer"),
1652 1, &GNUNET_GETOPT_set_uint, &ph.N_peers_start },
1654 gettext_noop ("end with peer"),
1655 1, &GNUNET_GETOPT_set_uint, &ph.N_peers_end },
1656 { 'i', "iterations", NULL,
1657 gettext_noop ("number of iterations used for averaging (default: 1)"),
1658 1, &GNUNET_GETOPT_set_uint, &ph.iterations },
1659 { 'p', "percentage", NULL,
1660 gettext_noop ("update a fix percentage of addresses"),
1661 1, &GNUNET_GETOPT_set_uint, &ph.opt_update_percent },
1662 { 'g', "gnuplot", NULL,
1663 gettext_noop ("create GNUplot file"),
1664 0, &GNUNET_GETOPT_set_one, &ph.create_plot},
1665 { 'u', "update", NULL,
1666 gettext_noop ("measure updates"),
1667 0, &GNUNET_GETOPT_set_one, &ph.measure_updates},
1668 GNUNET_GETOPT_OPTION_END
1671 GNUNET_PROGRAM_run (argc, argv, argv[0], NULL, options, &run, argv[0]);
1675 /* end of file perf_ats_solver.c */