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;
117 struct Result *current_result;
123 * Solver description as string
128 * Configured ATS solver
133 * #peers to start benchmarking with
138 * #peers to end benchmarking with
143 * #addresses to benchmarking with
148 * Percentage of peers to update
150 int opt_update_percent;
153 * Create gnuplot file
163 * Is a bulk operation running?
168 * Is a bulk operation running?
170 int expecting_solution;
182 enum GAS_Solver_Additional_Information info;
184 struct GNUNET_TIME_Relative d_setup;
185 struct GNUNET_TIME_Relative d_lp;
186 struct GNUNET_TIME_Relative d_mlp;
187 struct GNUNET_TIME_Relative d_total;
189 struct GNUNET_TIME_Absolute s_setup;
190 struct GNUNET_TIME_Absolute s_lp;
191 struct GNUNET_TIME_Absolute s_mlp;
192 struct GNUNET_TIME_Absolute s_total;
194 struct GNUNET_TIME_Absolute e_setup;
195 struct GNUNET_TIME_Absolute e_lp;
196 struct GNUNET_TIME_Absolute e_mlp;
197 struct GNUNET_TIME_Absolute e_total;
202 struct GNUNET_PeerIdentity id;
204 struct ATS_Address *head;
205 struct ATS_Address *tail;
208 static struct PerfHandle ph;
219 //static struct GNUNET_ATS_Information ats[2];
227 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
231 if (NULL != addresses)
233 GNUNET_CONTAINER_multihashmap_iterate (addresses, &addr_it, NULL);
234 GNUNET_CONTAINER_multihashmap_destroy (addresses);
237 if (NULL != ph.peers)
239 GNUNET_free(ph.peers);
242 GAS_normalization_stop ();
248 perf_create_peer (int cp)
251 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
252 &ph.peers[cp].id, sizeof (struct GNUNET_PeerIdentity));
253 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp,
254 GNUNET_i2s (&ph.peers[cp].id));
260 perf_update_address (struct ATS_Address *cur)
265 r_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2);
269 r_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
270 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
271 "Updating peer `%s' address %p type %s val %u\n",
272 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DELAY", r_val);
273 ph.env.sf.s_address_update_property (ph.solver, cur,
274 GNUNET_ATS_QUALITY_NET_DELAY,
275 r_val, (double) (100 + r_val / 100));
278 r_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10);
280 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
281 "Updating peer `%s' address %p type %s val %u\n",
282 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE", r_val);
283 ph.env.sf.s_address_update_property (ph.solver, cur,
284 GNUNET_ATS_QUALITY_NET_DISTANCE,
285 r_val, (double) (100 + r_val) / 100);
290 ph.env.sf.s_address_update_inuse (ph.solver, cur, GNUNET_YES);
295 bandwidth_changed_cb (void *cls,
296 struct ATS_Address *address)
298 if ( (0 == ntohl (address->assigned_bw_out.value__)) &&
299 (0 == ntohl (address->assigned_bw_in.value__)) )
302 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
303 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
304 GNUNET_i2s (&address->peer),
306 (unsigned int) ntohl (address->assigned_bw_out.value__),
307 (unsigned int) ntohl (address->assigned_bw_in.value__));
308 if (GNUNET_YES == ph.bulk_running)
315 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
317 return GAS_normalization_get_preferences_by_peer (id);
322 get_property_cb (void *cls, const struct ATS_Address *address)
324 return GAS_normalization_get_properties ((struct ATS_Address *) address);
328 normalized_property_changed_cb (void *cls, struct ATS_Address *peer,
329 uint32_t type, double prop_rel)
335 perf_address_initial_update (void *solver,
336 struct GNUNET_CONTAINER_MultiPeerMap * addresses,
337 struct ATS_Address *address)
339 ph.env.sf.s_address_update_property (solver, address, GNUNET_ATS_QUALITY_NET_DELAY,
341 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100))
344 ph.env.sf.s_address_update_property (solver, address,
345 GNUNET_ATS_QUALITY_NET_DISTANCE, 10,
346 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100))
351 perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percentage_peers)
353 struct ATS_Address *cur_address;
362 count = cp * ((double) percentage_peers / 100);
363 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
364 "Updating %u of %u peers \n", count, cp);
366 for (c_peer = 0; c_peer < cp; c_peer++)
371 while (c_select < count)
373 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, cp);
377 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
378 "Updating peer [%u] \n", r);
382 for (c_cur_p = 0; c_cur_p < cp; c_cur_p++)
386 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca);
387 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
388 "Updating peer [%u] address [%u]\n", c_cur_p, r);
391 for (cur_address = ph.peers[c_cur_p].head; NULL != cur_address; cur_address = cur_address->next)
394 perf_update_address (cur_address);
403 static struct ATS_Address *
404 perf_create_address (int cp, int ca)
406 struct ATS_Address *a;
407 a = create_address (&ph.peers[cp].id,
408 "Test 1", "test 1", strlen ("test 1") + 1, 0);
409 GNUNET_CONTAINER_DLL_insert (ph.peers[cp].head, ph.peers[cp].tail, a);
410 GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a,
411 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
416 solver_info_cb (void *cls,
417 enum GAS_Solver_Operation op,
418 enum GAS_Solver_Status stat,
419 enum GAS_Solver_Additional_Information add)
424 add_info = "GAS_INFO_NONE";
427 add_info = "GAS_INFO_MLP_FULL";
429 case GAS_INFO_UPDATED:
430 add_info = "GAS_INFO_MLP_UPDATED";
432 case GAS_INFO_PROP_ALL:
433 add_info = "GAS_INFO_PROP_ALL";
435 case GAS_INFO_PROP_SINGLE:
436 add_info = "GAS_INFO_PROP_SINGLE";
439 add_info = "INVALID";
446 case GAS_OP_SOLVE_START:
447 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
448 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
449 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
450 if (GNUNET_NO == ph.expecting_solution)
452 /* We do not expect a solution at the moment */
457 if ((GAS_STAT_SUCCESS == stat) && (NULL == ph.current_result))
459 /* Create new result */
460 tmp = GNUNET_new (struct Result);
461 ph.current_result = tmp;
462 GNUNET_CONTAINER_DLL_insert_tail(ph.head, ph.tail, tmp);
463 ph.current_result->addresses = ph.current_a;
464 ph.current_result->peers = ph.current_p;
465 ph.current_result->s_total = GNUNET_TIME_absolute_get();
466 ph.current_result->d_total = GNUNET_TIME_UNIT_FOREVER_REL;
467 ph.current_result->d_setup = GNUNET_TIME_UNIT_FOREVER_REL;
468 ph.current_result->d_lp = GNUNET_TIME_UNIT_FOREVER_REL;
469 ph.current_result->d_mlp = GNUNET_TIME_UNIT_FOREVER_REL;
470 ph.current_result->info = add;
471 if (add == GAS_INFO_UPDATED)
472 ph.current_result->update = GNUNET_YES;
474 ph.current_result->update = GNUNET_NO;
477 case GAS_OP_SOLVE_STOP:
478 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
479 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
480 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
481 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
483 /* We do not expect a solution at the moment */
487 if (NULL != ph.current_result)
489 /* Finalize result */
490 ph.current_result->e_total = GNUNET_TIME_absolute_get ();
491 ph.current_result->d_total = GNUNET_TIME_absolute_get_difference (
492 ph.current_result->s_total, ph.current_result->e_total);
494 ph.current_result = NULL;
497 case GAS_OP_SOLVE_SETUP_START:
498 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
499 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
500 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
501 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
506 ph.current_result->s_setup = GNUNET_TIME_absolute_get ();
509 case GAS_OP_SOLVE_SETUP_STOP:
510 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
511 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
512 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
513 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
518 ph.current_result->e_setup = GNUNET_TIME_absolute_get ();
519 ph.current_result->d_setup = GNUNET_TIME_absolute_get_difference (
520 ph.current_result->s_setup, ph.current_result->e_setup);
523 case GAS_OP_SOLVE_MLP_LP_START:
524 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
525 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
526 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
527 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
532 ph.current_result->s_lp = GNUNET_TIME_absolute_get ();
534 case GAS_OP_SOLVE_MLP_LP_STOP:
535 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
536 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
537 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
538 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
543 ph.current_result->e_lp = GNUNET_TIME_absolute_get ();
544 ph.current_result->d_lp = GNUNET_TIME_absolute_get_difference (
545 ph.current_result->s_lp, ph.current_result->e_lp);
548 case GAS_OP_SOLVE_MLP_MLP_START:
549 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
550 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
551 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
552 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
557 ph.current_result->s_mlp = GNUNET_TIME_absolute_get ();
559 case GAS_OP_SOLVE_MLP_MLP_STOP:
560 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
561 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
562 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
563 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
568 ph.current_result->e_mlp = GNUNET_TIME_absolute_get ();
569 ph.current_result->d_mlp = GNUNET_TIME_absolute_get_difference (
570 ph.current_result->s_mlp, ph.current_result->e_mlp);
572 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
573 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
574 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
575 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
577 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
578 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
579 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
580 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
588 write_gnuplot_script (char * data_fn, int full)
590 struct GNUNET_DISK_FileHandle *f;
596 switch (ph.ats_mode) {
597 case MODE_PROPORTIONAL:
598 if (GNUNET_YES == full)
599 template = GNUPLOT_PROP_TEMPLATE;
601 template = GNUPLOT_PROP_UPDATE_TEMPLATE;
604 if (GNUNET_YES == full)
605 template = GNUPLOT_MLP_TEMPLATE;
607 template = GNUPLOT_MLP_UPDATE_TEMPLATE;
610 if (GNUNET_YES == full)
611 template = GNUPLOT_RIL_TEMPLATE;
613 template = GNUPLOT_RIL_UPDATE_TEMPLATE;
620 if (GNUNET_YES == full)
621 GNUNET_asprintf (&gfn, "perf_%s_full_%u_%u_%u.gnuplot", ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address);
623 GNUNET_asprintf (&gfn, "perf_%s_update_%u_%u_%u.gnuplot", ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address);
625 f = GNUNET_DISK_file_open (gfn,
626 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
627 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
630 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
635 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, template, strlen(template)))
636 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
639 if (MODE_PROPORTIONAL == ph.ats_mode)
641 GNUNET_asprintf (&data, "plot '%s' using 1:%u with lines title 'Total time to solve'\n" \
645 else if (MODE_MLP == ph.ats_mode)
647 GNUNET_asprintf (&data, "plot '%s' using 1:%u with lines title 'Total time to solve',\\\n" \
648 "'%s' using 1:%u with lines title 'Time to setup',\\\n"
649 "'%s' using 1:%u with lines title 'Time to solve LP',\\\n"
650 "'%s' using 1:%u with lines title 'Total time to solve MLP'\n" \
657 else if (MODE_RIL == ph.ats_mode)
659 GNUNET_asprintf (&data,
660 "plot '%s' using 1:%u with lines title 'Total time to solve'\n" \
665 if ((NULL != data) &&
666 (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen(data))))
667 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
668 "Cannot write data to plot file `%s'\n",
670 GNUNET_free_non_null (data);
672 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
673 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
674 "Cannot close gnuplot file `%s'\n",
677 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
678 "Data successfully written to plot file `%s'\n",
688 struct GNUNET_DISK_FileHandle *f_full;
689 struct GNUNET_DISK_FileHandle *f_update;
691 char * data_fn_update;
707 GNUNET_asprintf (&data_fn_full,
708 "perf_%s_full_%u_%u_%u.data",
713 f_full = GNUNET_DISK_file_open (data_fn_full,
714 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
715 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
718 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
719 "Cannot open gnuplot file `%s'\n",
721 GNUNET_free (data_fn_full);
724 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
725 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_full, data, strlen(data)))
726 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
727 "Cannot write data to log file `%s'\n",
729 write_gnuplot_script (data_fn_full, GNUNET_YES);
732 data_fn_update = NULL;
733 if ((ph.create_plot) && (GNUNET_YES == ph.measure_updates))
735 GNUNET_asprintf (&data_fn_update, "perf_%s_update_%u_%u_%u.data", ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address);
736 f_update = GNUNET_DISK_file_open (data_fn_update,
737 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
738 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
739 if (NULL == f_update)
741 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
742 "Cannot open gnuplot file `%s'\n", data_fn_update);
743 GNUNET_free (data_fn_update);
745 GNUNET_DISK_file_close (f_full);
746 GNUNET_free (data_fn_full);
749 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
750 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data)))
751 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
752 "Cannot write data to log file `%s'\n",
754 write_gnuplot_script (data_fn_update, GNUNET_NO);
758 while (NULL != (cur = next))
767 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_total.rel_value_us)
770 "Total time to solve %s for %u peers %u addresses: %llu us\n",
771 (GNUNET_YES == cur->update) ? "updated" : "full",
772 cur->peers, cur->addresses, (unsigned long long) cur->d_total.rel_value_us);
773 GNUNET_asprintf(&str_d_total,
775 (unsigned long long) cur->d_total.rel_value_us);
778 GNUNET_asprintf(&str_d_total, "-1");
779 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_setup.rel_value_us)
781 fprintf (stderr, "Total time to setup %s %u peers %u addresses: %llu us\n",
782 (GNUNET_YES == cur->update) ? "updated" : "full",
783 cur->peers, cur->addresses, (unsigned long long )cur->d_setup.rel_value_us);
784 GNUNET_asprintf(&str_d_setup, "%llu", (unsigned long long )cur->d_setup.rel_value_us);
787 GNUNET_asprintf(&str_d_setup, "-1");
788 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_lp.rel_value_us)
791 "Total time to solve %s LP for %u peers %u addresses: %llu us\n",
792 (GNUNET_YES == cur->update) ? "updated" : "full",
795 (unsigned long long )cur->d_lp.rel_value_us);
796 GNUNET_asprintf (&str_d_lp,
798 (unsigned long long )cur->d_lp.rel_value_us);
801 GNUNET_asprintf (&str_d_lp, "-1");
802 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_mlp.rel_value_us)
804 fprintf (stderr, "Total time to solve %s MLP for %u peers %u addresses: %llu us\n",
805 (GNUNET_YES == cur->update) ? "updated" : "full",
806 cur->peers, cur->addresses, (unsigned long long )cur->d_mlp.rel_value_us);
807 GNUNET_asprintf (&str_d_mlp,
809 (unsigned long long )cur->d_mlp.rel_value_us);
812 GNUNET_asprintf (&str_d_mlp, "-1");
815 if (GNUNET_YES == ph.create_plot)
818 GNUNET_asprintf (&data,
819 "%u;%u;%s;%s;%s;%s\n",
820 cur->peers, cur->addresses,
825 if (cur->update == GNUNET_NO)
827 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_full, data, strlen(data)))
828 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
829 "Cannot write data to log file `%s'\n",
832 if ((cur->update == GNUNET_YES) && (NULL != f_update))
834 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data)))
835 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
836 "Cannot write data to log file `%s'\n",
841 GNUNET_free_non_null (str_d_total);
842 GNUNET_free_non_null (str_d_setup);
843 GNUNET_free_non_null (str_d_lp);
844 GNUNET_free_non_null (str_d_mlp);
846 GNUNET_CONTAINER_DLL_remove (ph.head, ph.tail, cur);
850 if ((NULL != f_full) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_full)))
851 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
853 GNUNET_free_non_null (data_fn_full);
855 if ((NULL != f_update) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_update)))
856 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
858 GNUNET_free_non_null (data_fn_update);
865 struct ATS_Address *cur;
866 struct ATS_Address *next;
869 int count_p = ph.N_peers_end;
870 int count_a = ph.N_address;
871 struct ATS_Address * cur_addr;
874 ph.peers = GNUNET_malloc ((count_p) * sizeof (struct PerfPeer));
876 for (cp = 0; cp < count_p; cp++)
877 perf_create_peer (cp);
878 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
879 "Added %u peers\n", cp);
881 for (cp = 0; cp < count_p; cp++)
883 if (GNUNET_NO == ph.bulk_running)
885 ph.bulk_running = GNUNET_YES;
886 ph.env.sf.s_bulk_start (ph.solver);
888 ph.current_p = cp + 1;
889 for (ca = 0; ca < count_a; ca++)
891 cur_addr = perf_create_address (cp, ca);
893 ph.env.sf.s_add (ph.solver, cur_addr, GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_ATS_NetworkTypeCount));
894 ph.current_a = ca + 1;
895 perf_address_initial_update (ph.solver, ph.addresses, cur_addr);
896 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
897 "Adding address for peer %u address %u\n", cp, ca);
899 /* Notify solver about request */
900 ph.env.sf.s_get (ph.solver, &ph.peers[cp].id);
902 if (cp + 1 >= ph.N_peers_start)
904 /* Disable bulk to solve the problem */
905 if (GNUNET_YES == ph.bulk_running)
907 ph.expecting_solution = GNUNET_YES;
908 ph.bulk_running = GNUNET_NO;
909 ph.env.sf.s_bulk_stop (ph.solver);
916 /* Problem is solved by the solver here due to unlocking */
917 ph.expecting_solution = GNUNET_NO;
919 /* Update the problem */
920 if ((0 < ph.opt_update_percent) && (GNUNET_YES == ph.measure_updates))
923 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
924 "Updating problem with %u peers and %u addresses\n", cp + 1, ca);
926 ph.expecting_solution = GNUNET_YES;
927 if (GNUNET_NO == ph.bulk_running)
929 ph.bulk_running = GNUNET_YES;
930 ph.env.sf.s_bulk_start (ph.solver);
932 perf_update_all_addresses (cp + 1, ca, ph.opt_update_percent);
933 ph.bulk_running = GNUNET_NO;
934 ph.env.sf.s_bulk_stop (ph.solver);
935 /* Problem is solved by the solver here due to unlocking */
936 ph.expecting_solution = GNUNET_NO;
938 GNUNET_assert (GNUNET_NO == ph.bulk_running);
942 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
943 "Done, cleaning up addresses\n");
944 if (GNUNET_NO == ph.bulk_running)
946 ph.env.sf.s_bulk_start (ph.solver);
947 ph.bulk_running = GNUNET_YES;
950 for (cp = 0; cp < count_p; cp++)
952 for (cur = ph.peers[cp].head; cur != NULL ; cur = next)
954 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
955 "Deleting addresses for peer %u\n", cp);
956 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (ph.addresses,
957 &ph.peers[cp].id, cur));
958 ph.env.sf.s_del (ph.solver, cur, GNUNET_NO);
960 GNUNET_CONTAINER_DLL_remove(ph.peers[cp].head, ph.peers[cp].tail, cur);
965 GNUNET_free(ph.peers);
972 run (void *cls, char * const *args, const char *cfgfile,
973 const struct GNUNET_CONFIGURATION_Handle *cfg)
975 GNUNET_log_setup ("perf-ats-solver", "WARNING", NULL);
977 char *src_filename = GNUNET_strdup (__FILE__);
978 char *test_filename = cls;
981 struct GNUNET_CONFIGURATION_Handle *solver_cfg;
982 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
983 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
986 /* Extract test name */
987 if (NULL == (sep = (strstr (src_filename,".c"))))
989 GNUNET_free (src_filename);
996 if (NULL != (sep = strstr (test_filename, ".exe")))
999 if (NULL == (solver = strstr (test_filename, src_filename)))
1001 GNUNET_free (src_filename);
1006 solver += strlen (src_filename) +1;
1008 if (0 == strcmp(solver, "proportional"))
1010 ph.ats_mode = MODE_PROPORTIONAL;
1011 ph.ats_string = "proportional";
1013 else if (0 == strcmp(solver, "mlp"))
1015 ph.ats_mode = MODE_MLP;
1016 ph.ats_string = "mlp";
1018 else if ((0 == strcmp(solver, "ril")))
1020 ph.ats_mode = MODE_RIL;
1021 ph.ats_string = "ril";
1025 GNUNET_free (src_filename);
1030 GNUNET_free (src_filename);
1032 /* Calculcate peers */
1033 if ((0 == ph.N_peers_start) && (0 == ph.N_peers_end))
1035 ph.N_peers_start = DEFAULT_PEERS_START;
1036 ph.N_peers_end = DEFAULT_PEERS_END;
1038 if (0 == ph.N_address)
1039 ph.N_address = DEFAULT_ADDRESSES;
1041 if (ph.N_peers_start != ph.N_peers_end)
1042 fprintf (stderr, "Benchmarking solver `%s' with %u to %u peers and %u addresses\n",
1043 ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address);
1045 fprintf (stderr, "Benchmarking solver `%s' with %u peers and %u addresses\n",
1046 ph.ats_string, ph.N_peers_end, ph.N_address);
1048 if (0 == ph.opt_update_percent)
1049 ph.opt_update_percent = DEFAULT_UPDATE_PERCENTAGE;
1052 solver_cfg = GNUNET_CONFIGURATION_create();
1053 if ((NULL == solver_cfg) || (GNUNET_SYSERR == (GNUNET_CONFIGURATION_load ( solver_cfg, "perf_ats_solver.conf"))))
1059 if (GNUNET_ATS_NetworkTypeCount != load_quotas (solver_cfg,
1060 quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount))
1068 ph.env.cfg = solver_cfg;
1069 ph.stat = GNUNET_STATISTICS_create ("ats", cfg);
1070 ph.env.stats = ph.stat;
1071 ph.addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
1072 ph.env.addresses = ph.addresses;
1073 ph.env.bandwidth_changed_cb = bandwidth_changed_cb;
1074 ph.env.get_preferences = &get_preferences_cb;
1075 ph.env.get_property = &get_property_cb;
1076 ph.env.network_count = GNUNET_ATS_NetworkTypeCount;
1077 ph.env.info_cb = &solver_info_cb;
1078 ph.env.info_cb_cls = NULL;
1080 int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
1081 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
1083 ph.env.networks[c] = networks[c];
1084 ph.env.out_quota[c] = quotas_out[c];
1085 ph.env.in_quota[c] = quotas_in[c];
1086 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loading network quotas: `%s' %llu %llu \n",
1087 GNUNET_ATS_print_network_type(ph.env.networks[c]),
1088 ph.env.out_quota[c],
1089 ph.env.in_quota[c]);
1091 GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL );
1093 GNUNET_asprintf (&plugin, "libgnunet_plugin_ats_%s", ph.ats_string);
1094 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initializing solver `%s'\n"), ph.ats_string);
1095 if (NULL == (ph.solver = GNUNET_PLUGIN_load (plugin, &ph.env)))
1097 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver `%s'!\n"), plugin);
1106 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Unloading solver `%s'\n"), ph.ats_string);
1107 GNUNET_PLUGIN_unload (plugin, ph.solver);
1108 GNUNET_free (plugin);
1109 GNUNET_CONFIGURATION_destroy (solver_cfg);
1114 main (int argc, char *argv[])
1116 /* extract command line arguments */
1117 ph.opt_update_percent = 0;
1118 ph.N_peers_start = 0;
1121 ph.ats_string = NULL;
1122 ph.create_plot = GNUNET_NO;
1123 ph.measure_updates = GNUNET_NO;
1125 static struct GNUNET_GETOPT_CommandLineOption options[] = {
1126 { 'a', "addresses", NULL,
1127 gettext_noop ("addresses to use"),
1128 1, &GNUNET_GETOPT_set_uint, &ph.N_address },
1129 { 's', "start", NULL,
1130 gettext_noop ("start with peer"),
1131 1, &GNUNET_GETOPT_set_uint, &ph.N_peers_start },
1133 gettext_noop ("end with peer"),
1134 1, &GNUNET_GETOPT_set_uint, &ph.N_peers_end },
1135 { 'p', "percentage", NULL,
1136 gettext_noop ("update a fix percentage of addresses"),
1137 1, &GNUNET_GETOPT_set_uint, &ph.opt_update_percent },
1138 { 'g', "gnuplot", NULL,
1139 gettext_noop ("create GNUplot file"),
1140 0, &GNUNET_GETOPT_set_one, &ph.create_plot},
1141 { 'u', "update", NULL,
1142 gettext_noop ("measure updates"),
1143 0, &GNUNET_GETOPT_set_one, &ph.measure_updates},
1144 GNUNET_GETOPT_OPTION_END
1147 GNUNET_PROGRAM_run (argc, argv, argv[0], NULL, options, &run, argv[0]);
1152 /* end of file perf_ats_solver.c */