2 This file is part of GNUnet.
3 Copyright (C) 2010,2011 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @file ats/perf_ats_solver.c
20 * @brief generic performance test for ATS solvers
21 * @author Christian Grothoff
22 * @author Matthias Wachs
25 #include "gnunet_util_lib.h"
26 #include "gnunet_statistics_service.h"
27 #include "gnunet-service-ats_addresses.h"
28 #include "gnunet-service-ats_plugins.h"
29 #include "gnunet-service-ats_normalization.h"
30 #include "gnunet-service-ats_preferences.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
43 * Handle for statistics.
45 struct GNUNET_STATISTICS_Handle *GSA_stats;
48 * Handle for ATS address component
55 struct PerfPeer *peers;
60 struct GNUNET_ATS_SolverFunctions *sf;
65 struct GNUNET_STATISTICS_Handle *stat;
68 * A multihashmap to store all addresses
70 struct GNUNET_CONTAINER_MultiPeerMap *addresses;
75 struct GNUNET_ATS_PluginEnvironment env;
78 * Array for results for each iteration with length iterations
80 struct Iteration *iterations_results;
85 struct Result *current_result;
88 * Current number of peers benchmarked
93 * Current number of addresses benchmarked
98 * Solver description as string
103 * Configured ATS solver
108 * #peers to start benchmarking with
113 * #peers to end benchmarking with
118 * #addresses to benchmarking with
123 * Percentage of peers to update
125 int opt_update_percent;
128 * Create gnuplot file
138 * Number of iterations
140 int total_iterations;
145 int current_iteration;
148 * Is a bulk operation running?
153 * Is a bulk operation running?
155 int expecting_solution;
158 * Was the problem just updates?
160 int performed_update;
164 * Data structure to store results for a single iteration
168 struct Result **results_array;
170 struct Result **update_results_array;
175 * Result for a solver calculcation
180 * Previous element in the linked list
185 * Next element in the linked list
190 * Number of peers this solution included
195 * Number of addresses per peer this solution included
200 * Is this an update or a full solution
205 * Was the solution valid or did the solver fail
210 * Result of the solver
212 enum GAS_Solver_Additional_Information info;
215 * Duration of setting up the problem in the solver
217 struct GNUNET_TIME_Relative d_setup_full;
220 * Duration of solving the LP problem in the solver
223 struct GNUNET_TIME_Relative d_lp_full;
226 * Duration of solving the MLP problem in the solver
229 struct GNUNET_TIME_Relative d_mlp_full;
232 * Duration of solving whole problem in the solver
234 struct GNUNET_TIME_Relative d_total_full;
237 * Start time of setting up the problem in the solver
239 struct GNUNET_TIME_Absolute s_setup;
242 * Start time of solving the LP problem in the solver
245 struct GNUNET_TIME_Absolute s_lp;
248 * Start time of solving the MLP problem in the solver
251 struct GNUNET_TIME_Absolute s_mlp;
254 * Start time of solving whole problem in the solver
256 struct GNUNET_TIME_Absolute s_total;
259 * End time of setting up the problem in the solver
261 struct GNUNET_TIME_Absolute e_setup;
264 * End time of solving the LP problem in the solver
267 struct GNUNET_TIME_Absolute e_lp;
270 * End time of solving the MLP problem in the solver
273 struct GNUNET_TIME_Absolute e_mlp;
276 * End time of solving whole problem in the solver
278 struct GNUNET_TIME_Absolute e_total;
282 * Peer used for the benchmarking
289 struct GNUNET_PeerIdentity id;
292 * Head of linked list of addresses used with this peer
294 struct ATS_Address *head;
297 * Head of linked list of addresses used with this peer
299 struct ATS_Address *tail;
304 * ATS performance handle
306 static struct PerfHandle ph;
322 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
326 GNUNET_free_non_null (ph.peers);
327 GNUNET_free_non_null (ph.iterations_results);
329 GAS_normalization_stop ();
330 GAS_preference_done ();
336 * Create a peer used for benchmarking
338 * @param cp the number of the peer
341 perf_create_peer (int cp)
344 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
345 &ph.peers[cp].id, sizeof (struct GNUNET_PeerIdentity));
346 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp,
347 GNUNET_i2s (&ph.peers[cp].id));
352 * Perform an update for an address
354 * @param cur the address to update
357 perf_update_address (struct ATS_Address *cur)
363 r_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2);
367 abs_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
368 rel_val = (100 + (double) abs_val) / 100;
370 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
371 "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n",
372 GNUNET_i2s (&cur->peer), cur,
373 "GNUNET_ATS_QUALITY_NET_DELAY",
375 ph.sf->s_address_update_property (ph.sf->cls, cur,
376 GNUNET_ATS_QUALITY_NET_DELAY,
380 abs_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10);
381 rel_val = (100 + (double) abs_val) / 100;
383 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
384 "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n",
385 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE",
387 ph.sf->s_address_update_property (ph.sf->cls, cur,
388 GNUNET_ATS_QUALITY_NET_DISTANCE,
398 bandwidth_changed_cb (void *cls,
399 struct ATS_Address *address)
401 if ( (0 == address->assigned_bw_out) && (0 == address->assigned_bw_in) )
404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
405 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
406 GNUNET_i2s (&address->peer),
408 address->assigned_bw_out,
409 address->assigned_bw_in);
410 if (GNUNET_YES == ph.bulk_running)
416 static const double *
417 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
419 return GAS_preference_get_by_peer (NULL, id);
424 perf_address_initial_update (void *dead,
425 struct GNUNET_CONTAINER_MultiPeerMap * addresses,
426 struct ATS_Address *address)
430 uint32_t random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
431 delay = (100 + (double) random) / 100;
432 ph.sf->s_address_update_property (ph.sf->cls,
433 address, GNUNET_ATS_QUALITY_NET_DELAY,
436 random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
437 distance = (100 + (double) random) / 100;
439 ph.sf->s_address_update_property (ph.sf->cls, address,
440 GNUNET_ATS_QUALITY_NET_DISTANCE,
443 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
444 "Initial update address %p : %.2f %.2f\n",
445 address, delay, distance);
457 do_update_address (void *cls,
458 const struct GNUNET_PeerIdentity *pid,
461 struct DUA_Ctx *ctx = cls;
462 struct ATS_Address *addr = value;
464 if (ctx->c_cur_a == ctx->r)
465 perf_update_address (addr);
472 * Update a certain percentage of peers
474 * @param cp the current number of peers
475 * @param ca the current number of addresses
476 * @param percentage_peers the percentage of peers to update
479 perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percentage_peers)
487 struct DUA_Ctx dua_ctx;
489 count = cp * ((double) percentage_peers / 100);
490 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
491 "Updating %u of %u peers \n", count, cp);
493 for (c_peer = 0; c_peer < cp; c_peer++)
498 while (c_select < count)
500 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, cp);
504 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
505 "Updating peer [%u] \n", r);
509 for (c_cur_p = 0; c_cur_p < cp; c_cur_p++)
513 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca);
514 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
515 "Updating peer [%u] address [%u]\n", c_cur_p, r);
519 GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses,
520 &ph.peers[c_cur_p].id,
528 * Create an address for a peer
530 * @param cp index of the peer
531 * @param ca index of the address
532 * @return the address
534 static struct ATS_Address *
535 perf_create_address (int cp, int ca)
537 struct ATS_Address *a;
539 a = create_address (&ph.peers[cp].id,
540 "Test 1", "test 1", strlen ("test 1") + 1, 0);
541 GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a,
542 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
548 * Information callback for the solver
550 * @param op the solver operation
551 * @param stat status of the solver operation
552 * @param add additional solver information
555 solver_info_cb (void *cls,
556 enum GAS_Solver_Operation op,
557 enum GAS_Solver_Status stat,
558 enum GAS_Solver_Additional_Information add)
563 add_info = "GAS_INFO_NONE";
566 add_info = "GAS_INFO_MLP_FULL";
568 case GAS_INFO_UPDATED:
569 add_info = "GAS_INFO_MLP_UPDATED";
571 case GAS_INFO_PROP_ALL:
572 add_info = "GAS_INFO_PROP_ALL";
574 case GAS_INFO_PROP_SINGLE:
575 add_info = "GAS_INFO_PROP_SINGLE";
578 add_info = "INVALID";
585 case GAS_OP_SOLVE_START:
586 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
587 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
588 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
589 if (GNUNET_NO == ph.expecting_solution)
591 /* We do not expect a solution at the moment */
596 if ((GAS_STAT_SUCCESS == stat) && (NULL == ph.current_result))
598 tmp = GNUNET_new (struct Result);
599 /* Create new result */
600 if ((add == GAS_INFO_UPDATED) || (GNUNET_YES == ph.performed_update))
602 ph.current_result = tmp;
603 //fprintf (stderr,"UPDATE %u %u\n",ph.current_iteration-1, ph.current_p);
604 ph.iterations_results[ph.current_iteration-1].update_results_array[ph.current_p] = tmp;
608 ph.current_result = tmp;
609 //fprintf (stderr,"FULL %u %u\n",ph.current_iteration-1, ph.current_p);
610 ph.iterations_results[ph.current_iteration-1].results_array[ph.current_p] = tmp;
613 ph.current_result->addresses = ph.current_a;
614 ph.current_result->peers = ph.current_p;
615 ph.current_result->s_total = GNUNET_TIME_absolute_get();
616 ph.current_result->d_total_full = GNUNET_TIME_UNIT_FOREVER_REL;
617 ph.current_result->d_setup_full = GNUNET_TIME_UNIT_FOREVER_REL;
618 ph.current_result->d_lp_full = GNUNET_TIME_UNIT_FOREVER_REL;
619 ph.current_result->d_mlp_full = GNUNET_TIME_UNIT_FOREVER_REL;
620 ph.current_result->info = add;
621 if ((add == GAS_INFO_UPDATED) || (GNUNET_YES == ph.performed_update))
623 ph.current_result->update = GNUNET_YES;
627 ph.current_result->update = GNUNET_NO;
632 case GAS_OP_SOLVE_STOP:
633 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
634 "Solver notifies `%s' with result `%s', `%s'\n", "GAS_OP_SOLVE_STOP",
635 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
636 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
638 /* We do not expect a solution at the moment */
643 if (GAS_STAT_SUCCESS == stat)
644 ph.current_result->valid = GNUNET_YES;
646 ph.current_result->valid = GNUNET_NO;
648 if (NULL != ph.current_result)
650 /* Finalize result */
651 ph.current_result->e_total = GNUNET_TIME_absolute_get ();
652 ph.current_result->d_total_full = GNUNET_TIME_absolute_get_difference (
653 ph.current_result->s_total, ph.current_result->e_total);
655 ph.current_result = NULL;
658 case GAS_OP_SOLVE_SETUP_START:
659 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
660 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
661 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
662 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
668 if (GAS_STAT_SUCCESS == stat)
669 ph.current_result->valid = GNUNET_YES;
671 ph.current_result->valid = GNUNET_NO;
673 ph.current_result->s_setup = GNUNET_TIME_absolute_get ();
676 case GAS_OP_SOLVE_SETUP_STOP:
677 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
678 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
679 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
680 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
686 if (GAS_STAT_SUCCESS == stat)
687 ph.current_result->valid = GNUNET_YES;
689 ph.current_result->valid = GNUNET_NO;
691 ph.current_result->e_setup = GNUNET_TIME_absolute_get ();
692 ph.current_result->d_setup_full = GNUNET_TIME_absolute_get_difference (
693 ph.current_result->s_setup, ph.current_result->e_setup);
696 case GAS_OP_SOLVE_MLP_LP_START:
697 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
698 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
699 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
700 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
706 if (GAS_STAT_SUCCESS == stat)
707 ph.current_result->valid = GNUNET_YES;
709 ph.current_result->valid = GNUNET_NO;
711 ph.current_result->s_lp = GNUNET_TIME_absolute_get ();
713 case GAS_OP_SOLVE_MLP_LP_STOP:
714 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
715 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
716 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
717 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
723 if (GAS_STAT_SUCCESS == stat)
724 ph.current_result->valid = GNUNET_YES;
726 ph.current_result->valid = GNUNET_NO;
728 ph.current_result->e_lp = GNUNET_TIME_absolute_get ();
729 ph.current_result->d_lp_full = GNUNET_TIME_absolute_get_difference (
730 ph.current_result->s_lp, ph.current_result->e_lp);
733 case GAS_OP_SOLVE_MLP_MLP_START:
734 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
735 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
736 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
737 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
743 if (GAS_STAT_SUCCESS == stat)
744 ph.current_result->valid = GNUNET_YES;
746 ph.current_result->valid = GNUNET_NO;
748 ph.current_result->s_mlp = GNUNET_TIME_absolute_get ();
750 case GAS_OP_SOLVE_MLP_MLP_STOP:
751 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
752 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
753 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
754 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
760 if (GAS_STAT_SUCCESS == stat)
761 ph.current_result->valid = GNUNET_YES;
763 ph.current_result->valid = GNUNET_NO;
765 ph.current_result->e_mlp = GNUNET_TIME_absolute_get ();
766 ph.current_result->d_mlp_full = GNUNET_TIME_absolute_get_difference (
767 ph.current_result->s_mlp, ph.current_result->e_mlp);
769 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
770 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
771 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
772 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
774 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
775 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
776 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
777 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
778 if (GAS_STAT_SUCCESS != stat)
780 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
781 "Solver `%s' failed to update problem with %u peers and %u address!\n",
782 ph.ats_string, ph.current_p, ph.current_a);
792 * Evaluate results for a specific iteration
794 * @param iteration the iteration to evaluate
797 evaluate (int iteration)
802 for (cp = ph.N_peers_start; cp <= ph.N_peers_end; cp ++)
804 cur = ph.iterations_results[ph.current_iteration-1].results_array[cp];
811 "Missing result for %u peers\n", cp);
816 if (GNUNET_NO == cur->valid)
819 "Total time to solve %s for %u peers %u addresses: %s\n",
820 (GNUNET_YES == cur->update) ? "updated" : "full",
821 cur->peers, cur->addresses, "Failed to solve!");
826 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_total_full.rel_value_us)
829 "Total time to solve %s for %u peers %u addresses: %llu us\n",
830 (GNUNET_YES == cur->update) ? "updated" : "full",
831 cur->peers, cur->addresses,
832 (unsigned long long) cur->d_total_full.rel_value_us);
836 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_setup_full.rel_value_us)
838 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
839 "Total time to setup %s %u peers %u addresses: %llu us\n",
840 (GNUNET_YES == cur->update) ? "updated" : "full",
841 cur->peers, cur->addresses,
842 (unsigned long long) cur->d_setup_full.rel_value_us);
845 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_lp_full.rel_value_us)
847 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
848 "Total time to solve %s LP for %u peers %u addresses: %llu us\n",
849 (GNUNET_YES == cur->update) ? "updated" : "full",
852 (unsigned long long )cur->d_lp_full.rel_value_us);
855 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_mlp_full.rel_value_us)
857 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
858 "Total time to solve %s MLP for %u peers %u addresses: %llu us\n",
859 (GNUNET_YES == cur->update) ? "updated" : "full",
860 cur->peers, cur->addresses,
861 (unsigned long long )cur->d_mlp_full.rel_value_us);
868 get_connectivity_cb (void *cls,
869 const struct GNUNET_PeerIdentity *peer)
871 return GNUNET_CONTAINER_multipeermap_contains (ph.addresses,
877 * Evaluate average results for all iterations
880 write_all_iterations (void)
885 struct GNUNET_DISK_FileHandle *f_full;
886 struct GNUNET_DISK_FileHandle *f_update;
888 char * data_fn_update;
896 if (GNUNET_NO == ph.create_datafile)
899 GNUNET_asprintf (&data_fn_full,
900 "perf_%s_full_%u-%u_%u_%u.data",
906 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
907 "Using data file `%s'\n",
910 f_full = GNUNET_DISK_file_open (data_fn_full,
911 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
912 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
915 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
916 "Cannot open data file `%s'\n",
918 GNUNET_free (data_fn_full);
922 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
923 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_full, data, strlen(data)))
924 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
925 "Cannot write data to log file `%s'\n",
928 data_fn_update = NULL;
929 if (GNUNET_YES == ph.measure_updates)
931 GNUNET_asprintf (&data_fn_update, "perf_%s_update_%u-%u_%u_%u.data",
937 f_update = GNUNET_DISK_file_open (data_fn_update,
938 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
939 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
940 if (NULL == f_update)
942 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
943 "Cannot open gnuplot file `%s'\n", data_fn_update);
944 GNUNET_free (data_fn_update);
946 GNUNET_DISK_file_close (f_full);
947 GNUNET_free (data_fn_full);
951 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
952 "Using update data file `%s'\n",
955 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
956 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data)))
957 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
958 "Cannot write data to log file `%s'\n",
962 for (c_peer = ph.N_peers_start; c_peer <= ph.N_peers_end; c_peer ++)
968 GNUNET_asprintf(&data_str, "%u;%u",c_peer, ph.N_address);
969 if (ph.measure_updates)
970 GNUNET_asprintf(&data_upd_str, "%u;%u",c_peer, ph.N_address);
971 for (c_iteration = 0; c_iteration < ph.total_iterations; c_iteration ++)
973 struct Result *cur_full_res;
974 struct Result *cur_upd_res;
978 //fprintf (stderr, "P: %u I: %u == %p \n", c_peer, c_iteration, cur_res);
979 cur_full_res = ph.iterations_results[c_iteration].results_array[c_peer];
982 if (NULL == cur_full_res)
985 if (ph.measure_updates)
987 cur_upd_res = ph.iterations_results[c_iteration].update_results_array[c_peer];
988 data_upd_tmp = GNUNET_strdup (data_upd_str);
989 GNUNET_free (data_upd_str);
990 if (GNUNET_YES == cur_full_res->valid)
992 GNUNET_asprintf (&data_upd_str, "%s;%llu", data_upd_tmp,
993 (NULL == cur_upd_res) ? 0 : cur_upd_res->d_total_full.rel_value_us);
997 GNUNET_asprintf (&data_upd_str, "%s;", data_upd_tmp);
999 GNUNET_free (data_upd_tmp);
1003 //fprintf (stderr, "P: %u I: %u: P %i A %i\n", c_peer, c_iteration, cur_res->peers, cur_res->addresses);
1004 //fprintf (stderr, "D total: %llu\n", (long long unsigned int) cur_res->d_total.rel_value_us);
1006 data_tmp = GNUNET_strdup (data_str);
1007 GNUNET_free (data_str);
1008 if (GNUNET_YES == cur_full_res->valid)
1010 GNUNET_asprintf (&data_str, "%s;%llu", data_tmp,
1011 cur_full_res->d_total_full.rel_value_us);
1015 GNUNET_asprintf (&data_str, "%s;", data_tmp);
1018 GNUNET_free (data_tmp);
1020 data_tmp = GNUNET_strdup (data_str);
1021 GNUNET_free (data_str);
1022 GNUNET_asprintf (&data_str, "%s\n", data_tmp);
1023 GNUNET_free (data_tmp);
1025 fprintf (stderr, "Result full solution: %s\n", data_str);
1026 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_full, data_str, strlen(data_str)))
1028 GNUNET_free (data_str);
1030 if (ph.measure_updates)
1032 data_upd_tmp = GNUNET_strdup (data_upd_str);
1033 GNUNET_free (data_upd_str);
1034 GNUNET_asprintf (&data_upd_str, "%s\n", data_upd_tmp);
1035 GNUNET_free (data_upd_tmp);
1037 fprintf (stderr, "Result updated solution: `%s'\n", data_upd_str);
1038 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data_upd_str, strlen(data_upd_str)))
1040 GNUNET_free (data_upd_str);
1044 if ((NULL != f_full) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_full)))
1045 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1047 GNUNET_free_non_null (data_fn_full);
1049 if ((NULL != f_update) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_update)))
1050 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1052 GNUNET_free_non_null (data_fn_update);
1057 do_delete_address (void *cls,
1058 const struct GNUNET_PeerIdentity *pid,
1061 struct ATS_Address *cur = value;
1063 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1064 "Deleting addresses for peer %u\n",
1066 GNUNET_assert (GNUNET_OK ==
1067 GNUNET_CONTAINER_multipeermap_remove (ph.addresses,
1070 ph.sf->s_del (ph.sf->cls, cur);
1071 GNUNET_free_non_null (cur->atsi);
1078 * Run a performance iteration
1081 perf_run_iteration (void)
1085 int count_p = ph.N_peers_end;
1086 int count_a = ph.N_address;
1087 struct ATS_Address * cur_addr;
1090 ph.iterations_results[ph.current_iteration-1].results_array = GNUNET_malloc ((count_p + 1) * sizeof (struct Result *));
1091 if (ph.measure_updates)
1092 ph.iterations_results[ph.current_iteration-1].update_results_array = GNUNET_malloc ((count_p + 1) * sizeof (struct Result *));
1093 ph.peers = GNUNET_malloc ((count_p) * sizeof (struct PerfPeer));
1094 for (cp = 0; cp < count_p; cp++)
1095 perf_create_peer (cp);
1096 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1097 "Iteration %u of %u, added %u peers\n", ph.current_iteration, ph.total_iterations, cp);
1099 for (cp = 0; cp < count_p; cp++)
1101 fprintf (stderr,"%u..", cp);
1102 if (GNUNET_NO == ph.bulk_running)
1104 ph.bulk_running = GNUNET_YES;
1105 ph.sf->s_bulk_start (ph.sf->cls);
1107 ph.current_p = cp + 1;
1108 for (ca = 0; ca < count_a; ca++)
1110 cur_addr = perf_create_address (cp, ca);
1113 /* Random network selection */
1114 //net = 1 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_ATS_NetworkTypeCount - 1);
1115 /* Random equally distributed network selection */
1116 net = 1 + (ca % (GNUNET_ATS_NetworkTypeCount - 1));
1117 /* fprintf (stderr, "Network: %u `%s'\n",
1118 * mod_net , GNUNET_ATS_print_network_type(mod_net)); */
1120 cur_addr->atsi = GNUNET_new (struct GNUNET_ATS_Information);
1121 cur_addr->atsi_count = 1;
1122 cur_addr->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
1123 cur_addr->atsi[0].value = htonl (net);
1124 ph.sf->s_add (ph.sf->cls, cur_addr, net);
1126 ph.current_a = ca + 1;
1127 perf_address_initial_update (NULL, ph.addresses, cur_addr);
1128 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1129 "Adding address for peer %u address %u in network %s\n", cp, ca,
1130 GNUNET_ATS_print_network_type(net));
1132 /* Notify solver about request */
1133 ph.sf->s_get (ph.sf->cls, &ph.peers[cp].id);
1135 if (cp + 1 >= ph.N_peers_start)
1137 /* Disable bulk to solve the problem */
1138 if (GNUNET_YES == ph.bulk_running)
1140 ph.expecting_solution = GNUNET_YES;
1141 ph.bulk_running = GNUNET_NO;
1142 ph.sf->s_bulk_stop (ph.sf->cls);
1147 /* Problem is solved by the solver here due to unlocking */
1148 ph.expecting_solution = GNUNET_NO;
1150 /* Update the problem */
1151 if ((0 < ph.opt_update_percent) && (GNUNET_YES == ph.measure_updates))
1154 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1155 "Updating problem with %u peers and %u addresses\n", cp + 1, ca);
1157 ph.expecting_solution = GNUNET_YES;
1158 ph.performed_update = GNUNET_YES;
1159 if (GNUNET_NO == ph.bulk_running)
1161 ph.bulk_running = GNUNET_YES;
1162 ph.sf->s_bulk_start (ph.sf->cls);
1164 perf_update_all_addresses (cp + 1, ca, ph.opt_update_percent);
1165 ph.bulk_running = GNUNET_NO;
1166 ph.sf->s_bulk_stop (ph.sf->cls);
1167 /* Problem is solved by the solver here due to unlocking */
1168 ph.performed_update = GNUNET_NO;
1169 ph.expecting_solution = GNUNET_NO;
1171 GNUNET_assert (GNUNET_NO == ph.bulk_running);
1174 fprintf (stderr,"\n");
1175 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1176 "Done, cleaning up addresses\n");
1177 if (GNUNET_NO == ph.bulk_running)
1179 ph.sf->s_bulk_start (ph.sf->cls);
1180 ph.bulk_running = GNUNET_YES;
1183 for (cp = 0; cp < count_p; cp++)
1185 GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses,
1190 if (GNUNET_NO == ph.bulk_running)
1192 ph.sf->s_bulk_stop (ph.sf->cls);
1193 ph.bulk_running = GNUNET_NO;
1196 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1197 "Iteration done\n");
1198 GNUNET_free(ph.peers);
1203 run (void *cls, char * const *args, const char *cfgfile,
1204 const struct GNUNET_CONFIGURATION_Handle *cfg)
1206 GNUNET_log_setup ("perf-ats-solver", "WARNING", NULL);
1208 char *src_filename = GNUNET_strdup (__FILE__);
1209 char *test_filename = cls;
1212 struct GNUNET_CONFIGURATION_Handle *solver_cfg;
1213 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
1214 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
1218 /* Extract test name */
1219 if (NULL == (sep = (strstr (src_filename,".c"))))
1221 GNUNET_free (src_filename);
1228 if (NULL != (sep = strstr (test_filename, ".exe")))
1231 if (NULL == (solver = strstr (test_filename, src_filename)))
1233 GNUNET_free (src_filename);
1238 solver += strlen (src_filename) +1;
1240 if (0 == strcmp(solver, "proportional"))
1242 ph.ats_string = "proportional";
1244 else if (0 == strcmp(solver, "mlp"))
1246 ph.ats_string = "mlp";
1248 else if ((0 == strcmp(solver, "ril")))
1250 ph.ats_string = "ril";
1254 GNUNET_free (src_filename);
1259 GNUNET_free (src_filename);
1261 /* Calculcate peers */
1262 if ((0 == ph.N_peers_start) && (0 == ph.N_peers_end))
1264 ph.N_peers_start = DEFAULT_PEERS_START;
1265 ph.N_peers_end = DEFAULT_PEERS_END;
1267 if (0 == ph.N_address)
1268 ph.N_address = DEFAULT_ADDRESSES;
1271 if (ph.N_peers_start != ph.N_peers_end)
1272 fprintf (stderr, "Benchmarking solver `%s' with %u to %u peers and %u addresses in %u iterations\n",
1273 ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address, ph.total_iterations);
1275 fprintf (stderr, "Benchmarking solver `%s' with %u peers and %u addresses in %u iterations\n",
1276 ph.ats_string, ph.N_peers_end, ph.N_address, ph.total_iterations);
1278 if (0 == ph.opt_update_percent)
1279 ph.opt_update_percent = DEFAULT_UPDATE_PERCENTAGE;
1282 solver_cfg = GNUNET_CONFIGURATION_create();
1283 if ((NULL == solver_cfg) || (GNUNET_SYSERR == (GNUNET_CONFIGURATION_load ( solver_cfg, "perf_ats_solver.conf"))))
1289 if (GNUNET_ATS_NetworkTypeCount != load_quotas (solver_cfg,
1290 quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount))
1297 /* Create array of DLL to store results for iterations */
1298 ph.iterations_results = GNUNET_malloc (sizeof (struct Iteration) * ph.total_iterations);
1301 ph.env.cfg = solver_cfg;
1302 ph.stat = GNUNET_STATISTICS_create ("ats", cfg);
1303 ph.env.stats = ph.stat;
1304 ph.addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
1305 ph.env.addresses = ph.addresses;
1306 ph.env.bandwidth_changed_cb = bandwidth_changed_cb;
1307 ph.env.get_connectivity = &get_connectivity_cb;
1308 ph.env.get_preferences = &get_preferences_cb;
1309 ph.env.network_count = GNUNET_ATS_NetworkTypeCount;
1310 ph.env.info_cb = &solver_info_cb;
1312 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
1314 ph.env.out_quota[c] = quotas_out[c];
1315 ph.env.in_quota[c] = quotas_in[c];
1316 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1317 "Loading network quotas: `%s' %llu %llu \n",
1318 GNUNET_ATS_print_network_type (c),
1319 ph.env.out_quota[c],
1320 ph.env.in_quota[c]);
1322 GAS_normalization_start ();
1323 GAS_preference_init ();
1325 GNUNET_asprintf (&plugin,
1326 "libgnunet_plugin_ats_%s",
1328 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1329 _("Initializing solver `%s'\n"),
1331 if (NULL == (ph.sf = GNUNET_PLUGIN_load (plugin, &ph.env)))
1333 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1334 _("Failed to initialize solver `%s'!\n"),
1340 /* Do the benchmark */
1341 for (ph.current_iteration = 1; ph.current_iteration <= ph.total_iterations; ph.current_iteration++)
1344 "Iteration %u of %u starting\n",
1345 ph.current_iteration,
1346 ph.total_iterations);
1347 perf_run_iteration ();
1348 evaluate (ph.current_iteration);
1350 "Iteration %u of %u done\n",
1351 ph.current_iteration,
1352 ph.total_iterations);
1354 if (ph.create_datafile)
1355 write_all_iterations ();
1358 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1359 _("Unloading solver `%s'\n"),
1361 GNUNET_PLUGIN_unload (plugin, ph.sf);
1363 GNUNET_free (plugin);
1364 for (c = 0; c < ph.total_iterations; c++ )
1366 for (c2 = ph.N_peers_start; c2 < ph.N_peers_end; c2++ )
1370 if (ph.measure_updates)
1371 GNUNET_free_non_null (ph.iterations_results[c].update_results_array[c2]);
1372 GNUNET_free (ph.iterations_results[c].results_array[c2]);
1374 if (ph.measure_updates)
1375 GNUNET_free (ph.iterations_results[c].update_results_array);
1376 GNUNET_free(ph.iterations_results[c].results_array);
1378 GNUNET_free (ph.iterations_results);
1380 GNUNET_CONFIGURATION_destroy (solver_cfg);
1381 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
1386 * Main function of the benchmark
1388 * @param argc argument count
1389 * @param argv argument values
1392 main (int argc, char *argv[])
1394 /* extract command line arguments */
1395 ph.opt_update_percent = 0;
1396 ph.N_peers_start = 0;
1399 ph.ats_string = NULL;
1400 ph.create_datafile = GNUNET_NO;
1401 ph.measure_updates = GNUNET_NO;
1402 ph.total_iterations = 1;
1404 static struct GNUNET_GETOPT_CommandLineOption options[] = {
1406 GNUNET_GETOPT_option_uint ('a',
1408 gettext_noop ("addresses to use"),
1411 GNUNET_GETOPT_option_uint ('s',
1413 gettext_noop ("start with peer"),
1416 GNUNET_GETOPT_option_uint ('e',
1418 gettext_noop ("end with peer"),
1421 GNUNET_GETOPT_option_uint ('i',
1423 gettext_noop ("number of iterations used for averaging (default: 1)"),
1424 &ph.total_iterations),
1426 GNUNET_GETOPT_option_uint ('p',
1428 gettext_noop ("update a fix percentage of addresses"),
1429 &ph.opt_update_percent),
1431 GNUNET_GETOPT_option_flag ('d',
1433 gettext_noop ("create data file"),
1434 &ph.create_datafile),
1436 GNUNET_GETOPT_option_flag ('u',
1438 gettext_noop ("measure updates"),
1439 &ph.measure_updates),
1441 GNUNET_GETOPT_OPTION_END
1444 GNUNET_PROGRAM_run (argc, argv, argv[0], NULL, options, &run, argv[0]);
1448 /* end of file perf_ats_solver.c */