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 result with length #peers
121 struct Result *averaged_result;
123 struct Result *current_result;
129 * Solver description as string
134 * Configured ATS solver
139 * #peers to start benchmarking with
144 * #peers to end benchmarking with
149 * #addresses to benchmarking with
154 * Percentage of peers to update
156 int opt_update_percent;
159 * Create gnuplot file
169 * Number of iterations
176 int current_iteration;
179 * Is a bulk operation running?
184 * Is a bulk operation running?
186 int expecting_solution;
191 struct Result *result_head;
193 struct Result *result_tail;
205 enum GAS_Solver_Additional_Information info;
207 struct GNUNET_TIME_Relative d_setup;
208 struct GNUNET_TIME_Relative d_lp;
209 struct GNUNET_TIME_Relative d_mlp;
210 struct GNUNET_TIME_Relative d_total;
212 struct GNUNET_TIME_Absolute s_setup;
213 struct GNUNET_TIME_Absolute s_lp;
214 struct GNUNET_TIME_Absolute s_mlp;
215 struct GNUNET_TIME_Absolute s_total;
217 struct GNUNET_TIME_Absolute e_setup;
218 struct GNUNET_TIME_Absolute e_lp;
219 struct GNUNET_TIME_Absolute e_mlp;
220 struct GNUNET_TIME_Absolute e_total;
225 struct GNUNET_PeerIdentity id;
227 struct ATS_Address *head;
228 struct ATS_Address *tail;
231 static struct PerfHandle ph;
242 //static struct GNUNET_ATS_Information ats[2];
250 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
254 if (NULL != addresses)
256 GNUNET_CONTAINER_multihashmap_iterate (addresses, &addr_it, NULL);
257 GNUNET_CONTAINER_multihashmap_destroy (addresses);
260 if (NULL != ph.peers)
262 GNUNET_free(ph.peers);
265 GAS_normalization_stop ();
271 perf_create_peer (int cp)
274 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
275 &ph.peers[cp].id, sizeof (struct GNUNET_PeerIdentity));
276 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp,
277 GNUNET_i2s (&ph.peers[cp].id));
283 perf_update_address (struct ATS_Address *cur)
288 r_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2);
292 r_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
293 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
294 "Updating peer `%s' address %p type %s val %u\n",
295 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DELAY", r_val);
296 ph.env.sf.s_address_update_property (ph.solver, cur,
297 GNUNET_ATS_QUALITY_NET_DELAY,
298 r_val, (double) (100 + r_val / 100));
301 r_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10);
303 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
304 "Updating peer `%s' address %p type %s val %u\n",
305 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE", r_val);
306 ph.env.sf.s_address_update_property (ph.solver, cur,
307 GNUNET_ATS_QUALITY_NET_DISTANCE,
308 r_val, (double) (100 + r_val) / 100);
313 ph.env.sf.s_address_update_inuse (ph.solver, cur, GNUNET_YES);
318 bandwidth_changed_cb (void *cls,
319 struct ATS_Address *address)
321 if ( (0 == ntohl (address->assigned_bw_out.value__)) &&
322 (0 == ntohl (address->assigned_bw_in.value__)) )
325 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
326 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
327 GNUNET_i2s (&address->peer),
329 (unsigned int) ntohl (address->assigned_bw_out.value__),
330 (unsigned int) ntohl (address->assigned_bw_in.value__));
331 if (GNUNET_YES == ph.bulk_running)
338 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
340 return GAS_normalization_get_preferences_by_peer (id);
345 get_property_cb (void *cls, const struct ATS_Address *address)
347 return GAS_normalization_get_properties ((struct ATS_Address *) address);
351 normalized_property_changed_cb (void *cls, struct ATS_Address *peer,
352 uint32_t type, double prop_rel)
358 perf_address_initial_update (void *solver,
359 struct GNUNET_CONTAINER_MultiPeerMap * addresses,
360 struct ATS_Address *address)
362 ph.env.sf.s_address_update_property (solver, address, GNUNET_ATS_QUALITY_NET_DELAY,
364 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100))
367 ph.env.sf.s_address_update_property (solver, address,
368 GNUNET_ATS_QUALITY_NET_DISTANCE, 10,
369 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100))
374 perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percentage_peers)
376 struct ATS_Address *cur_address;
385 count = cp * ((double) percentage_peers / 100);
386 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
387 "Updating %u of %u peers \n", count, cp);
389 for (c_peer = 0; c_peer < cp; c_peer++)
394 while (c_select < count)
396 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, cp);
400 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
401 "Updating peer [%u] \n", r);
405 for (c_cur_p = 0; c_cur_p < cp; c_cur_p++)
409 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca);
410 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
411 "Updating peer [%u] address [%u]\n", c_cur_p, r);
414 for (cur_address = ph.peers[c_cur_p].head; NULL != cur_address; cur_address = cur_address->next)
417 perf_update_address (cur_address);
426 static struct ATS_Address *
427 perf_create_address (int cp, int ca)
429 struct ATS_Address *a;
430 a = create_address (&ph.peers[cp].id,
431 "Test 1", "test 1", strlen ("test 1") + 1, 0);
432 GNUNET_CONTAINER_DLL_insert (ph.peers[cp].head, ph.peers[cp].tail, a);
433 GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a,
434 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
439 solver_info_cb (void *cls,
440 enum GAS_Solver_Operation op,
441 enum GAS_Solver_Status stat,
442 enum GAS_Solver_Additional_Information add)
447 add_info = "GAS_INFO_NONE";
450 add_info = "GAS_INFO_MLP_FULL";
452 case GAS_INFO_UPDATED:
453 add_info = "GAS_INFO_MLP_UPDATED";
455 case GAS_INFO_PROP_ALL:
456 add_info = "GAS_INFO_PROP_ALL";
458 case GAS_INFO_PROP_SINGLE:
459 add_info = "GAS_INFO_PROP_SINGLE";
462 add_info = "INVALID";
469 case GAS_OP_SOLVE_START:
470 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
471 "Solver notifies `%s' with result `%s' `%s' in iteration %u \n", "GAS_OP_SOLVE_START",
472 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info, ph.current_iteration);
473 if (GNUNET_NO == ph.expecting_solution)
475 /* We do not expect a solution at the moment */
480 if ((GAS_STAT_SUCCESS == stat) && (NULL == ph.current_result))
482 /* Create new result */
483 tmp = GNUNET_new (struct Result);
484 ph.current_result = tmp;
485 GNUNET_CONTAINER_DLL_insert_tail(ph.iterations_results[ph.current_iteration-1].result_head,
486 ph.iterations_results[ph.current_iteration-1].result_tail, tmp);
487 ph.current_result->addresses = ph.current_a;
488 ph.current_result->peers = ph.current_p;
489 ph.current_result->s_total = GNUNET_TIME_absolute_get();
490 ph.current_result->d_total = GNUNET_TIME_UNIT_FOREVER_REL;
491 ph.current_result->d_setup = GNUNET_TIME_UNIT_FOREVER_REL;
492 ph.current_result->d_lp = GNUNET_TIME_UNIT_FOREVER_REL;
493 ph.current_result->d_mlp = GNUNET_TIME_UNIT_FOREVER_REL;
494 ph.current_result->info = add;
495 if (add == GAS_INFO_UPDATED)
496 ph.current_result->update = GNUNET_YES;
498 ph.current_result->update = GNUNET_NO;
501 case GAS_OP_SOLVE_STOP:
502 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
503 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
504 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
505 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
507 /* We do not expect a solution at the moment */
511 if (NULL != ph.current_result)
513 /* Finalize result */
514 ph.current_result->e_total = GNUNET_TIME_absolute_get ();
515 ph.current_result->d_total = GNUNET_TIME_absolute_get_difference (
516 ph.current_result->s_total, ph.current_result->e_total);
518 ph.current_result = NULL;
521 case GAS_OP_SOLVE_SETUP_START:
522 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
523 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
524 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
525 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
530 ph.current_result->s_setup = GNUNET_TIME_absolute_get ();
533 case GAS_OP_SOLVE_SETUP_STOP:
534 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
535 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
536 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
537 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
542 ph.current_result->e_setup = GNUNET_TIME_absolute_get ();
543 ph.current_result->d_setup = GNUNET_TIME_absolute_get_difference (
544 ph.current_result->s_setup, ph.current_result->e_setup);
547 case GAS_OP_SOLVE_MLP_LP_START:
548 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
549 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
550 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
551 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
556 ph.current_result->s_lp = GNUNET_TIME_absolute_get ();
558 case GAS_OP_SOLVE_MLP_LP_STOP:
559 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
560 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
561 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
562 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
567 ph.current_result->e_lp = GNUNET_TIME_absolute_get ();
568 ph.current_result->d_lp = GNUNET_TIME_absolute_get_difference (
569 ph.current_result->s_lp, ph.current_result->e_lp);
572 case GAS_OP_SOLVE_MLP_MLP_START:
573 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
574 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
575 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
576 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
581 ph.current_result->s_mlp = GNUNET_TIME_absolute_get ();
583 case GAS_OP_SOLVE_MLP_MLP_STOP:
584 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
585 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
586 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
587 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
592 ph.current_result->e_mlp = GNUNET_TIME_absolute_get ();
593 ph.current_result->d_mlp = GNUNET_TIME_absolute_get_difference (
594 ph.current_result->s_mlp, ph.current_result->e_mlp);
596 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
597 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
598 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
599 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
601 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
602 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
603 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
604 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
612 write_gnuplot_script (char * data_fn, int full)
614 struct GNUNET_DISK_FileHandle *f;
620 switch (ph.ats_mode) {
621 case MODE_PROPORTIONAL:
622 if (GNUNET_YES == full)
623 template = GNUPLOT_PROP_TEMPLATE;
625 template = GNUPLOT_PROP_UPDATE_TEMPLATE;
628 if (GNUNET_YES == full)
629 template = GNUPLOT_MLP_TEMPLATE;
631 template = GNUPLOT_MLP_UPDATE_TEMPLATE;
634 if (GNUNET_YES == full)
635 template = GNUPLOT_RIL_TEMPLATE;
637 template = GNUPLOT_RIL_UPDATE_TEMPLATE;
644 if (GNUNET_YES == full)
645 GNUNET_asprintf (&gfn, "perf_%s_full_%u_%u_%u.gnuplot", ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address);
647 GNUNET_asprintf (&gfn, "perf_%s_update_%u_%u_%u.gnuplot", ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address);
649 f = GNUNET_DISK_file_open (gfn,
650 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
651 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
654 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
659 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, template, strlen(template)))
660 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
663 if (MODE_PROPORTIONAL == ph.ats_mode)
665 GNUNET_asprintf (&data, "plot '%s' using 1:%u with lines title 'Total time to solve'\n" \
669 else if (MODE_MLP == ph.ats_mode)
671 GNUNET_asprintf (&data, "plot '%s' using 1:%u with lines title 'Total time to solve',\\\n" \
672 "'%s' using 1:%u with lines title 'Time to setup',\\\n"
673 "'%s' using 1:%u with lines title 'Time to solve LP',\\\n"
674 "'%s' using 1:%u with lines title 'Total time to solve MLP'\n" \
681 else if (MODE_RIL == ph.ats_mode)
683 GNUNET_asprintf (&data,
684 "plot '%s' using 1:%u with lines title 'Total time to solve'\n" \
689 if ((NULL != data) &&
690 (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen(data))))
691 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
692 "Cannot write data to plot file `%s'\n",
694 GNUNET_free_non_null (data);
696 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
697 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
698 "Cannot close gnuplot file `%s'\n",
701 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
702 "Data successfully written to plot file `%s'\n",
709 * Evaluate results for a specific iteration
711 * @param iteration the iteration to evaluate
715 evaluate (int iteration)
717 struct GNUNET_DISK_FileHandle *f_full;
718 struct GNUNET_DISK_FileHandle *f_update;
720 char * data_fn_update;
736 GNUNET_asprintf (&data_fn_full,
737 "perf_%s_full_%u_%u_%u.data",
742 f_full = GNUNET_DISK_file_open (data_fn_full,
743 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
744 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
747 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
748 "Cannot open gnuplot file `%s'\n",
750 GNUNET_free (data_fn_full);
753 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
754 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_full, data, strlen(data)))
755 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
756 "Cannot write data to log file `%s'\n",
758 write_gnuplot_script (data_fn_full, GNUNET_YES);
761 data_fn_update = NULL;
762 if ((ph.create_plot) && (GNUNET_YES == ph.measure_updates))
764 GNUNET_asprintf (&data_fn_update, "perf_%s_update_%u_%u_%u.data",
769 f_update = GNUNET_DISK_file_open (data_fn_update,
770 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
771 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
772 if (NULL == f_update)
774 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
775 "Cannot open gnuplot file `%s'\n", data_fn_update);
776 GNUNET_free (data_fn_update);
778 GNUNET_DISK_file_close (f_full);
779 GNUNET_free (data_fn_full);
782 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
783 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data)))
784 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
785 "Cannot write data to log file `%s'\n",
787 write_gnuplot_script (data_fn_update, GNUNET_NO);
790 next = ph.iterations_results[ph.current_iteration -1].result_head;
791 while (NULL != (cur = next))
800 ph.averaged_result[cur->peers - ph.N_peers_start].peers = cur->peers;
801 ph.averaged_result[cur->peers - ph.N_peers_start].addresses = cur->addresses;
802 ph.averaged_result[cur->peers - ph.N_peers_start].update = cur->update;
804 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_total.rel_value_us)
806 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == ph.averaged_result[cur->peers - ph.N_peers_start].d_total.rel_value_us)
807 ph.averaged_result[cur->peers - ph.N_peers_start].d_total.rel_value_us = 0;
808 ph.averaged_result[cur->peers - ph.N_peers_start].d_total.rel_value_us += cur->d_total.rel_value_us;
810 "Total time to solve %s for %u peers %u addresses: %llu us\n",
811 (GNUNET_YES == cur->update) ? "updated" : "full",
812 cur->peers, cur->addresses, (unsigned long long) cur->d_total.rel_value_us);
813 GNUNET_asprintf(&str_d_total,
815 (unsigned long long) cur->d_total.rel_value_us);
818 GNUNET_asprintf(&str_d_total, "-1");
819 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_setup.rel_value_us)
821 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == ph.averaged_result[cur->peers - ph.N_peers_start].d_setup.rel_value_us)
822 ph.averaged_result[cur->peers - ph.N_peers_start].d_setup.rel_value_us = 0;
823 ph.averaged_result[cur->peers - ph.N_peers_start].d_setup.rel_value_us += cur->d_setup.rel_value_us;
824 fprintf (stderr, "Total time to setup %s %u peers %u addresses: %llu us\n",
825 (GNUNET_YES == cur->update) ? "updated" : "full",
826 cur->peers, cur->addresses, (unsigned long long )cur->d_setup.rel_value_us);
827 GNUNET_asprintf(&str_d_setup, "%llu", (unsigned long long )cur->d_setup.rel_value_us);
830 GNUNET_asprintf(&str_d_setup, "-1");
831 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_lp.rel_value_us)
833 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == ph.averaged_result[cur->peers - ph.N_peers_start].d_lp.rel_value_us)
834 ph.averaged_result[cur->peers - ph.N_peers_start].d_lp.rel_value_us = 0;
835 ph.averaged_result[cur->peers - ph.N_peers_start].d_lp.rel_value_us += cur->d_lp.rel_value_us;
837 "Total time to solve %s LP for %u peers %u addresses: %llu us\n",
838 (GNUNET_YES == cur->update) ? "updated" : "full",
841 (unsigned long long )cur->d_lp.rel_value_us);
842 GNUNET_asprintf (&str_d_lp,
844 (unsigned long long )cur->d_lp.rel_value_us);
847 GNUNET_asprintf (&str_d_lp, "-1");
848 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_mlp.rel_value_us)
850 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == ph.averaged_result[cur->peers - ph.N_peers_start].d_mlp.rel_value_us)
851 ph.averaged_result[cur->peers - ph.N_peers_start].d_mlp.rel_value_us = 0;
852 ph.averaged_result[cur->peers - ph.N_peers_start].d_mlp.rel_value_us += cur->d_mlp.rel_value_us;
853 fprintf (stderr, "Total time to solve %s MLP for %u peers %u addresses: %llu us\n",
854 (GNUNET_YES == cur->update) ? "updated" : "full",
855 cur->peers, cur->addresses, (unsigned long long )cur->d_mlp.rel_value_us);
856 GNUNET_asprintf (&str_d_mlp,
858 (unsigned long long )cur->d_mlp.rel_value_us);
861 GNUNET_asprintf (&str_d_mlp, "-1");
864 if (GNUNET_YES == ph.create_plot)
867 GNUNET_asprintf (&data,
868 "%u;%u;%s;%s;%s;%s\n",
869 cur->peers, cur->addresses,
874 if (cur->update == GNUNET_NO)
876 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_full, data, strlen(data)))
877 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
878 "Cannot write data to log file `%s'\n",
881 if ((cur->update == GNUNET_YES) && (NULL != f_update))
883 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data)))
884 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
885 "Cannot write data to log file `%s'\n",
890 GNUNET_free_non_null (str_d_total);
891 GNUNET_free_non_null (str_d_setup);
892 GNUNET_free_non_null (str_d_lp);
893 GNUNET_free_non_null (str_d_mlp);
895 GNUNET_CONTAINER_DLL_remove (ph.iterations_results[ph.current_iteration-1].result_head,
896 ph.iterations_results[ph.current_iteration-1].result_tail, cur);
900 if ((NULL != f_full) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_full)))
901 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
903 GNUNET_free_non_null (data_fn_full);
905 if ((NULL != f_update) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_update)))
906 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
908 GNUNET_free_non_null (data_fn_update);
913 evaluate_average (void)
916 for (c = 0; c <= ph.N_peers_end - ph.N_peers_start; c++)
918 struct Result *cur = &ph.averaged_result[c];
919 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_total.rel_value_us)
921 "Average total time to solve %s for %u peers %u addresses: %llu us\n",
922 (GNUNET_YES == cur->update) ? "updated" : "full",
923 cur->peers, cur->addresses,
924 (unsigned long long) cur->d_total.rel_value_us / ph.iterations);
926 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_setup.rel_value_us)
928 "Average total time to setup for %u peers %u addresses: %llu us\n",
929 cur->peers, cur->addresses,
930 (unsigned long long) cur->d_setup.rel_value_us / ph.iterations);
931 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_lp.rel_value_us)
933 "Average total time to solve lp %s for %u peers %u addresses: %llu us\n",
934 (GNUNET_YES == cur->update) ? "updated" : "full",
935 cur->peers, cur->addresses,
936 (unsigned long long) cur->d_lp.rel_value_us / ph.iterations);
937 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_mlp.rel_value_us)
939 "Average total time to solve mlp %s for %u peers %u addresses: %llu us\n",
940 (GNUNET_YES == cur->update) ? "updated" : "full",
941 cur->peers, cur->addresses,
942 (unsigned long long) cur->d_mlp.rel_value_us / ph.iterations);
950 struct ATS_Address *cur;
951 struct ATS_Address *next;
954 int count_p = ph.N_peers_end;
955 int count_a = ph.N_address;
956 struct ATS_Address * cur_addr;
959 ph.peers = GNUNET_malloc ((count_p) * sizeof (struct PerfPeer));
960 for (cp = 0; cp < count_p; cp++)
961 perf_create_peer (cp);
962 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
963 "Iteration %u of %u, added %u peers\n", ph.current_iteration, ph.iterations, cp);
965 for (cp = 0; cp < count_p; cp++)
967 if (GNUNET_NO == ph.bulk_running)
969 ph.bulk_running = GNUNET_YES;
970 ph.env.sf.s_bulk_start (ph.solver);
972 ph.current_p = cp + 1;
973 for (ca = 0; ca < count_a; ca++)
975 cur_addr = perf_create_address (cp, ca);
977 ph.env.sf.s_add (ph.solver, cur_addr, GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_ATS_NetworkTypeCount));
978 ph.current_a = ca + 1;
979 perf_address_initial_update (ph.solver, ph.addresses, cur_addr);
980 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
981 "Adding address for peer %u address %u\n", cp, ca);
983 /* Notify solver about request */
984 ph.env.sf.s_get (ph.solver, &ph.peers[cp].id);
986 if (cp + 1 >= ph.N_peers_start)
988 /* Disable bulk to solve the problem */
989 if (GNUNET_YES == ph.bulk_running)
991 ph.expecting_solution = GNUNET_YES;
992 ph.bulk_running = GNUNET_NO;
993 ph.env.sf.s_bulk_stop (ph.solver);
1000 /* Problem is solved by the solver here due to unlocking */
1001 ph.expecting_solution = GNUNET_NO;
1003 /* Update the problem */
1004 if ((0 < ph.opt_update_percent) && (GNUNET_YES == ph.measure_updates))
1007 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1008 "Updating problem with %u peers and %u addresses\n", cp + 1, ca);
1010 ph.expecting_solution = GNUNET_YES;
1011 if (GNUNET_NO == ph.bulk_running)
1013 ph.bulk_running = GNUNET_YES;
1014 ph.env.sf.s_bulk_start (ph.solver);
1016 perf_update_all_addresses (cp + 1, ca, ph.opt_update_percent);
1017 ph.bulk_running = GNUNET_NO;
1018 ph.env.sf.s_bulk_stop (ph.solver);
1019 /* Problem is solved by the solver here due to unlocking */
1020 ph.expecting_solution = GNUNET_NO;
1022 GNUNET_assert (GNUNET_NO == ph.bulk_running);
1026 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1027 "Done, cleaning up addresses\n");
1028 if (GNUNET_NO == ph.bulk_running)
1030 ph.env.sf.s_bulk_start (ph.solver);
1031 ph.bulk_running = GNUNET_YES;
1034 for (cp = 0; cp < count_p; cp++)
1036 for (cur = ph.peers[cp].head; cur != NULL ; cur = next)
1038 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1039 "Deleting addresses for peer %u\n", cp);
1040 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (ph.addresses,
1041 &ph.peers[cp].id, cur));
1042 ph.env.sf.s_del (ph.solver, cur, GNUNET_NO);
1044 GNUNET_CONTAINER_DLL_remove(ph.peers[cp].head, ph.peers[cp].tail, cur);
1049 GNUNET_free(ph.peers);
1054 run (void *cls, char * const *args, const char *cfgfile,
1055 const struct GNUNET_CONFIGURATION_Handle *cfg)
1057 GNUNET_log_setup ("perf-ats-solver", "WARNING", NULL);
1059 char *src_filename = GNUNET_strdup (__FILE__);
1060 char *test_filename = cls;
1063 struct GNUNET_CONFIGURATION_Handle *solver_cfg;
1064 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
1065 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
1068 /* Extract test name */
1069 if (NULL == (sep = (strstr (src_filename,".c"))))
1071 GNUNET_free (src_filename);
1078 if (NULL != (sep = strstr (test_filename, ".exe")))
1081 if (NULL == (solver = strstr (test_filename, src_filename)))
1083 GNUNET_free (src_filename);
1088 solver += strlen (src_filename) +1;
1090 if (0 == strcmp(solver, "proportional"))
1092 ph.ats_mode = MODE_PROPORTIONAL;
1093 ph.ats_string = "proportional";
1095 else if (0 == strcmp(solver, "mlp"))
1097 ph.ats_mode = MODE_MLP;
1098 ph.ats_string = "mlp";
1100 else if ((0 == strcmp(solver, "ril")))
1102 ph.ats_mode = MODE_RIL;
1103 ph.ats_string = "ril";
1107 GNUNET_free (src_filename);
1112 GNUNET_free (src_filename);
1114 /* Calculcate peers */
1115 if ((0 == ph.N_peers_start) && (0 == ph.N_peers_end))
1117 ph.N_peers_start = DEFAULT_PEERS_START;
1118 ph.N_peers_end = DEFAULT_PEERS_END;
1120 if (0 == ph.N_address)
1121 ph.N_address = DEFAULT_ADDRESSES;
1123 if (ph.N_peers_start != ph.N_peers_end)
1124 fprintf (stderr, "Benchmarking solver `%s' with %u to %u peers and %u addresses in %u iterations\n",
1125 ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address, ph.iterations);
1127 fprintf (stderr, "Benchmarking solver `%s' with %u peers and %u addresses in %u iterations\n",
1128 ph.ats_string, ph.N_peers_end, ph.N_address, ph.iterations);
1130 if (0 == ph.opt_update_percent)
1131 ph.opt_update_percent = DEFAULT_UPDATE_PERCENTAGE;
1134 solver_cfg = GNUNET_CONFIGURATION_create();
1135 if ((NULL == solver_cfg) || (GNUNET_SYSERR == (GNUNET_CONFIGURATION_load ( solver_cfg, "perf_ats_solver.conf"))))
1141 if (GNUNET_ATS_NetworkTypeCount != load_quotas (solver_cfg,
1142 quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount))
1149 /* Create array of DLL to store results for iterations */
1150 ph.iterations_results = GNUNET_malloc (sizeof (struct Iteration) * ph.iterations);
1151 ph.averaged_result = GNUNET_malloc (sizeof (struct Result) * ((ph.N_peers_end + 1) - ph.N_peers_start));
1152 for (c = 0; c <= ph.N_peers_end - ph.N_peers_start; c++)
1154 ph.averaged_result[c].d_setup = GNUNET_TIME_UNIT_FOREVER_REL;
1155 ph.averaged_result[c].d_total = GNUNET_TIME_UNIT_FOREVER_REL;
1156 ph.averaged_result[c].d_lp = GNUNET_TIME_UNIT_FOREVER_REL;
1157 ph.averaged_result[c].d_mlp = GNUNET_TIME_UNIT_FOREVER_REL;
1161 ph.env.cfg = solver_cfg;
1162 ph.stat = GNUNET_STATISTICS_create ("ats", cfg);
1163 ph.env.stats = ph.stat;
1164 ph.addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
1165 ph.env.addresses = ph.addresses;
1166 ph.env.bandwidth_changed_cb = bandwidth_changed_cb;
1167 ph.env.get_preferences = &get_preferences_cb;
1168 ph.env.get_property = &get_property_cb;
1169 ph.env.network_count = GNUNET_ATS_NetworkTypeCount;
1170 ph.env.info_cb = &solver_info_cb;
1171 ph.env.info_cb_cls = NULL;
1173 int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
1174 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
1176 ph.env.networks[c] = networks[c];
1177 ph.env.out_quota[c] = quotas_out[c];
1178 ph.env.in_quota[c] = quotas_in[c];
1179 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loading network quotas: `%s' %llu %llu \n",
1180 GNUNET_ATS_print_network_type(ph.env.networks[c]),
1181 ph.env.out_quota[c],
1182 ph.env.in_quota[c]);
1184 GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL );
1186 GNUNET_asprintf (&plugin, "libgnunet_plugin_ats_%s", ph.ats_string);
1187 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initializing solver `%s'\n"), ph.ats_string);
1188 if (NULL == (ph.solver = GNUNET_PLUGIN_load (plugin, &ph.env)))
1190 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver `%s'!\n"), plugin);
1195 /* Do the benchmark */
1196 for (ph.current_iteration = 1; ph.current_iteration <= ph.iterations; ph.current_iteration++)
1199 evaluate (ph.current_iteration);
1201 evaluate_average ();
1204 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Unloading solver `%s'\n"), ph.ats_string);
1205 GNUNET_PLUGIN_unload (plugin, ph.solver);
1206 GNUNET_free (plugin);
1207 GNUNET_free (ph.iterations_results);
1208 GNUNET_free (ph.averaged_result);
1209 GNUNET_CONFIGURATION_destroy (solver_cfg);
1210 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
1215 main (int argc, char *argv[])
1217 /* extract command line arguments */
1218 ph.opt_update_percent = 0;
1219 ph.N_peers_start = 0;
1222 ph.ats_string = NULL;
1223 ph.create_plot = GNUNET_NO;
1224 ph.measure_updates = GNUNET_NO;
1227 static struct GNUNET_GETOPT_CommandLineOption options[] = {
1228 { 'a', "addresses", NULL,
1229 gettext_noop ("addresses to use"),
1230 1, &GNUNET_GETOPT_set_uint, &ph.N_address },
1231 { 's', "start", NULL,
1232 gettext_noop ("start with peer"),
1233 1, &GNUNET_GETOPT_set_uint, &ph.N_peers_start },
1235 gettext_noop ("end with peer"),
1236 1, &GNUNET_GETOPT_set_uint, &ph.N_peers_end },
1237 { 'i', "iterations", NULL,
1238 gettext_noop ("number of iterations used for averaging (default: 1)"),
1239 1, &GNUNET_GETOPT_set_uint, &ph.iterations },
1240 { 'p', "percentage", NULL,
1241 gettext_noop ("update a fix percentage of addresses"),
1242 1, &GNUNET_GETOPT_set_uint, &ph.opt_update_percent },
1243 { 'g', "gnuplot", NULL,
1244 gettext_noop ("create GNUplot file"),
1245 0, &GNUNET_GETOPT_set_one, &ph.create_plot},
1246 { 'u', "update", NULL,
1247 gettext_noop ("measure updates"),
1248 0, &GNUNET_GETOPT_set_one, &ph.measure_updates},
1249 GNUNET_GETOPT_OPTION_END
1252 GNUNET_PROGRAM_run (argc, argv, argv[0], NULL, options, &run, argv[0]);
1257 /* end of file perf_ats_solver.c */