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
186 int total_iterations;
191 int current_iteration;
194 * Is a bulk operation running?
199 * Is a bulk operation running?
201 int expecting_solution;
204 * Was the problem just updates?
206 int performed_update;
210 * Data structure to store results for a single iteration
215 * Head of the linked list
217 struct Result *result_head;
220 * Tail of the linked list
222 struct Result *result_tail;
227 * Result for a solver calculcation
232 * Previous element in the linked list
237 * Next element in the linked list
242 * Number of peers this solution included
247 * Number of addresses per peer this solution included
252 * Is this an update or a full solution
257 * Was the solution valid or did the solver fail
262 * Result of the solver
264 enum GAS_Solver_Additional_Information info;
267 * Duration of setting up the problem in the solver
269 struct GNUNET_TIME_Relative d_setup;
272 * Duration of solving the LP problem in the solver
275 struct GNUNET_TIME_Relative d_lp;
278 * Duration of solving the MLP problem in the solver
281 struct GNUNET_TIME_Relative d_mlp;
284 * Duration of solving whole problem in the solver
286 struct GNUNET_TIME_Relative d_total;
289 * Start time of setting up the problem in the solver
291 struct GNUNET_TIME_Absolute s_setup;
294 * Start time of solving the LP problem in the solver
297 struct GNUNET_TIME_Absolute s_lp;
300 * Start time of solving the MLP problem in the solver
303 struct GNUNET_TIME_Absolute s_mlp;
306 * Start time of solving whole problem in the solver
308 struct GNUNET_TIME_Absolute s_total;
311 * End time of setting up the problem in the solver
313 struct GNUNET_TIME_Absolute e_setup;
316 * End time of solving the LP problem in the solver
319 struct GNUNET_TIME_Absolute e_lp;
322 * End time of solving the MLP problem in the solver
325 struct GNUNET_TIME_Absolute e_mlp;
328 * End time of solving whole problem in the solver
330 struct GNUNET_TIME_Absolute e_total;
334 * Peer used for the benchmarking
341 struct GNUNET_PeerIdentity id;
344 * Head of linked list of addresses used with this peer
346 struct ATS_Address *head;
349 * Head of linked list of addresses used with this peer
351 struct ATS_Address *tail;
356 * ATS performance handle
358 static struct PerfHandle ph;
374 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
378 GNUNET_free_non_null (ph.peers);
379 GNUNET_free_non_null (ph.iterations_results);
380 GNUNET_free_non_null (ph.averaged_full_result);
381 GNUNET_free_non_null (ph.averaged_update_result);
383 GAS_normalization_stop ();
389 * Create a peer used for benchmarking
391 * @param cp the number of the peer
394 perf_create_peer (int cp)
397 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
398 &ph.peers[cp].id, sizeof (struct GNUNET_PeerIdentity));
399 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp,
400 GNUNET_i2s (&ph.peers[cp].id));
405 * Perform an update for an address
407 * @param cur the address to update
410 perf_update_address (struct ATS_Address *cur)
415 r_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2);
419 r_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
420 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
421 "Updating peer `%s' address %p type %s val %u\n",
422 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DELAY", r_val);
423 ph.env.sf.s_address_update_property (ph.solver, cur,
424 GNUNET_ATS_QUALITY_NET_DELAY,
425 r_val, (double) (100 + r_val / 100));
428 r_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10);
430 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
431 "Updating peer `%s' address %p type %s val %u\n",
432 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE", r_val);
433 ph.env.sf.s_address_update_property (ph.solver, cur,
434 GNUNET_ATS_QUALITY_NET_DISTANCE,
435 r_val, (double) (100 + r_val) / 100);
440 ph.env.sf.s_address_update_inuse (ph.solver, cur, GNUNET_YES);
445 bandwidth_changed_cb (void *cls,
446 struct ATS_Address *address)
448 if ( (0 == ntohl (address->assigned_bw_out.value__)) &&
449 (0 == ntohl (address->assigned_bw_in.value__)) )
452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
453 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
454 GNUNET_i2s (&address->peer),
456 (unsigned int) ntohl (address->assigned_bw_out.value__),
457 (unsigned int) ntohl (address->assigned_bw_in.value__));
458 if (GNUNET_YES == ph.bulk_running)
465 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
467 return GAS_normalization_get_preferences_by_peer (id);
472 get_property_cb (void *cls, const struct ATS_Address *address)
474 return GAS_normalization_get_properties ((struct ATS_Address *) address);
478 normalized_property_changed_cb (void *cls, struct ATS_Address *peer,
479 uint32_t type, double prop_rel)
485 perf_address_initial_update (void *solver,
486 struct GNUNET_CONTAINER_MultiPeerMap * addresses,
487 struct ATS_Address *address)
489 ph.env.sf.s_address_update_property (solver, address, GNUNET_ATS_QUALITY_NET_DELAY,
491 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100))
494 ph.env.sf.s_address_update_property (solver, address,
495 GNUNET_ATS_QUALITY_NET_DISTANCE, 10,
496 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100))
501 * Update a certain percentage of peers
503 * @param cp the current number of peers
504 * @param ca the current number of addresses
505 * @param percentage_peers the percentage of peers to update
509 perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percentage_peers)
511 struct ATS_Address *cur_address;
520 count = cp * ((double) percentage_peers / 100);
521 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
522 "Updating %u of %u peers \n", count, cp);
524 for (c_peer = 0; c_peer < cp; c_peer++)
529 while (c_select < count)
531 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, cp);
535 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
536 "Updating peer [%u] \n", r);
540 for (c_cur_p = 0; c_cur_p < cp; c_cur_p++)
544 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca);
545 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
546 "Updating peer [%u] address [%u]\n", c_cur_p, r);
549 for (cur_address = ph.peers[c_cur_p].head; NULL != cur_address; cur_address = cur_address->next)
552 perf_update_address (cur_address);
560 * Create an address for a peer
562 * @param cp index of the peer
563 * @param ca index of the address
564 * @return the address
566 static struct ATS_Address *
567 perf_create_address (int cp, int ca)
569 struct ATS_Address *a;
570 a = create_address (&ph.peers[cp].id,
571 "Test 1", "test 1", strlen ("test 1") + 1, 0);
572 GNUNET_CONTAINER_DLL_insert (ph.peers[cp].head, ph.peers[cp].tail, a);
573 GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a,
574 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
580 * Information callback for the solver
582 * @param op the solver operation
583 * @param stat status of the solver operation
584 * @param add additional solver information
587 solver_info_cb (void *cls,
588 enum GAS_Solver_Operation op,
589 enum GAS_Solver_Status stat,
590 enum GAS_Solver_Additional_Information add)
595 add_info = "GAS_INFO_NONE";
598 add_info = "GAS_INFO_MLP_FULL";
600 case GAS_INFO_UPDATED:
601 add_info = "GAS_INFO_MLP_UPDATED";
603 case GAS_INFO_PROP_ALL:
604 add_info = "GAS_INFO_PROP_ALL";
606 case GAS_INFO_PROP_SINGLE:
607 add_info = "GAS_INFO_PROP_SINGLE";
610 add_info = "INVALID";
617 case GAS_OP_SOLVE_START:
618 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
619 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
620 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
621 if (GNUNET_NO == ph.expecting_solution)
623 /* We do not expect a solution at the moment */
628 if ((GAS_STAT_SUCCESS == stat) && (NULL == ph.current_result))
630 /* Create new result */
631 tmp = GNUNET_new (struct Result);
632 ph.current_result = tmp;
633 GNUNET_CONTAINER_DLL_insert_tail(ph.iterations_results[ph.current_iteration-1].result_head,
634 ph.iterations_results[ph.current_iteration-1].result_tail, tmp);
635 ph.current_result->addresses = ph.current_a;
636 ph.current_result->peers = ph.current_p;
637 ph.current_result->s_total = GNUNET_TIME_absolute_get();
638 ph.current_result->d_total = GNUNET_TIME_UNIT_FOREVER_REL;
639 ph.current_result->d_setup = GNUNET_TIME_UNIT_FOREVER_REL;
640 ph.current_result->d_lp = GNUNET_TIME_UNIT_FOREVER_REL;
641 ph.current_result->d_mlp = GNUNET_TIME_UNIT_FOREVER_REL;
642 ph.current_result->info = add;
643 if ((add == GAS_INFO_UPDATED) || (GNUNET_YES == ph.performed_update))
645 ph.current_result->update = GNUNET_YES;
649 ph.current_result->update = GNUNET_NO;
654 case GAS_OP_SOLVE_STOP:
655 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
656 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
657 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
658 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
660 /* We do not expect a solution at the moment */
665 if (GAS_STAT_SUCCESS == stat)
666 ph.current_result->valid = GNUNET_YES;
668 ph.current_result->valid = GNUNET_NO;
670 if (NULL != ph.current_result)
672 /* Finalize result */
673 ph.current_result->e_total = GNUNET_TIME_absolute_get ();
674 ph.current_result->d_total = GNUNET_TIME_absolute_get_difference (
675 ph.current_result->s_total, ph.current_result->e_total);
677 ph.current_result = NULL;
680 case GAS_OP_SOLVE_SETUP_START:
681 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
682 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
683 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
684 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
690 if (GAS_STAT_SUCCESS == stat)
691 ph.current_result->valid = GNUNET_YES;
693 ph.current_result->valid = GNUNET_NO;
695 ph.current_result->s_setup = GNUNET_TIME_absolute_get ();
698 case GAS_OP_SOLVE_SETUP_STOP:
699 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
700 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
701 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
702 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
708 if (GAS_STAT_SUCCESS == stat)
709 ph.current_result->valid = GNUNET_YES;
711 ph.current_result->valid = GNUNET_NO;
713 ph.current_result->e_setup = GNUNET_TIME_absolute_get ();
714 ph.current_result->d_setup = GNUNET_TIME_absolute_get_difference (
715 ph.current_result->s_setup, ph.current_result->e_setup);
718 case GAS_OP_SOLVE_MLP_LP_START:
719 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
720 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
721 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
722 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
728 if (GAS_STAT_SUCCESS == stat)
729 ph.current_result->valid = GNUNET_YES;
731 ph.current_result->valid = GNUNET_NO;
733 ph.current_result->s_lp = GNUNET_TIME_absolute_get ();
735 case GAS_OP_SOLVE_MLP_LP_STOP:
736 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
737 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
738 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
739 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
745 if (GAS_STAT_SUCCESS == stat)
746 ph.current_result->valid = GNUNET_YES;
748 ph.current_result->valid = GNUNET_NO;
750 ph.current_result->e_lp = GNUNET_TIME_absolute_get ();
751 ph.current_result->d_lp = GNUNET_TIME_absolute_get_difference (
752 ph.current_result->s_lp, ph.current_result->e_lp);
755 case GAS_OP_SOLVE_MLP_MLP_START:
756 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
757 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
758 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
759 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
765 if (GAS_STAT_SUCCESS == stat)
766 ph.current_result->valid = GNUNET_YES;
768 ph.current_result->valid = GNUNET_NO;
770 ph.current_result->s_mlp = GNUNET_TIME_absolute_get ();
772 case GAS_OP_SOLVE_MLP_MLP_STOP:
773 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
774 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
775 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
776 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
782 if (GAS_STAT_SUCCESS == stat)
783 ph.current_result->valid = GNUNET_YES;
785 ph.current_result->valid = GNUNET_NO;
787 ph.current_result->e_mlp = GNUNET_TIME_absolute_get ();
788 ph.current_result->d_mlp = GNUNET_TIME_absolute_get_difference (
789 ph.current_result->s_mlp, ph.current_result->e_mlp);
791 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
792 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
793 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
794 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
796 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
797 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
798 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
799 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
800 if (GAS_STAT_SUCCESS != stat)
802 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
803 "Solver `%s' failed to update problem with %u peers and %u address!\n",
804 ph.ats_string, ph.current_p, ph.current_a);
814 write_gnuplot_script (char * data_fn, int iteration, int full)
816 struct GNUNET_DISK_FileHandle *f;
823 switch (ph.ats_mode) {
824 case MODE_PROPORTIONAL:
825 if (GNUNET_YES == full)
826 template = GNUPLOT_PROP_TEMPLATE;
828 template = GNUPLOT_PROP_UPDATE_TEMPLATE;
831 if (GNUNET_YES == full)
832 template = GNUPLOT_MLP_TEMPLATE;
834 template = GNUPLOT_MLP_UPDATE_TEMPLATE;
837 if (GNUNET_YES == full)
838 template = GNUPLOT_RIL_TEMPLATE;
840 template = GNUPLOT_RIL_UPDATE_TEMPLATE;
847 GNUNET_asprintf (&iter_text, "%s_%u", "avg",ph.total_iterations);
849 GNUNET_asprintf (&iter_text, "%u", iteration);
850 if (GNUNET_YES == full)
852 GNUNET_asprintf (&gfn, "perf_%s_full_%s-%u_%u_%u.gnuplot",
861 GNUNET_asprintf (&gfn, "perf_%s_updat_%s-%u_%u_%u.gnuplot",
868 GNUNET_free (iter_text);
870 f = GNUNET_DISK_file_open (gfn,
871 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
872 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
875 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
880 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, template, strlen(template)))
881 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
884 if (MODE_PROPORTIONAL == ph.ats_mode)
886 GNUNET_asprintf (&data, "plot '%s' using 1:%u with lines title 'Total time to solve'\n" \
890 else if (MODE_MLP == ph.ats_mode)
892 GNUNET_asprintf (&data, "plot '%s' using 1:%u with lines title 'Total time to solve',\\\n" \
893 "'%s' using 1:%u with lines title 'Time to setup',\\\n"
894 "'%s' using 1:%u with lines title 'Time to solve LP',\\\n"
895 "'%s' using 1:%u with lines title 'Total time to solve MLP'\n" \
902 else if (MODE_RIL == ph.ats_mode)
904 GNUNET_asprintf (&data,
905 "plot '%s' using 1:%u with lines title 'Total time to solve'\n" \
910 if ((NULL != data) &&
911 (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen(data))))
912 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
913 "Cannot write data to plot file `%s'\n",
915 GNUNET_free_non_null (data);
917 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
918 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
919 "Cannot close gnuplot file `%s'\n",
922 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
923 "Data successfully written to plot file `%s'\n",
930 * Evaluate results for a specific iteration
932 * @param iteration the iteration to evaluate
935 evaluate (int iteration)
937 struct GNUNET_DISK_FileHandle *f_full;
938 struct GNUNET_DISK_FileHandle *f_update;
940 char * data_fn_update;
944 struct Result *cur_res;
959 GNUNET_asprintf (&iter_text, "%s", "avg");
961 GNUNET_asprintf (&iter_text, "%u", iteration);
962 GNUNET_asprintf (&data_fn_full,
963 "perf_%s_full_%s_%u_%u_%u.data",
969 GNUNET_free (iter_text);
970 f_full = GNUNET_DISK_file_open (data_fn_full,
971 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
972 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
975 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
976 "Cannot open gnuplot file `%s'\n",
978 GNUNET_free (data_fn_full);
981 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
982 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_full, data, strlen(data)))
983 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
984 "Cannot write data to log file `%s'\n",
986 write_gnuplot_script (data_fn_full, iteration, GNUNET_YES);
989 data_fn_update = NULL;
990 if ((ph.create_plot) && (GNUNET_YES == ph.measure_updates))
993 GNUNET_asprintf (&iter_text, "%s", "avg");
995 GNUNET_asprintf (&iter_text, "%u", iteration);
996 GNUNET_asprintf (&data_fn_update, "perf_%s_update_i%u_%u_%u_%u.data",
1002 GNUNET_free (iter_text);
1003 f_update = GNUNET_DISK_file_open (data_fn_update,
1004 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
1005 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
1006 if (NULL == f_update)
1008 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1009 "Cannot open gnuplot file `%s'\n", data_fn_update);
1010 GNUNET_free (data_fn_update);
1012 GNUNET_DISK_file_close (f_full);
1013 GNUNET_free (data_fn_full);
1016 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
1017 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data)))
1018 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1019 "Cannot write data to log file `%s'\n",
1021 write_gnuplot_script (data_fn_update, iteration, GNUNET_NO);
1024 next = ph.iterations_results[ph.current_iteration -1].result_head;
1025 while (NULL != (cur = next))
1034 if (GNUNET_NO == cur->update)
1036 cur_res = &ph.averaged_full_result[cur->peers - ph.N_peers_start];
1040 cur_res = &ph.averaged_update_result[cur->peers - ph.N_peers_start];
1043 cur_res->peers = cur->peers;
1044 cur_res->addresses = cur->addresses;
1045 cur_res->update = cur->update;
1047 if (GNUNET_NO == cur->valid)
1050 "Total time to solve %s for %u peers %u addresses: %s\n",
1051 (GNUNET_YES == cur->update) ? "updated" : "full",
1052 cur->peers, cur->addresses, "Failed to solve!");
1058 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_total.rel_value_us)
1060 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == cur_res->d_total.rel_value_us)
1061 cur_res->d_total.rel_value_us = 0;
1062 if (GNUNET_YES == cur->valid)
1063 cur_res->d_total.rel_value_us += cur->d_total.rel_value_us;
1065 "Total time to solve %s for %u peers %u addresses: %llu us\n",
1066 (GNUNET_YES == cur->update) ? "updated" : "full",
1067 cur->peers, cur->addresses,
1068 (unsigned long long) cur->d_total.rel_value_us);
1069 GNUNET_asprintf(&str_d_total,
1070 "%llu", (unsigned long long) cur->d_total.rel_value_us);
1073 GNUNET_asprintf(&str_d_total, "-1");
1074 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_setup.rel_value_us)
1076 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == cur_res->d_setup.rel_value_us)
1077 cur_res->d_setup.rel_value_us = 0;
1078 if (GNUNET_YES == cur->valid)
1079 cur_res->d_setup.rel_value_us += cur->d_setup.rel_value_us;
1080 fprintf (stderr, "Total time to setup %s %u peers %u addresses: %llu us\n",
1081 (GNUNET_YES == cur->update) ? "updated" : "full",
1082 cur->peers, cur->addresses,
1083 (unsigned long long) cur->d_setup.rel_value_us);
1084 GNUNET_asprintf(&str_d_setup, "%llu",
1085 (unsigned long long )cur->d_setup.rel_value_us);
1088 GNUNET_asprintf(&str_d_setup, "-1");
1090 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_lp.rel_value_us)
1092 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == cur_res->d_lp.rel_value_us)
1093 cur_res->d_lp.rel_value_us = 0;
1094 if (GNUNET_YES == cur->valid)
1095 cur_res->d_lp.rel_value_us += cur->d_lp.rel_value_us;
1097 "Total time to solve %s LP for %u peers %u addresses: %llu us\n",
1098 (GNUNET_YES == cur->update) ? "updated" : "full",
1101 (unsigned long long )cur->d_lp.rel_value_us);
1102 GNUNET_asprintf (&str_d_lp,
1103 "%llu", (unsigned long long )cur->d_lp.rel_value_us);
1106 GNUNET_asprintf (&str_d_lp, "-1");
1108 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_mlp.rel_value_us)
1110 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == cur_res->d_mlp.rel_value_us)
1111 cur_res->d_mlp.rel_value_us = 0;
1112 if (GNUNET_YES == cur->valid)
1113 cur_res->d_mlp.rel_value_us += cur->d_mlp.rel_value_us;
1115 fprintf (stderr, "Total time to solve %s MLP for %u peers %u addresses: %llu us\n",
1116 (GNUNET_YES == cur->update) ? "updated" : "full",
1117 cur->peers, cur->addresses,
1118 (unsigned long long )cur->d_mlp.rel_value_us);
1119 GNUNET_asprintf (&str_d_mlp,
1120 "%llu", (unsigned long long )cur->d_mlp.rel_value_us);
1123 GNUNET_asprintf (&str_d_mlp, "-1");
1126 if (GNUNET_YES == ph.create_plot)
1129 GNUNET_asprintf (&data,
1130 "%u;%u;%s;%s;%s;%s\n",
1131 cur->peers, cur->addresses,
1136 if (cur->update == GNUNET_NO)
1138 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_full, data, strlen(data)))
1139 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1140 "Cannot write data to log file `%s'\n",
1143 if ((cur->update == GNUNET_YES) && (NULL != f_update))
1145 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data)))
1146 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1147 "Cannot write data to log file `%s'\n",
1152 GNUNET_free_non_null (str_d_total);
1153 GNUNET_free_non_null (str_d_setup);
1154 GNUNET_free_non_null (str_d_lp);
1155 GNUNET_free_non_null (str_d_mlp);
1157 GNUNET_CONTAINER_DLL_remove (ph.iterations_results[ph.current_iteration-1].result_head,
1158 ph.iterations_results[ph.current_iteration-1].result_tail, cur);
1162 if ((NULL != f_full) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_full)))
1163 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1165 GNUNET_free_non_null (data_fn_full);
1167 if ((NULL != f_update) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_update)))
1168 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1170 GNUNET_free_non_null (data_fn_update);
1174 * Evaluate average results for all iterations
1177 evaluate_average (void)
1182 struct GNUNET_DISK_FileHandle *f_full;
1183 struct GNUNET_DISK_FileHandle *f_update;
1185 char * data_fn_full;
1186 char * data_fn_update;
1196 data_fn_full = NULL;
1200 GNUNET_asprintf (&data_fn_full,
1201 "perf_%s_full_avg_%u-%u_%u_%u.data",
1203 ph.total_iterations,
1207 f_full = GNUNET_DISK_file_open (data_fn_full,
1208 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
1209 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
1212 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1213 "Cannot open gnuplot file `%s'\n",
1215 GNUNET_free (data_fn_full);
1218 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
1219 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_full, data, strlen(data)))
1220 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1221 "Cannot write data to log file `%s'\n",
1223 write_gnuplot_script (data_fn_full, -1, GNUNET_YES);
1226 data_fn_update = NULL;
1227 if ((ph.create_plot) && (GNUNET_YES == ph.measure_updates))
1229 GNUNET_asprintf (&data_fn_update, "perf_%s_update_avg_%u-%u_%u_%u.data",
1231 ph.total_iterations,
1235 f_update = GNUNET_DISK_file_open (data_fn_update,
1236 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
1237 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
1238 if (NULL == f_update)
1240 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1241 "Cannot open gnuplot file `%s'\n", data_fn_update);
1242 GNUNET_free (data_fn_update);
1244 GNUNET_DISK_file_close (f_full);
1245 GNUNET_free (data_fn_full);
1248 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
1249 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data)))
1250 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1251 "Cannot write data to log file `%s'\n",
1253 write_gnuplot_script (data_fn_update, -1, GNUNET_NO);
1256 for (c_o = 0; c_o < 2; c_o++)
1260 "Duration for a full solution averaged over %i iterations\n",
1261 ph.total_iterations);
1264 "Duration for a full solution averaged over %i iterations\n",
1265 ph.total_iterations);
1267 for (c_i = 0; c_i <= ph.N_peers_end - ph.N_peers_start; c_i++)
1271 cur = &ph.averaged_full_result[c_i];
1273 else if ((GNUNET_YES == ph.measure_updates) && (1 == c_o))
1275 cur = &ph.averaged_update_result[c_i];
1280 if (0 == cur->peers)
1288 if (0 >= cur->valid)
1291 "No valid results for %s for %u peers %u addresses!\n",
1292 (GNUNET_YES == cur->update) ? "updated" : "full",
1293 cur->peers, cur->addresses);
1297 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_total.rel_value_us)
1300 "Average total time from %u iterations to solve %s for %u peers %u addresses: %llu us\n",
1302 (GNUNET_YES == cur->update) ? "updated" : "full",
1303 cur->peers, cur->addresses,
1304 (unsigned long long) cur->d_total.rel_value_us / cur->valid);
1305 GNUNET_asprintf(&str_d_total, "%llu",
1306 (unsigned long long) cur->d_total.rel_value_us / cur->valid);
1309 GNUNET_asprintf (&str_d_total, "-1");
1311 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_setup.rel_value_us)
1314 "Average total time from %u iterations to setup for %u peers %u addresses: %llu us\n",
1315 cur->valid, cur->peers, cur->addresses,
1316 (unsigned long long) cur->d_setup.rel_value_us / cur->valid);
1317 GNUNET_asprintf(&str_d_setup, "%llu",
1318 (unsigned long long) cur->d_setup.rel_value_us / cur->valid);
1322 GNUNET_asprintf (&str_d_setup, "-1");
1324 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_lp.rel_value_us)
1327 "Average total time from %u iterations to solve lp %s for %u peers %u addresses: %llu us\n",
1329 (GNUNET_YES == cur->update) ? "updated" : "full",
1330 cur->peers, cur->addresses,
1331 (unsigned long long) cur->d_lp.rel_value_us / cur->valid);
1332 GNUNET_asprintf(&str_d_lp, "%llu",
1333 (unsigned long long) cur->d_lp.rel_value_us / ph.total_iterations);
1336 GNUNET_asprintf (&str_d_lp, "-1");
1338 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_mlp.rel_value_us)
1341 "Average total time from %u iterations to solve mlp %s for %u peers %u addresses: %llu us\n",
1343 (GNUNET_YES == cur->update) ? "updated" : "full",
1344 cur->peers, cur->addresses,
1345 (unsigned long long) cur->d_mlp.rel_value_us / cur->valid);
1346 GNUNET_asprintf(&str_d_mlp, "%llu",
1347 (unsigned long long) cur->d_mlp.rel_value_us / cur->valid);
1350 GNUNET_asprintf (&str_d_mlp, "-1");
1353 if (GNUNET_YES == ph.create_plot)
1355 GNUNET_asprintf (&data,
1356 "%u;%u;%s;%s;%s;%s\n",
1357 cur->peers, cur->addresses,
1362 if (cur->update == GNUNET_NO)
1364 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_full, data, strlen(data)))
1365 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1366 "Cannot write data to log file `%s'\n",
1369 if ((cur->update == GNUNET_YES) && (NULL != f_update))
1371 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data)))
1372 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1373 "Cannot write data to log file `%s'\n",
1379 GNUNET_free_non_null (str_d_total);
1380 GNUNET_free_non_null (str_d_setup);
1381 GNUNET_free_non_null (str_d_lp);
1382 GNUNET_free_non_null (str_d_mlp);
1386 if ((NULL != f_full) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_full)))
1387 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1389 GNUNET_free_non_null (data_fn_full);
1391 if ((NULL != f_update) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_update)))
1392 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1394 GNUNET_free_non_null (data_fn_update);
1398 * Run a performance iteration
1402 perf_run_iteration (void)
1404 struct ATS_Address *cur;
1405 struct ATS_Address *next;
1408 int count_p = ph.N_peers_end;
1409 int count_a = ph.N_address;
1410 struct ATS_Address * cur_addr;
1413 ph.peers = GNUNET_malloc ((count_p) * sizeof (struct PerfPeer));
1414 for (cp = 0; cp < count_p; cp++)
1415 perf_create_peer (cp);
1416 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1417 "Iteration %u of %u, added %u peers\n", ph.current_iteration, ph.total_iterations, cp);
1419 for (cp = 0; cp < count_p; cp++)
1421 if (GNUNET_NO == ph.bulk_running)
1423 ph.bulk_running = GNUNET_YES;
1424 ph.env.sf.s_bulk_start (ph.solver);
1426 ph.current_p = cp + 1;
1427 for (ca = 0; ca < count_a; ca++)
1429 cur_addr = perf_create_address (cp, ca);
1431 ph.env.sf.s_add (ph.solver, cur_addr, GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_ATS_NetworkTypeCount));
1432 ph.current_a = ca + 1;
1433 perf_address_initial_update (ph.solver, ph.addresses, cur_addr);
1434 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1435 "Adding address for peer %u address %u\n", cp, ca);
1437 /* Notify solver about request */
1438 ph.env.sf.s_get (ph.solver, &ph.peers[cp].id);
1440 if (cp + 1 >= ph.N_peers_start)
1442 /* Disable bulk to solve the problem */
1443 if (GNUNET_YES == ph.bulk_running)
1445 ph.expecting_solution = GNUNET_YES;
1446 ph.bulk_running = GNUNET_NO;
1447 ph.env.sf.s_bulk_stop (ph.solver);
1452 /* Problem is solved by the solver here due to unlocking */
1453 ph.expecting_solution = GNUNET_NO;
1455 /* Update the problem */
1456 if ((0 < ph.opt_update_percent) && (GNUNET_YES == ph.measure_updates))
1459 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1460 "Updating problem with %u peers and %u addresses\n", cp + 1, ca);
1462 ph.expecting_solution = GNUNET_YES;
1463 ph.performed_update = GNUNET_YES;
1464 if (GNUNET_NO == ph.bulk_running)
1466 ph.bulk_running = GNUNET_YES;
1467 ph.env.sf.s_bulk_start (ph.solver);
1469 perf_update_all_addresses (cp + 1, ca, ph.opt_update_percent);
1470 ph.bulk_running = GNUNET_NO;
1471 ph.env.sf.s_bulk_stop (ph.solver);
1472 /* Problem is solved by the solver here due to unlocking */
1473 ph.performed_update = GNUNET_NO;
1474 ph.expecting_solution = GNUNET_NO;
1476 GNUNET_assert (GNUNET_NO == ph.bulk_running);
1480 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1481 "Done, cleaning up addresses\n");
1482 if (GNUNET_NO == ph.bulk_running)
1484 ph.env.sf.s_bulk_start (ph.solver);
1485 ph.bulk_running = GNUNET_YES;
1488 for (cp = 0; cp < count_p; cp++)
1490 for (cur = ph.peers[cp].head; cur != NULL ; cur = next)
1492 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1493 "Deleting addresses for peer %u\n", cp);
1494 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (ph.addresses,
1495 &ph.peers[cp].id, cur));
1496 ph.env.sf.s_del (ph.solver, cur, GNUNET_NO);
1498 GNUNET_CONTAINER_DLL_remove(ph.peers[cp].head, ph.peers[cp].tail, cur);
1503 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1504 "Iteration done\n");
1505 GNUNET_free(ph.peers);
1510 run (void *cls, char * const *args, const char *cfgfile,
1511 const struct GNUNET_CONFIGURATION_Handle *cfg)
1513 GNUNET_log_setup ("perf-ats-solver", "WARNING", NULL);
1515 char *src_filename = GNUNET_strdup (__FILE__);
1516 char *test_filename = cls;
1519 struct GNUNET_CONFIGURATION_Handle *solver_cfg;
1520 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
1521 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
1524 /* Extract test name */
1525 if (NULL == (sep = (strstr (src_filename,".c"))))
1527 GNUNET_free (src_filename);
1534 if (NULL != (sep = strstr (test_filename, ".exe")))
1537 if (NULL == (solver = strstr (test_filename, src_filename)))
1539 GNUNET_free (src_filename);
1544 solver += strlen (src_filename) +1;
1546 if (0 == strcmp(solver, "proportional"))
1548 ph.ats_mode = MODE_PROPORTIONAL;
1549 ph.ats_string = "proportional";
1551 else if (0 == strcmp(solver, "mlp"))
1553 ph.ats_mode = MODE_MLP;
1554 ph.ats_string = "mlp";
1556 else if ((0 == strcmp(solver, "ril")))
1558 ph.ats_mode = MODE_RIL;
1559 ph.ats_string = "ril";
1563 GNUNET_free (src_filename);
1568 GNUNET_free (src_filename);
1570 /* Calculcate peers */
1571 if ((0 == ph.N_peers_start) && (0 == ph.N_peers_end))
1573 ph.N_peers_start = DEFAULT_PEERS_START;
1574 ph.N_peers_end = DEFAULT_PEERS_END;
1576 if (0 == ph.N_address)
1577 ph.N_address = DEFAULT_ADDRESSES;
1579 if (ph.N_peers_start != ph.N_peers_end)
1580 fprintf (stderr, "Benchmarking solver `%s' with %u to %u peers and %u addresses in %u iterations\n",
1581 ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address, ph.total_iterations);
1583 fprintf (stderr, "Benchmarking solver `%s' with %u peers and %u addresses in %u iterations\n",
1584 ph.ats_string, ph.N_peers_end, ph.N_address, ph.total_iterations);
1586 if (0 == ph.opt_update_percent)
1587 ph.opt_update_percent = DEFAULT_UPDATE_PERCENTAGE;
1590 solver_cfg = GNUNET_CONFIGURATION_create();
1591 if ((NULL == solver_cfg) || (GNUNET_SYSERR == (GNUNET_CONFIGURATION_load ( solver_cfg, "perf_ats_solver.conf"))))
1597 if (GNUNET_ATS_NetworkTypeCount != load_quotas (solver_cfg,
1598 quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount))
1605 /* Create array of DLL to store results for iterations */
1606 ph.iterations_results = GNUNET_malloc (sizeof (struct Iteration) * ph.total_iterations);
1607 ph.averaged_full_result = GNUNET_malloc (sizeof (struct Result) * ((ph.N_peers_end + 1) - ph.N_peers_start));
1608 for (c = 0; c <= ph.N_peers_end - ph.N_peers_start; c++)
1610 ph.averaged_full_result[c].d_setup = GNUNET_TIME_UNIT_FOREVER_REL;
1611 ph.averaged_full_result[c].d_total = GNUNET_TIME_UNIT_FOREVER_REL;
1612 ph.averaged_full_result[c].d_lp = GNUNET_TIME_UNIT_FOREVER_REL;
1613 ph.averaged_full_result[c].d_mlp = GNUNET_TIME_UNIT_FOREVER_REL;
1615 ph.averaged_update_result = GNUNET_malloc (sizeof (struct Result) * ((ph.N_peers_end + 1) - ph.N_peers_start));
1616 for (c = 0; c <= ph.N_peers_end - ph.N_peers_start; c++)
1618 ph.averaged_update_result[c].d_setup = GNUNET_TIME_UNIT_FOREVER_REL;
1619 ph.averaged_update_result[c].d_total = GNUNET_TIME_UNIT_FOREVER_REL;
1620 ph.averaged_update_result[c].d_lp = GNUNET_TIME_UNIT_FOREVER_REL;
1621 ph.averaged_update_result[c].d_mlp = GNUNET_TIME_UNIT_FOREVER_REL;
1625 ph.env.cfg = solver_cfg;
1626 ph.stat = GNUNET_STATISTICS_create ("ats", cfg);
1627 ph.env.stats = ph.stat;
1628 ph.addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
1629 ph.env.addresses = ph.addresses;
1630 ph.env.bandwidth_changed_cb = bandwidth_changed_cb;
1631 ph.env.get_preferences = &get_preferences_cb;
1632 ph.env.get_property = &get_property_cb;
1633 ph.env.network_count = GNUNET_ATS_NetworkTypeCount;
1634 ph.env.info_cb = &solver_info_cb;
1635 ph.env.info_cb_cls = NULL;
1637 int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
1638 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
1640 ph.env.networks[c] = networks[c];
1641 ph.env.out_quota[c] = quotas_out[c];
1642 ph.env.in_quota[c] = quotas_in[c];
1643 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loading network quotas: `%s' %llu %llu \n",
1644 GNUNET_ATS_print_network_type(ph.env.networks[c]),
1645 ph.env.out_quota[c],
1646 ph.env.in_quota[c]);
1648 GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL );
1650 GNUNET_asprintf (&plugin, "libgnunet_plugin_ats_%s", ph.ats_string);
1651 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initializing solver `%s'\n"), ph.ats_string);
1652 if (NULL == (ph.solver = GNUNET_PLUGIN_load (plugin, &ph.env)))
1654 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver `%s'!\n"), plugin);
1659 /* Do the benchmark */
1660 for (ph.current_iteration = 1; ph.current_iteration <= ph.total_iterations; ph.current_iteration++)
1662 perf_run_iteration ();
1663 evaluate (ph.current_iteration);
1665 evaluate_average ();
1668 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Unloading solver `%s'\n"), ph.ats_string);
1669 GNUNET_PLUGIN_unload (plugin, ph.solver);
1670 GNUNET_free (plugin);
1671 GNUNET_free (ph.iterations_results);
1672 GNUNET_free (ph.averaged_full_result);
1673 GNUNET_free (ph.averaged_update_result);
1674 GNUNET_CONFIGURATION_destroy (solver_cfg);
1675 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
1680 * Main function of the benchmark
1682 * @param argc argument count
1683 * @param argv argument values
1686 main (int argc, char *argv[])
1688 /* extract command line arguments */
1689 ph.opt_update_percent = 0;
1690 ph.N_peers_start = 0;
1693 ph.ats_string = NULL;
1694 ph.create_plot = GNUNET_NO;
1695 ph.measure_updates = GNUNET_NO;
1696 ph.total_iterations = 1;
1698 static struct GNUNET_GETOPT_CommandLineOption options[] = {
1699 { 'a', "addresses", NULL,
1700 gettext_noop ("addresses to use"),
1701 1, &GNUNET_GETOPT_set_uint, &ph.N_address },
1702 { 's', "start", NULL,
1703 gettext_noop ("start with peer"),
1704 1, &GNUNET_GETOPT_set_uint, &ph.N_peers_start },
1706 gettext_noop ("end with peer"),
1707 1, &GNUNET_GETOPT_set_uint, &ph.N_peers_end },
1708 { 'i', "iterations", NULL,
1709 gettext_noop ("number of iterations used for averaging (default: 1)"),
1710 1, &GNUNET_GETOPT_set_uint, &ph.total_iterations },
1711 { 'p', "percentage", NULL,
1712 gettext_noop ("update a fix percentage of addresses"),
1713 1, &GNUNET_GETOPT_set_uint, &ph.opt_update_percent },
1714 { 'g', "gnuplot", NULL,
1715 gettext_noop ("create GNUplot file"),
1716 0, &GNUNET_GETOPT_set_one, &ph.create_plot},
1717 { 'u', "update", NULL,
1718 gettext_noop ("measure updates"),
1719 0, &GNUNET_GETOPT_set_one, &ph.measure_updates},
1720 GNUNET_GETOPT_OPTION_END
1723 GNUNET_PROGRAM_run (argc, argv, argv[0], NULL, options, &run, argv[0]);
1727 /* end of file perf_ats_solver.c */