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_plugins.h"
31 #include "gnunet-service-ats_normalization.h"
32 #include "gnunet-service-ats_preferences.h"
33 #include "gnunet_ats_service.h"
34 #include "gnunet_ats_plugin.h"
35 #include "test_ats_api_common.h"
37 #define DEFAULT_UPDATE_PERCENTAGE 20
38 #define DEFAULT_PEERS_START 10
39 #define DEFAULT_PEERS_END 10
40 #define DEFAULT_ADDRESSES 10
41 #define DEFAULT_ATS_COUNT 2
45 * Handle for statistics.
47 struct GNUNET_STATISTICS_Handle *GSA_stats;
50 * Handle for ATS address component
57 struct PerfPeer *peers;
62 struct GNUNET_ATS_SolverFunctions *sf;
67 struct GNUNET_STATISTICS_Handle *stat;
70 * A multihashmap to store all addresses
72 struct GNUNET_CONTAINER_MultiPeerMap *addresses;
77 struct GNUNET_ATS_PluginEnvironment env;
80 * Array for results for each iteration with length iterations
82 struct Iteration *iterations_results;
87 struct Result *current_result;
90 * Current number of peers benchmarked
95 * Current number of addresses benchmarked
100 * Solver description as string
105 * Configured ATS solver
110 * #peers to start benchmarking with
115 * #peers to end benchmarking with
120 * #addresses to benchmarking with
125 * Percentage of peers to update
127 int opt_update_percent;
130 * Create gnuplot file
140 * Number of iterations
142 int total_iterations;
147 int current_iteration;
150 * Is a bulk operation running?
155 * Is a bulk operation running?
157 int expecting_solution;
160 * Was the problem just updates?
162 int performed_update;
166 * Data structure to store results for a single iteration
170 struct Result **results_array;
172 struct Result **update_results_array;
177 * Result for a solver calculcation
182 * Previous element in the linked list
187 * Next element in the linked list
192 * Number of peers this solution included
197 * Number of addresses per peer this solution included
202 * Is this an update or a full solution
207 * Was the solution valid or did the solver fail
212 * Result of the solver
214 enum GAS_Solver_Additional_Information info;
217 * Duration of setting up the problem in the solver
219 struct GNUNET_TIME_Relative d_setup_full;
222 * Duration of solving the LP problem in the solver
225 struct GNUNET_TIME_Relative d_lp_full;
228 * Duration of solving the MLP problem in the solver
231 struct GNUNET_TIME_Relative d_mlp_full;
234 * Duration of solving whole problem in the solver
236 struct GNUNET_TIME_Relative d_total_full;
239 * Start time of setting up the problem in the solver
241 struct GNUNET_TIME_Absolute s_setup;
244 * Start time of solving the LP problem in the solver
247 struct GNUNET_TIME_Absolute s_lp;
250 * Start time of solving the MLP problem in the solver
253 struct GNUNET_TIME_Absolute s_mlp;
256 * Start time of solving whole problem in the solver
258 struct GNUNET_TIME_Absolute s_total;
261 * End time of setting up the problem in the solver
263 struct GNUNET_TIME_Absolute e_setup;
266 * End time of solving the LP problem in the solver
269 struct GNUNET_TIME_Absolute e_lp;
272 * End time of solving the MLP problem in the solver
275 struct GNUNET_TIME_Absolute e_mlp;
278 * End time of solving whole problem in the solver
280 struct GNUNET_TIME_Absolute e_total;
284 * Peer used for the benchmarking
291 struct GNUNET_PeerIdentity id;
294 * Head of linked list of addresses used with this peer
296 struct ATS_Address *head;
299 * Head of linked list of addresses used with this peer
301 struct ATS_Address *tail;
306 * ATS performance handle
308 static struct PerfHandle ph;
324 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
328 GNUNET_free_non_null (ph.peers);
329 GNUNET_free_non_null (ph.iterations_results);
331 GAS_normalization_stop ();
332 GAS_preference_done ();
338 * Create a peer used for benchmarking
340 * @param cp the number of the peer
343 perf_create_peer (int cp)
346 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
347 &ph.peers[cp].id, sizeof (struct GNUNET_PeerIdentity));
348 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp,
349 GNUNET_i2s (&ph.peers[cp].id));
354 * Perform an update for an address
356 * @param cur the address to update
359 perf_update_address (struct ATS_Address *cur)
365 r_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2);
369 abs_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
370 rel_val = (100 + (double) abs_val) / 100;
372 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
373 "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n",
374 GNUNET_i2s (&cur->peer), cur,
375 "GNUNET_ATS_QUALITY_NET_DELAY",
377 ph.sf->s_address_update_property (ph.sf->cls, cur,
378 GNUNET_ATS_QUALITY_NET_DELAY,
382 abs_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10);
383 rel_val = (100 + (double) abs_val) / 100;
385 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
386 "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n",
387 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE",
389 ph.sf->s_address_update_property (ph.sf->cls, cur,
390 GNUNET_ATS_QUALITY_NET_DISTANCE,
400 bandwidth_changed_cb (void *cls,
401 struct ATS_Address *address)
403 if ( (0 == address->assigned_bw_out) && (0 == address->assigned_bw_in) )
406 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
407 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
408 GNUNET_i2s (&address->peer),
410 address->assigned_bw_out,
411 address->assigned_bw_in);
412 if (GNUNET_YES == ph.bulk_running)
419 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
421 return GAS_normalization_get_preferences_by_peer (NULL, id);
426 get_property_cb (void *cls, const struct ATS_Address *address)
428 return GAS_normalization_get_properties (NULL,
434 perf_address_initial_update (void *dead,
435 struct GNUNET_CONTAINER_MultiPeerMap * addresses,
436 struct ATS_Address *address)
440 uint32_t random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
441 delay = (100 + (double) random) / 100;
442 ph.sf->s_address_update_property (ph.sf->cls,
443 address, GNUNET_ATS_QUALITY_NET_DELAY,
446 random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
447 distance = (100 + (double) random) / 100;
449 ph.sf->s_address_update_property (ph.sf->cls, address,
450 GNUNET_ATS_QUALITY_NET_DISTANCE,
453 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
454 "Initial update address %p : %.2f %.2f\n",
455 address, delay, distance);
467 do_update_address (void *cls,
468 const struct GNUNET_PeerIdentity *pid,
471 struct DUA_Ctx *ctx = cls;
472 struct ATS_Address *addr = value;
474 if (ctx->c_cur_a == ctx->r)
475 perf_update_address (addr);
482 * Update a certain percentage of peers
484 * @param cp the current number of peers
485 * @param ca the current number of addresses
486 * @param percentage_peers the percentage of peers to update
489 perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percentage_peers)
497 struct DUA_Ctx dua_ctx;
499 count = cp * ((double) percentage_peers / 100);
500 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
501 "Updating %u of %u peers \n", count, cp);
503 for (c_peer = 0; c_peer < cp; c_peer++)
508 while (c_select < count)
510 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, cp);
514 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
515 "Updating peer [%u] \n", r);
519 for (c_cur_p = 0; c_cur_p < cp; c_cur_p++)
523 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca);
524 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
525 "Updating peer [%u] address [%u]\n", c_cur_p, r);
529 GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses,
530 &ph.peers[c_cur_p].id,
538 * Create an address for a peer
540 * @param cp index of the peer
541 * @param ca index of the address
542 * @return the address
544 static struct ATS_Address *
545 perf_create_address (int cp, int ca)
547 struct ATS_Address *a;
549 a = create_address (&ph.peers[cp].id,
550 "Test 1", "test 1", strlen ("test 1") + 1, 0);
551 GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a,
552 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
558 * Information callback for the solver
560 * @param op the solver operation
561 * @param stat status of the solver operation
562 * @param add additional solver information
565 solver_info_cb (void *cls,
566 enum GAS_Solver_Operation op,
567 enum GAS_Solver_Status stat,
568 enum GAS_Solver_Additional_Information add)
573 add_info = "GAS_INFO_NONE";
576 add_info = "GAS_INFO_MLP_FULL";
578 case GAS_INFO_UPDATED:
579 add_info = "GAS_INFO_MLP_UPDATED";
581 case GAS_INFO_PROP_ALL:
582 add_info = "GAS_INFO_PROP_ALL";
584 case GAS_INFO_PROP_SINGLE:
585 add_info = "GAS_INFO_PROP_SINGLE";
588 add_info = "INVALID";
595 case GAS_OP_SOLVE_START:
596 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
597 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
598 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
599 if (GNUNET_NO == ph.expecting_solution)
601 /* We do not expect a solution at the moment */
606 if ((GAS_STAT_SUCCESS == stat) && (NULL == ph.current_result))
608 tmp = GNUNET_new (struct Result);
609 /* Create new result */
610 if ((add == GAS_INFO_UPDATED) || (GNUNET_YES == ph.performed_update))
612 ph.current_result = tmp;
613 //fprintf (stderr,"UPDATE %u %u\n",ph.current_iteration-1, ph.current_p);
614 ph.iterations_results[ph.current_iteration-1].update_results_array[ph.current_p] = tmp;
618 ph.current_result = tmp;
619 //fprintf (stderr,"FULL %u %u\n",ph.current_iteration-1, ph.current_p);
620 ph.iterations_results[ph.current_iteration-1].results_array[ph.current_p] = tmp;
623 ph.current_result->addresses = ph.current_a;
624 ph.current_result->peers = ph.current_p;
625 ph.current_result->s_total = GNUNET_TIME_absolute_get();
626 ph.current_result->d_total_full = GNUNET_TIME_UNIT_FOREVER_REL;
627 ph.current_result->d_setup_full = GNUNET_TIME_UNIT_FOREVER_REL;
628 ph.current_result->d_lp_full = GNUNET_TIME_UNIT_FOREVER_REL;
629 ph.current_result->d_mlp_full = GNUNET_TIME_UNIT_FOREVER_REL;
630 ph.current_result->info = add;
631 if ((add == GAS_INFO_UPDATED) || (GNUNET_YES == ph.performed_update))
633 ph.current_result->update = GNUNET_YES;
637 ph.current_result->update = GNUNET_NO;
642 case GAS_OP_SOLVE_STOP:
643 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
644 "Solver notifies `%s' with result `%s', `%s'\n", "GAS_OP_SOLVE_STOP",
645 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
646 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
648 /* We do not expect a solution at the moment */
653 if (GAS_STAT_SUCCESS == stat)
654 ph.current_result->valid = GNUNET_YES;
656 ph.current_result->valid = GNUNET_NO;
658 if (NULL != ph.current_result)
660 /* Finalize result */
661 ph.current_result->e_total = GNUNET_TIME_absolute_get ();
662 ph.current_result->d_total_full = GNUNET_TIME_absolute_get_difference (
663 ph.current_result->s_total, ph.current_result->e_total);
665 ph.current_result = NULL;
668 case GAS_OP_SOLVE_SETUP_START:
669 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
670 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
671 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
672 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
678 if (GAS_STAT_SUCCESS == stat)
679 ph.current_result->valid = GNUNET_YES;
681 ph.current_result->valid = GNUNET_NO;
683 ph.current_result->s_setup = GNUNET_TIME_absolute_get ();
686 case GAS_OP_SOLVE_SETUP_STOP:
687 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
688 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
689 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
690 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
696 if (GAS_STAT_SUCCESS == stat)
697 ph.current_result->valid = GNUNET_YES;
699 ph.current_result->valid = GNUNET_NO;
701 ph.current_result->e_setup = GNUNET_TIME_absolute_get ();
702 ph.current_result->d_setup_full = GNUNET_TIME_absolute_get_difference (
703 ph.current_result->s_setup, ph.current_result->e_setup);
706 case GAS_OP_SOLVE_MLP_LP_START:
707 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
708 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
709 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
710 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
716 if (GAS_STAT_SUCCESS == stat)
717 ph.current_result->valid = GNUNET_YES;
719 ph.current_result->valid = GNUNET_NO;
721 ph.current_result->s_lp = GNUNET_TIME_absolute_get ();
723 case GAS_OP_SOLVE_MLP_LP_STOP:
724 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
725 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
726 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
727 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
733 if (GAS_STAT_SUCCESS == stat)
734 ph.current_result->valid = GNUNET_YES;
736 ph.current_result->valid = GNUNET_NO;
738 ph.current_result->e_lp = GNUNET_TIME_absolute_get ();
739 ph.current_result->d_lp_full = GNUNET_TIME_absolute_get_difference (
740 ph.current_result->s_lp, ph.current_result->e_lp);
743 case GAS_OP_SOLVE_MLP_MLP_START:
744 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
745 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
746 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
747 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
753 if (GAS_STAT_SUCCESS == stat)
754 ph.current_result->valid = GNUNET_YES;
756 ph.current_result->valid = GNUNET_NO;
758 ph.current_result->s_mlp = GNUNET_TIME_absolute_get ();
760 case GAS_OP_SOLVE_MLP_MLP_STOP:
761 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
762 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
763 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
764 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
770 if (GAS_STAT_SUCCESS == stat)
771 ph.current_result->valid = GNUNET_YES;
773 ph.current_result->valid = GNUNET_NO;
775 ph.current_result->e_mlp = GNUNET_TIME_absolute_get ();
776 ph.current_result->d_mlp_full = GNUNET_TIME_absolute_get_difference (
777 ph.current_result->s_mlp, ph.current_result->e_mlp);
779 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
780 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
781 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
782 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
784 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
785 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
786 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
787 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
788 if (GAS_STAT_SUCCESS != stat)
790 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
791 "Solver `%s' failed to update problem with %u peers and %u address!\n",
792 ph.ats_string, ph.current_p, ph.current_a);
802 * Evaluate results for a specific iteration
804 * @param iteration the iteration to evaluate
807 evaluate (int iteration)
812 for (cp = ph.N_peers_start; cp <= ph.N_peers_end; cp ++)
814 cur = ph.iterations_results[ph.current_iteration-1].results_array[cp];
821 "Missing result for %u peers\n", cp);
826 if (GNUNET_NO == cur->valid)
829 "Total time to solve %s for %u peers %u addresses: %s\n",
830 (GNUNET_YES == cur->update) ? "updated" : "full",
831 cur->peers, cur->addresses, "Failed to solve!");
836 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_total_full.rel_value_us)
839 "Total time to solve %s for %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_total_full.rel_value_us);
846 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_setup_full.rel_value_us)
848 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
849 "Total time to setup %s %u peers %u addresses: %llu us\n",
850 (GNUNET_YES == cur->update) ? "updated" : "full",
851 cur->peers, cur->addresses,
852 (unsigned long long) cur->d_setup_full.rel_value_us);
855 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_lp_full.rel_value_us)
857 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
858 "Total time to solve %s LP for %u peers %u addresses: %llu us\n",
859 (GNUNET_YES == cur->update) ? "updated" : "full",
862 (unsigned long long )cur->d_lp_full.rel_value_us);
865 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_mlp_full.rel_value_us)
867 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
868 "Total time to solve %s MLP for %u peers %u addresses: %llu us\n",
869 (GNUNET_YES == cur->update) ? "updated" : "full",
870 cur->peers, cur->addresses,
871 (unsigned long long )cur->d_mlp_full.rel_value_us);
878 * Evaluate average results for all iterations
881 write_all_iterations (void)
886 struct GNUNET_DISK_FileHandle *f_full;
887 struct GNUNET_DISK_FileHandle *f_update;
889 char * data_fn_update;
897 if (GNUNET_NO == ph.create_datafile)
900 GNUNET_asprintf (&data_fn_full,
901 "perf_%s_full_%u-%u_%u_%u.data",
907 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
908 "Using data file `%s'\n",
911 f_full = GNUNET_DISK_file_open (data_fn_full,
912 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
913 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
916 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
917 "Cannot open data file `%s'\n",
919 GNUNET_free (data_fn_full);
923 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
924 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_full, data, strlen(data)))
925 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
926 "Cannot write data to log file `%s'\n",
929 data_fn_update = NULL;
930 if (GNUNET_YES == ph.measure_updates)
932 GNUNET_asprintf (&data_fn_update, "perf_%s_update_%u-%u_%u_%u.data",
938 f_update = GNUNET_DISK_file_open (data_fn_update,
939 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
940 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
941 if (NULL == f_update)
943 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
944 "Cannot open gnuplot file `%s'\n", data_fn_update);
945 GNUNET_free (data_fn_update);
947 GNUNET_DISK_file_close (f_full);
948 GNUNET_free (data_fn_full);
952 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
953 "Using update data file `%s'\n",
956 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
957 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data)))
958 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
959 "Cannot write data to log file `%s'\n",
963 for (c_peer = ph.N_peers_start; c_peer <= ph.N_peers_end; c_peer ++)
969 GNUNET_asprintf(&data_str, "%u;%u",c_peer, ph.N_address);
970 if (ph.measure_updates)
971 GNUNET_asprintf(&data_upd_str, "%u;%u",c_peer, ph.N_address);
972 for (c_iteration = 0; c_iteration < ph.total_iterations; c_iteration ++)
974 struct Result *cur_full_res;
975 struct Result *cur_upd_res;
979 //fprintf (stderr, "P: %u I: %u == %p \n", c_peer, c_iteration, cur_res);
980 cur_full_res = ph.iterations_results[c_iteration].results_array[c_peer];
983 if (NULL == cur_full_res)
986 if (ph.measure_updates)
988 cur_upd_res = ph.iterations_results[c_iteration].update_results_array[c_peer];
989 data_upd_tmp = GNUNET_strdup (data_upd_str);
990 GNUNET_free (data_upd_str);
991 if (GNUNET_YES == cur_full_res->valid)
993 GNUNET_asprintf (&data_upd_str, "%s;%llu", data_upd_tmp,
994 (NULL == cur_upd_res) ? 0 : cur_upd_res->d_total_full.rel_value_us);
998 GNUNET_asprintf (&data_upd_str, "%s;", data_upd_tmp);
1000 GNUNET_free (data_upd_tmp);
1004 //fprintf (stderr, "P: %u I: %u: P %i A %i\n", c_peer, c_iteration, cur_res->peers, cur_res->addresses);
1005 //fprintf (stderr, "D total: %llu\n", (long long unsigned int) cur_res->d_total.rel_value_us);
1007 data_tmp = GNUNET_strdup (data_str);
1008 GNUNET_free (data_str);
1009 if (GNUNET_YES == cur_full_res->valid)
1011 GNUNET_asprintf (&data_str, "%s;%llu", data_tmp,
1012 cur_full_res->d_total_full.rel_value_us);
1016 GNUNET_asprintf (&data_str, "%s;", data_tmp);
1019 GNUNET_free (data_tmp);
1021 data_tmp = GNUNET_strdup (data_str);
1022 GNUNET_free (data_str);
1023 GNUNET_asprintf (&data_str, "%s\n", data_tmp);
1024 GNUNET_free (data_tmp);
1026 fprintf (stderr, "Result full solution: %s\n", data_str);
1027 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_full, data_str, strlen(data_str)))
1029 GNUNET_free (data_str);
1031 if (ph.measure_updates)
1033 data_upd_tmp = GNUNET_strdup (data_upd_str);
1034 GNUNET_free (data_upd_str);
1035 GNUNET_asprintf (&data_upd_str, "%s\n", data_upd_tmp);
1036 GNUNET_free (data_upd_tmp);
1038 fprintf (stderr, "Result updated solution: `%s'\n", data_upd_str);
1039 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data_upd_str, strlen(data_upd_str)))
1041 GNUNET_free (data_upd_str);
1045 if ((NULL != f_full) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_full)))
1046 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1048 GNUNET_free_non_null (data_fn_full);
1050 if ((NULL != f_update) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_update)))
1051 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1053 GNUNET_free_non_null (data_fn_update);
1058 do_delete_address (void *cls,
1059 const struct GNUNET_PeerIdentity *pid,
1062 struct ATS_Address *cur = value;
1064 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1065 "Deleting addresses for peer %u\n",
1067 GNUNET_assert (GNUNET_OK ==
1068 GNUNET_CONTAINER_multipeermap_remove (ph.addresses,
1071 ph.sf->s_del (ph.sf->cls, cur, GNUNET_NO);
1072 GNUNET_free_non_null (cur->atsi);
1079 * Run a performance iteration
1082 perf_run_iteration (void)
1086 int count_p = ph.N_peers_end;
1087 int count_a = ph.N_address;
1088 struct ATS_Address * cur_addr;
1091 ph.iterations_results[ph.current_iteration-1].results_array = GNUNET_malloc ((count_p + 1) * sizeof (struct Result *));
1092 if (ph.measure_updates)
1093 ph.iterations_results[ph.current_iteration-1].update_results_array = GNUNET_malloc ((count_p + 1) * sizeof (struct Result *));
1094 ph.peers = GNUNET_malloc ((count_p) * sizeof (struct PerfPeer));
1095 for (cp = 0; cp < count_p; cp++)
1096 perf_create_peer (cp);
1097 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1098 "Iteration %u of %u, added %u peers\n", ph.current_iteration, ph.total_iterations, cp);
1100 for (cp = 0; cp < count_p; cp++)
1102 fprintf (stderr,"%u..", cp);
1103 if (GNUNET_NO == ph.bulk_running)
1105 ph.bulk_running = GNUNET_YES;
1106 ph.sf->s_bulk_start (ph.sf->cls);
1108 ph.current_p = cp + 1;
1109 for (ca = 0; ca < count_a; ca++)
1111 cur_addr = perf_create_address (cp, ca);
1114 /* Random network selection */
1115 //net = 1 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_ATS_NetworkTypeCount - 1);
1116 /* Random equally distributed network selection */
1117 net = 1 + (ca % (GNUNET_ATS_NetworkTypeCount - 1));
1118 /* fprintf (stderr, "Network: %u `%s'\n",
1119 * mod_net , GNUNET_ATS_print_network_type(mod_net)); */
1121 cur_addr->atsi = GNUNET_new (struct GNUNET_ATS_Information);
1122 cur_addr->atsi_count = 1;
1123 cur_addr->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
1124 cur_addr->atsi[0].value = htonl (net);
1125 ph.sf->s_add (ph.sf->cls, cur_addr, net);
1127 ph.current_a = ca + 1;
1128 perf_address_initial_update (NULL, ph.addresses, cur_addr);
1129 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1130 "Adding address for peer %u address %u in network %s\n", cp, ca,
1131 GNUNET_ATS_print_network_type(net));
1133 /* Notify solver about request */
1134 ph.sf->s_get (ph.sf->cls, &ph.peers[cp].id);
1136 if (cp + 1 >= ph.N_peers_start)
1138 /* Disable bulk to solve the problem */
1139 if (GNUNET_YES == ph.bulk_running)
1141 ph.expecting_solution = GNUNET_YES;
1142 ph.bulk_running = GNUNET_NO;
1143 ph.sf->s_bulk_stop (ph.sf->cls);
1148 /* Problem is solved by the solver here due to unlocking */
1149 ph.expecting_solution = GNUNET_NO;
1151 /* Update the problem */
1152 if ((0 < ph.opt_update_percent) && (GNUNET_YES == ph.measure_updates))
1155 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1156 "Updating problem with %u peers and %u addresses\n", cp + 1, ca);
1158 ph.expecting_solution = GNUNET_YES;
1159 ph.performed_update = GNUNET_YES;
1160 if (GNUNET_NO == ph.bulk_running)
1162 ph.bulk_running = GNUNET_YES;
1163 ph.sf->s_bulk_start (ph.sf->cls);
1165 perf_update_all_addresses (cp + 1, ca, ph.opt_update_percent);
1166 ph.bulk_running = GNUNET_NO;
1167 ph.sf->s_bulk_stop (ph.sf->cls);
1168 /* Problem is solved by the solver here due to unlocking */
1169 ph.performed_update = GNUNET_NO;
1170 ph.expecting_solution = GNUNET_NO;
1172 GNUNET_assert (GNUNET_NO == ph.bulk_running);
1175 fprintf (stderr,"\n");
1176 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1177 "Done, cleaning up addresses\n");
1178 if (GNUNET_NO == ph.bulk_running)
1180 ph.sf->s_bulk_start (ph.sf->cls);
1181 ph.bulk_running = GNUNET_YES;
1184 for (cp = 0; cp < count_p; cp++)
1186 GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses,
1192 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1193 "Iteration done\n");
1194 GNUNET_free(ph.peers);
1199 run (void *cls, char * const *args, const char *cfgfile,
1200 const struct GNUNET_CONFIGURATION_Handle *cfg)
1202 GNUNET_log_setup ("perf-ats-solver", "WARNING", NULL);
1204 char *src_filename = GNUNET_strdup (__FILE__);
1205 char *test_filename = cls;
1208 struct GNUNET_CONFIGURATION_Handle *solver_cfg;
1209 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
1210 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
1214 /* Extract test name */
1215 if (NULL == (sep = (strstr (src_filename,".c"))))
1217 GNUNET_free (src_filename);
1224 if (NULL != (sep = strstr (test_filename, ".exe")))
1227 if (NULL == (solver = strstr (test_filename, src_filename)))
1229 GNUNET_free (src_filename);
1234 solver += strlen (src_filename) +1;
1236 if (0 == strcmp(solver, "proportional"))
1238 ph.ats_mode = MODE_PROPORTIONAL;
1239 ph.ats_string = "proportional";
1241 else if (0 == strcmp(solver, "mlp"))
1243 ph.ats_mode = MODE_MLP;
1244 ph.ats_string = "mlp";
1246 else if ((0 == strcmp(solver, "ril")))
1248 ph.ats_mode = MODE_RIL;
1249 ph.ats_string = "ril";
1253 GNUNET_free (src_filename);
1258 GNUNET_free (src_filename);
1260 /* Calculcate peers */
1261 if ((0 == ph.N_peers_start) && (0 == ph.N_peers_end))
1263 ph.N_peers_start = DEFAULT_PEERS_START;
1264 ph.N_peers_end = DEFAULT_PEERS_END;
1266 if (0 == ph.N_address)
1267 ph.N_address = DEFAULT_ADDRESSES;
1270 if (ph.N_peers_start != ph.N_peers_end)
1271 fprintf (stderr, "Benchmarking solver `%s' with %u to %u peers and %u addresses in %u iterations\n",
1272 ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address, ph.total_iterations);
1274 fprintf (stderr, "Benchmarking solver `%s' with %u peers and %u addresses in %u iterations\n",
1275 ph.ats_string, ph.N_peers_end, ph.N_address, ph.total_iterations);
1277 if (0 == ph.opt_update_percent)
1278 ph.opt_update_percent = DEFAULT_UPDATE_PERCENTAGE;
1281 solver_cfg = GNUNET_CONFIGURATION_create();
1282 if ((NULL == solver_cfg) || (GNUNET_SYSERR == (GNUNET_CONFIGURATION_load ( solver_cfg, "perf_ats_solver.conf"))))
1288 if (GNUNET_ATS_NetworkTypeCount != load_quotas (solver_cfg,
1289 quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount))
1296 /* Create array of DLL to store results for iterations */
1297 ph.iterations_results = GNUNET_malloc (sizeof (struct Iteration) * ph.total_iterations);
1300 ph.env.cfg = solver_cfg;
1301 ph.stat = GNUNET_STATISTICS_create ("ats", cfg);
1302 ph.env.stats = ph.stat;
1303 ph.addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
1304 ph.env.addresses = ph.addresses;
1305 ph.env.bandwidth_changed_cb = bandwidth_changed_cb;
1306 ph.env.get_preferences = &get_preferences_cb;
1307 ph.env.get_property = &get_property_cb;
1308 ph.env.network_count = GNUNET_ATS_NetworkTypeCount;
1309 ph.env.info_cb = &solver_info_cb;
1311 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
1313 ph.env.out_quota[c] = quotas_out[c];
1314 ph.env.in_quota[c] = quotas_in[c];
1315 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loading network quotas: `%s' %llu %llu \n",
1316 GNUNET_ATS_print_network_type (c),
1317 ph.env.out_quota[c],
1318 ph.env.in_quota[c]);
1320 GAS_normalization_start ();
1321 GAS_preference_init ();
1323 GNUNET_asprintf (&plugin, "libgnunet_plugin_ats_%s", ph.ats_string);
1324 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initializing solver `%s'\n"), ph.ats_string);
1325 if (NULL == (ph.sf = GNUNET_PLUGIN_load (plugin, &ph.env)))
1327 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1328 _("Failed to initialize solver `%s'!\n"), plugin);
1333 /* Do the benchmark */
1334 for (ph.current_iteration = 1; ph.current_iteration <= ph.total_iterations; ph.current_iteration++)
1336 fprintf (stderr, "Iteration %u of %u starting\n", ph.current_iteration, ph.total_iterations);
1337 perf_run_iteration ();
1338 evaluate (ph.current_iteration);
1339 fprintf (stderr, "Iteration %u of %u done\n", ph.current_iteration, ph.total_iterations);
1341 if (ph.create_datafile)
1342 write_all_iterations ();
1345 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Unloading solver `%s'\n"), ph.ats_string);
1346 GNUNET_PLUGIN_unload (plugin, ph.sf);
1348 GNUNET_free (plugin);
1349 for (c = 0; c < ph.total_iterations; c++ )
1351 for (c2 = ph.N_peers_start; c2 < ph.N_peers_end; c2++ )
1355 if (ph.measure_updates)
1356 GNUNET_free_non_null (ph.iterations_results[c].update_results_array[c2]);
1357 GNUNET_free (ph.iterations_results[c].results_array[c2]);
1359 if (ph.measure_updates)
1360 GNUNET_free (ph.iterations_results[c].update_results_array);
1361 GNUNET_free(ph.iterations_results[c].results_array);
1363 GNUNET_free (ph.iterations_results);
1365 GNUNET_CONFIGURATION_destroy (solver_cfg);
1366 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
1370 * Main function of the benchmark
1372 * @param argc argument count
1373 * @param argv argument values
1376 main (int argc, char *argv[])
1378 /* extract command line arguments */
1379 ph.opt_update_percent = 0;
1380 ph.N_peers_start = 0;
1383 ph.ats_string = NULL;
1384 ph.create_datafile = GNUNET_NO;
1385 ph.measure_updates = GNUNET_NO;
1386 ph.total_iterations = 1;
1388 static struct GNUNET_GETOPT_CommandLineOption options[] = {
1389 { 'a', "addresses", NULL,
1390 gettext_noop ("addresses to use"),
1391 1, &GNUNET_GETOPT_set_uint, &ph.N_address },
1392 { 's', "start", NULL,
1393 gettext_noop ("start with peer"),
1394 1, &GNUNET_GETOPT_set_uint, &ph.N_peers_start },
1396 gettext_noop ("end with peer"),
1397 1, &GNUNET_GETOPT_set_uint, &ph.N_peers_end },
1398 { 'i', "iterations", NULL,
1399 gettext_noop ("number of iterations used for averaging (default: 1)"),
1400 1, &GNUNET_GETOPT_set_uint, &ph.total_iterations },
1401 { 'p', "percentage", NULL,
1402 gettext_noop ("update a fix percentage of addresses"),
1403 1, &GNUNET_GETOPT_set_uint, &ph.opt_update_percent },
1404 { 'd', "data", NULL,
1405 gettext_noop ("create data file"),
1406 0, &GNUNET_GETOPT_set_one, &ph.create_datafile},
1407 { 'u', "update", NULL,
1408 gettext_noop ("measure updates"),
1409 0, &GNUNET_GETOPT_set_one, &ph.measure_updates},
1410 GNUNET_GETOPT_OPTION_END
1413 GNUNET_PROGRAM_run (argc, argv, argv[0], NULL, options, &run, argv[0]);
1417 /* end of file perf_ats_solver.c */