diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 130 | ||||
-rw-r--r-- | src/transport/test_transport_ats.c | 2 | ||||
-rw-r--r-- | src/transport/transport.h | 7 |
3 files changed, 95 insertions, 44 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index c83e5398d..25a6446e7 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -48,6 +48,7 @@ | |||
48 | 48 | ||
49 | #define DEBUG_TRANSPORT_HELLO GNUNET_YES | 49 | #define DEBUG_TRANSPORT_HELLO GNUNET_YES |
50 | 50 | ||
51 | #define DEBUG_ATS GNUNET_NO | ||
51 | #define VERBOSE_ATS GNUNET_NO | 52 | #define VERBOSE_ATS GNUNET_NO |
52 | 53 | ||
53 | /** | 54 | /** |
@@ -5557,7 +5558,6 @@ struct ATS_transports | |||
5557 | double c_1; | 5558 | double c_1; |
5558 | }; | 5559 | }; |
5559 | 5560 | ||
5560 | |||
5561 | #if HAVE_LIBGLPK | 5561 | #if HAVE_LIBGLPK |
5562 | static glp_prob * | 5562 | static glp_prob * |
5563 | ats_create_problem (int peers, | 5563 | ats_create_problem (int peers, |
@@ -5568,8 +5568,9 @@ ats_create_problem (int peers, | |||
5568 | const struct ATS_peer * pl, | 5568 | const struct ATS_peer * pl, |
5569 | const struct ATS_transports * tl, | 5569 | const struct ATS_transports * tl, |
5570 | int max_it, | 5570 | int max_it, |
5571 | int max_dur) | 5571 | int max_dur, int mlp) |
5572 | { | 5572 | { |
5573 | |||
5573 | int result = GLP_UNDEF; | 5574 | int result = GLP_UNDEF; |
5574 | int c1, c2; | 5575 | int c1, c2; |
5575 | glp_prob *lp; | 5576 | glp_prob *lp; |
@@ -5581,29 +5582,21 @@ ats_create_problem (int peers, | |||
5581 | int start = 0; | 5582 | int start = 0; |
5582 | int cur_row = 0; | 5583 | int cur_row = 0; |
5583 | 5584 | ||
5584 | int ia[1+(rows*cols)], ja[1+(rows*cols)]; | 5585 | //int ia[1+(rows*cols)]; |
5585 | double ar[1+(rows*cols)]; | 5586 | //int ja[1+(rows*cols)]; |
5586 | double value; | 5587 | //double ar[1+(rows*cols)]; |
5587 | 5588 | ||
5588 | /* Setting GLPK options */ | 5589 | int * ia = GNUNET_malloc (1+(rows*cols) * sizeof (int)); |
5589 | glp_smcp * options = GNUNET_malloc( sizeof (glp_smcp)); | 5590 | int * ja = GNUNET_malloc (1+(rows*cols) * sizeof (int)); |
5590 | glp_init_smcp(options); | 5591 | double * ar = GNUNET_malloc(1+(rows*cols)* sizeof (double)); |
5591 | 5592 | ||
5592 | /* maximum iterations */ | 5593 | double value; |
5593 | options->it_lim = max_it; | ||
5594 | /* maximum durations */ | ||
5595 | options->tm_lim = max_dur; | ||
5596 | /* output level */ | ||
5597 | if (VERBOSE_ATS) | ||
5598 | options->msg_lev = GLP_MSG_ALL; | ||
5599 | else | ||
5600 | options->msg_lev = GLP_MSG_OFF; | ||
5601 | 5594 | ||
5602 | if (DEBUG_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Creating LP problem: %i peers, relativity r %3.2f, b_max %5.2f, b_min %5.2f, \n",peers, r, b_max, b_min); | 5595 | if (DEBUG_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Creating LP problem: %i peers, relativity r %3.2f, b_max %5.2f, b_min %5.2f, \n",peers, r, b_max, b_min); |
5596 | if (DEBUG_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Current memory consumption %i\n",(1+(rows*cols) * (2*sizeof(int) + sizeof(double))) / (1024*1024)); | ||
5603 | lp = glp_create_prob(); | 5597 | lp = glp_create_prob(); |
5604 | glp_set_prob_name(lp, "gnunet ats bandwidth distribution"); | 5598 | glp_set_prob_name(lp, "gnunet ats bandwidth distribution"); |
5605 | glp_set_obj_dir(lp, GLP_MAX); | 5599 | glp_set_obj_dir(lp, GLP_MAX); |
5606 | |||
5607 | /* Adding transports and objective function coefficients*/ | 5600 | /* Adding transports and objective function coefficients*/ |
5608 | glp_add_cols(lp, cols); | 5601 | glp_add_cols(lp, cols); |
5609 | for (c1=1; c1<=cols; c1++) | 5602 | for (c1=1; c1<=cols; c1++) |
@@ -5714,24 +5707,59 @@ ats_create_problem (int peers, | |||
5714 | } | 5707 | } |
5715 | 5708 | ||
5716 | glp_load_matrix(lp, rows * cols, ia, ja, ar); | 5709 | glp_load_matrix(lp, rows * cols, ia, ja, ar); |
5717 | result = glp_simplex(lp, options); | 5710 | |
5711 | /* Solve the MLP problem */ | ||
5712 | if (mlp == GNUNET_YES) | ||
5713 | { | ||
5714 | glp_iocp opt; | ||
5715 | glp_init_iocp(&opt); | ||
5716 | |||
5717 | /* Use LP presolver (if not, valid LP solution has to be provided)*/ | ||
5718 | opt.presolve =GLP_ON; | ||
5719 | /* maximum duration */ | ||
5720 | opt.tm_lim = max_dur; | ||
5721 | /* output level */ | ||
5722 | if (VERBOSE_ATS) | ||
5723 | opt.msg_lev = GLP_MSG_ALL; | ||
5724 | else | ||
5725 | opt.msg_lev = GLP_MSG_OFF; | ||
5726 | result = glp_intopt(lp, &opt); | ||
5727 | } | ||
5728 | /* Solve the LP problem */ | ||
5729 | { | ||
5730 | glp_smcp opt ; | ||
5731 | glp_init_smcp(&opt); | ||
5732 | |||
5733 | /* maximum iterations */ | ||
5734 | opt.it_lim = max_it; | ||
5735 | /* maximum duration */ | ||
5736 | opt.tm_lim = max_dur; | ||
5737 | /* output level */ | ||
5738 | if (VERBOSE_ATS) | ||
5739 | opt.msg_lev = GLP_MSG_ALL; | ||
5740 | else | ||
5741 | opt.msg_lev = GLP_MSG_OFF; | ||
5742 | |||
5743 | result = glp_simplex(lp, &opt); | ||
5744 | } | ||
5745 | |||
5718 | if (DEBUG_ATS) | 5746 | if (DEBUG_ATS) |
5719 | { | 5747 | { |
5720 | switch (result) { | 5748 | switch (result) { |
5721 | case GLP_ESTOP : /* search terminated by application */ | 5749 | case GLP_ESTOP : /* search terminated by application */ |
5722 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Search terminated by application "); | 5750 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Search terminated by application "); |
5723 | case GLP_EITLIM : /* iteration limit exceeded */ | 5751 | case GLP_EITLIM : /* iteration limit exceeded */ |
5724 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iteration limit exceeded "); | 5752 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Iteration limit exceeded "); |
5725 | break; | 5753 | break; |
5726 | case GLP_ETMLIM : /* time limit exceeded */ | 5754 | case GLP_ETMLIM : /* time limit exceeded */ |
5727 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Time limit exceeded "); | 5755 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Time limit exceeded "); |
5728 | break; | 5756 | break; |
5729 | case GLP_ENOFEAS: /* no primal/dual feasible solution */ | 5757 | case GLP_ENOFEAS: /* no primal/dual feasible solution */ |
5730 | case GLP_ENOCVG : /* no convergence */ | 5758 | case GLP_ENOCVG : /* no convergence */ |
5731 | case GLP_ERANGE : /* result out of range */ | 5759 | case GLP_ERANGE : /* result out of range */ |
5732 | case GLP_ENOPFS : /* no primal feasible solution */ | 5760 | case GLP_ENOPFS : /* no primal feasible solution */ |
5733 | case GLP_ENODFS : /* no dual feasible solution */ | 5761 | case GLP_ENODFS : /* no dual feasible solution */ |
5734 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No feasible solution"); | 5762 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No feasible solution"); |
5735 | break; | 5763 | break; |
5736 | 5764 | ||
5737 | case GLP_EBADB : /* invalid basis */ | 5765 | case GLP_EBADB : /* invalid basis */ |
@@ -5745,7 +5773,7 @@ ats_create_problem (int peers, | |||
5745 | case GLP_EMIPGAP: /* relative mip gap tolerance reached */ | 5773 | case GLP_EMIPGAP: /* relative mip gap tolerance reached */ |
5746 | case GLP_EINSTAB: /* numerical instability */ | 5774 | case GLP_EINSTAB: /* numerical instability */ |
5747 | case GLP_EDATA : /* invalid data */ | 5775 | case GLP_EDATA : /* invalid data */ |
5748 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Invalid Input data\n"); | 5776 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid Input data\n"); |
5749 | break; | 5777 | break; |
5750 | 5778 | ||
5751 | break; | 5779 | break; |
@@ -5764,11 +5792,15 @@ ats_create_problem (int peers, | |||
5764 | if (old!=NULL) GNUNET_free(old); | 5792 | if (old!=NULL) GNUNET_free(old); |
5765 | } | 5793 | } |
5766 | GNUNET_asprintf(&debug_solution, "%s z = %g; \n", debug_solution, glp_get_obj_val(lp)); | 5794 | GNUNET_asprintf(&debug_solution, "%s z = %g; \n", debug_solution, glp_get_obj_val(lp)); |
5767 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s \n",debug_solution); | 5795 | if (DEBUG_ATS) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s \n",debug_solution); |
5768 | GNUNET_free(debug_solution); | 5796 | GNUNET_free(debug_solution); |
5769 | 5797 | ||
5770 | glp_delete_prob(lp); | 5798 | glp_delete_prob(lp); |
5771 | GNUNET_free(options); | 5799 | |
5800 | GNUNET_free(ar); | ||
5801 | GNUNET_free(ia); | ||
5802 | GNUNET_free(ja); | ||
5803 | |||
5772 | return lp; | 5804 | return lp; |
5773 | } | 5805 | } |
5774 | #else | 5806 | #else |
@@ -5781,7 +5813,7 @@ ats_create_problem (int peers, | |||
5781 | const struct ATS_peer * pl, | 5813 | const struct ATS_peer * pl, |
5782 | const struct ATS_transports * tl, | 5814 | const struct ATS_transports * tl, |
5783 | int max_it, | 5815 | int max_it, |
5784 | int max_dur) | 5816 | int max_dur, int mlp) |
5785 | { | 5817 | { |
5786 | return NULL; | 5818 | return NULL; |
5787 | } | 5819 | } |
@@ -5799,17 +5831,27 @@ void ats_calculate_bandwidth_distribution () | |||
5799 | return; | 5831 | return; |
5800 | } | 5832 | } |
5801 | 5833 | ||
5802 | int peers = 3; | 5834 | struct GNUNET_TIME_Absolute start; |
5835 | int test = 3; | ||
5836 | int mlp = GNUNET_YES; | ||
5837 | |||
5838 | //for (test=1; test<75000; test++) | ||
5839 | //{ | ||
5840 | int peers = test; | ||
5803 | int transports = 3; | 5841 | int transports = 3; |
5804 | 5842 | ||
5805 | double b_min = 10; | 5843 | double b_min = 1; |
5806 | double b_max = 100.0; | 5844 | double b_max = 100000.0; |
5807 | double r = 0.85;//1.0; | 5845 | double r = 0.85;//1.0; |
5808 | double R = 1.0; | 5846 | double R = 1.0; |
5809 | 5847 | ||
5810 | int it = 50; | 5848 | int it = ATS_MAX_ITERATIONS; |
5811 | int dur = 500; | 5849 | int dur = 500; |
5812 | //if (INT_MAX) ats.max_exec_duration.rel_value; | 5850 | if (INT_MAX < ats->max_exec_duration.rel_value) |
5851 | dur = INT_MAX; | ||
5852 | else | ||
5853 | dur = (int) ats->max_exec_duration.rel_value; | ||
5854 | |||
5813 | 5855 | ||
5814 | struct ATS_transports * tl = GNUNET_malloc(transports * sizeof (struct ATS_peer)); | 5856 | struct ATS_transports * tl = GNUNET_malloc(transports * sizeof (struct ATS_peer)); |
5815 | 5857 | ||
@@ -5820,32 +5862,35 @@ void ats_calculate_bandwidth_distribution () | |||
5820 | pl[c].peer.hashPubKey.bits[0] = c+1; | 5862 | pl[c].peer.hashPubKey.bits[0] = c+1; |
5821 | pl[c].f = 1 / (double) peers ; | 5863 | pl[c].f = 1 / (double) peers ; |
5822 | pl[c].t = 1; | 5864 | pl[c].t = 1; |
5823 | //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ats_calculate_bandwidth_distribution Peer[%i] : %s %p \n",c , GNUNET_i2s(&list[c].peer), &list[c].peer); | 5865 | //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ats_calculate_bandwidth_distribution Peer[%i] : %s %p \n",c , GNUNET_i2s(&pl[c].peer), &pl[c].peer); |
5824 | c++; | 5866 | c++; |
5825 | } | 5867 | } |
5826 | c = 0; | 5868 | c = 0; |
5827 | while (c < transports) | 5869 | while (c < transports) |
5828 | { | 5870 | { |
5829 | tl[c].id = c; | 5871 | tl[c].id = c; |
5830 | tl[c].c_max = 100; | 5872 | tl[c].c_max = 100000; |
5831 | tl[c].c_1 = 1; | 5873 | tl[c].c_1 = 1; |
5832 | c++; | 5874 | c++; |
5875 | //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ats_calculate_bandwidth_distribution Peer[%i] : %s %p \n",c , GNUNET_i2s(&pl[c].peer), &pl[c].peer); | ||
5833 | } | 5876 | } |
5834 | 5877 | ||
5835 | // test // | 5878 | // test // |
5836 | 5879 | ||
5837 | pl[0].f = 0.33; | 5880 | //pl[0].f = 0.33; |
5838 | pl[2].f = 0.43; | 5881 | //pl[2].f = 0.43; |
5839 | pl[1].f = 0.33; | 5882 | //pl[1].f = 0.33; |
5840 | // test // | 5883 | // test // |
5841 | 5884 | start = GNUNET_TIME_absolute_get(); | |
5842 | ats_create_problem(peers, transports, b_min, b_max, r, R, pl, tl, it, dur); | 5885 | ats_create_problem(peers, transports, b_min, b_max, r, R, pl, tl, it, dur, mlp); |
5886 | if (DEBUG_ATS) | ||
5887 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s,%i,%llu,%i\n",(mlp)?"mlp":"lp", peers, | ||
5888 | GNUNET_TIME_absolute_get_difference(start,GNUNET_TIME_absolute_get()).rel_value, (1+(peers*transports) * (2*sizeof(int) + sizeof(double)))); | ||
5843 | 5889 | ||
5844 | GNUNET_free (pl); | 5890 | GNUNET_free (pl); |
5845 | GNUNET_free (tl); | 5891 | GNUNET_free (tl); |
5846 | 5892 | //} | |
5847 | ats->last = GNUNET_TIME_absolute_get(); | 5893 | ats->last = GNUNET_TIME_absolute_get(); |
5848 | |||
5849 | } | 5894 | } |
5850 | 5895 | ||
5851 | 5896 | ||
@@ -5901,6 +5946,7 @@ struct ATS_info * ats_init () | |||
5901 | ats->min_delta = ATS_MIN_INTERVAL; | 5946 | ats->min_delta = ATS_MIN_INTERVAL; |
5902 | ats->exec_intervall = ATS_EXEC_INTERVAL; | 5947 | ats->exec_intervall = ATS_EXEC_INTERVAL; |
5903 | ats->max_exec_duration = ATS_MAX_EXEC_DURATION; | 5948 | ats->max_exec_duration = ATS_MAX_EXEC_DURATION; |
5949 | ats->max_iterations = ATS_MAX_ITERATIONS; | ||
5904 | 5950 | ||
5905 | ats->ats_task = GNUNET_SCHEDULER_NO_TASK; | 5951 | ats->ats_task = GNUNET_SCHEDULER_NO_TASK; |
5906 | /* | 5952 | /* |
diff --git a/src/transport/test_transport_ats.c b/src/transport/test_transport_ats.c index 0f80807f6..88e9706ec 100644 --- a/src/transport/test_transport_ats.c +++ b/src/transport/test_transport_ats.c | |||
@@ -136,7 +136,7 @@ static void | |||
136 | end_badly () | 136 | end_badly () |
137 | { | 137 | { |
138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); | 138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); |
139 | GNUNET_break (0); | 139 | //GNUNET_break (0); |
140 | GNUNET_TRANSPORT_disconnect (p1.th); | 140 | GNUNET_TRANSPORT_disconnect (p1.th); |
141 | //GNUNET_TRANSPORT_disconnect (p2.th); | 141 | //GNUNET_TRANSPORT_disconnect (p2.th); |
142 | ok = 1; | 142 | ok = 1; |
diff --git a/src/transport/transport.h b/src/transport/transport.h index 3b0c4d3ef..5cbfce34c 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h | |||
@@ -33,7 +33,8 @@ | |||
33 | /* Minimum time between to calculations*/ | 33 | /* Minimum time between to calculations*/ |
34 | #define ATS_MIN_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250) | 34 | #define ATS_MIN_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250) |
35 | #define ATS_EXEC_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) | 35 | #define ATS_EXEC_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) |
36 | #define ATS_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500) | 36 | #define ATS_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 500) |
37 | #define ATS_MAX_ITERATIONS INT_MAX | ||
37 | 38 | ||
38 | struct ATS_info | 39 | struct ATS_info |
39 | { | 40 | { |
@@ -54,6 +55,10 @@ struct ATS_info | |||
54 | * Maximum execution time per calculation | 55 | * Maximum execution time per calculation |
55 | */ | 56 | */ |
56 | struct GNUNET_TIME_Relative max_exec_duration; | 57 | struct GNUNET_TIME_Relative max_exec_duration; |
58 | /** | ||
59 | * Maximum number of LP iterations per calculation | ||
60 | */ | ||
61 | int max_iterations; | ||
57 | 62 | ||
58 | GNUNET_SCHEDULER_TaskIdentifier ats_task; | 63 | GNUNET_SCHEDULER_TaskIdentifier ats_task; |
59 | }; | 64 | }; |