- combining performance selection and stability in proportional address selection
authorMatthias Wachs <wachs@net.in.tum.de>
Thu, 8 May 2014 17:24:44 +0000 (17:24 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Thu, 8 May 2014 17:24:44 +0000 (17:24 +0000)
- adding stbility tolerance configuration setting

src/ats/ats.conf.in
src/ats/gnunet-service-ats_normalization.c
src/ats/plugin_ats_proportional.c
src/ats/plugin_ats_proportional.h

index aa938e4c3b4a10a3d51f4fb62a30765d67707a35..e5bda20bc146eec371d2becdc908dfae2fd1ef33 100644 (file)
@@ -35,8 +35,11 @@ BLUETOOTH_QUOTA_OUT = 128 KiB
 # Proportional specific settings
 # How proportional to preferences is bandwidth distribution in a network
 # 1: Fair with respect to addresses without preferences
-# > 1: The bigger, the more respect is payed to preferences 
-PROP_PROPORTIONALITY_FACTOR = 4
+# > 100: The bigger, the more respect is payed to preferences 
+PROP_PROPORTIONALITY_FACTOR = 200
+# Should we stick to existing connections are prefer to switch?
+# [100...200], lower value prefers to switch, bigger value is more tolerant
+PROP_STABILITY_FACTOR = 125
 
 # MLP specific settings
 # MLP defaults
index f2964626052f5a08c3445e523ce48ccbc9ded529..1adc4811f115c33efca6683df83a4f2fe653a781 100644 (file)
@@ -733,6 +733,7 @@ normalize_address (void *cls, const struct GNUNET_PeerIdentity *h, void *k)
   backup = address->atsin[p->prop_type].norm;
   avg_value = address->atsin[p->prop_type].avg;
   delta = p->max - p->min;
+  /* max - 2 * min + avg_value / max - min */
   address->atsin[p->prop_type].norm = (delta + (avg_value - p->min)) / (delta);
 
   if (backup == address->atsin[p->prop_type].norm)
index 71223417fd9aafe7015ec17b1dcf658cee2396cb..0fde58acc0f3ffabc67e237fff3a6556f410e80d 100644 (file)
@@ -291,6 +291,11 @@ struct GAS_PROPORTIONAL_Handle
    * Proportionality factor
    */
   double prop_factor;
+
+  /**
+   * Stability factor
+   */
+  double stability_factor;
 };
 
 /**
@@ -400,6 +405,7 @@ libgnunet_plugin_ats_proportional_init (void *cls)
   struct Network * cur;
   char * net_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
   unsigned long long prop_factor;
+  unsigned long long stability_factor;
   int c;
 
   GNUNET_assert (NULL != env);
@@ -440,11 +446,32 @@ libgnunet_plugin_ats_proportional_init (void *cls)
   s->addresses = env->addresses;
   s->requests = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
 
+  if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number(s->env->cfg, "ats",
+      "PROP_STABILITY_FACTOR", &stability_factor))
+  {
+    if ((stability_factor >= 100) && (stability_factor <= 200))
+    {
+      s->stability_factor = ((double) stability_factor) / 100;
+    }
+    else
+    {
+      GNUNET_break (0);
+      s->stability_factor = PROP_STABILITY_FACTOR;
+    }
+  }
+  else
+  {
+    GNUNET_break (0);
+    s->stability_factor = PROP_STABILITY_FACTOR;
+  }
+  LOG (GNUNET_ERROR_TYPE_INFO, "Using stability factor %.3f\n",
+      s->stability_factor);
+
   if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number(s->env->cfg, "ats",
       "PROP_PROPORTIONALITY_FACTOR", &prop_factor))
   {
-    if (prop_factor > 1)
-      s->prop_factor = (double) prop_factor;
+    if (prop_factor >= 100)
+      s->prop_factor = ((double) prop_factor) / 100;
     else
     {
       GNUNET_break (0);
@@ -453,7 +480,7 @@ libgnunet_plugin_ats_proportional_init (void *cls)
   }
   else
     s->prop_factor = PROPORTIONALITY_FACTOR;
-  LOG (GNUNET_ERROR_TYPE_INFO, "Using proportionality factor %.0f\n",
+  LOG (GNUNET_ERROR_TYPE_INFO, "Using proportionality factor %.3f\n",
       s->prop_factor);
 
 
@@ -743,6 +770,10 @@ find_best_address_it (void *cls,
   struct AddressSolverInformation *asi;
   const double *norm_prop_cur;
   const double *norm_prop_best;
+  double best_delay;
+  double best_distance;
+  double cur_delay;
+  double cur_distance;
   int index;
 
   current_best = NULL;
@@ -790,45 +821,75 @@ find_best_address_it (void *cls,
       goto end;
     }
   }
-  if (NULL == ctx->best)
+  else
   {
     /* We do not have a 'best' address so take this address */
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "Setting initial address %p\n", current);
     current_best = current;
     goto end;
   }
 
-  if ( (ntohl (ctx->best->assigned_bw_in.value__) == 0) &&
-       (ntohl (current->assigned_bw_in.value__) > 0) )
-  {
-    /* stick to existing connection */
-    current_best = current;
-  }
-
   /* Now compare ATS information */
   norm_prop_cur = ctx->s->get_properties (ctx->s->get_properties_cls,
       (const struct ATS_Address *) current);
+  index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE);
+  cur_distance = norm_prop_cur[index];
+  index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY);
+  cur_delay = norm_prop_cur[index];
+
   norm_prop_best = ctx->s->get_properties (ctx->s->get_properties_cls,
       (const struct ATS_Address *) ctx->best);
-
   index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE);
-  if (GNUNET_SYSERR != index)
+  best_distance = norm_prop_best[index];
+  index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY);
+  best_delay = norm_prop_best[index];
+
+  /* user shorter distance */
+
+
+  if (cur_distance < best_distance)
   {
-    /* user shorter distance */
-    if (norm_prop_cur[index] < norm_prop_best[index])
+
+    if (GNUNET_NO == ctx->best->active)
+    {
+      current_best = current; /* Use current */
+    }
+    else if ((best_distance / cur_distance) > ctx->s->stability_factor)
+    {
+      /* Best and active address performs worse  */
       current_best = current;
-    else
-      current_best = ctx->best;
+    }
+  }
+  else
+  {
+    /* Use current best */
+    current_best = ctx->best;
   }
 
-  index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY);
-  if (GNUNET_SYSERR != index)
+  /* User connection with less delay */
+  if (cur_delay < best_delay)
   {
-    /* User connection with less delay */
-    if (norm_prop_cur[index] < norm_prop_best[index])
+
+    if (GNUNET_NO == ctx->best->active)
+    {
+      current_best = current; /* Use current */
+    }
+    else if ((best_delay / cur_delay) > ctx->s->stability_factor)
+    {
+      /* Best and active address performs worse  */
       current_best = current;
+    }
     else
-      current_best = ctx->best;
+    {
+      //GNUNET_break (0);
+    }
   }
+  else
+  {
+    /* Use current best */
+    current_best = ctx->best;
+  }
+
 end:
   ctx->best = current_best;
   return GNUNET_OK;
@@ -1523,7 +1584,7 @@ GAS_proportional_address_property_changed (void *solver,
     return;
   }
 
-  LOG(GNUNET_ERROR_TYPE_DEBUG,
+  LOG(GNUNET_ERROR_TYPE_INFO,
       "Property `%s' for peer `%s' address %p changed to %.2f \n",
       GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer),
       address, rel_value);
index 371c4077ca65a7905ed3d880a51018edb8e19bf5..999f42f3f0eebf34dcca4ebbb59eb4ea978024fd 100644 (file)
@@ -29,6 +29,8 @@
 #include "gnunet_ats_plugin.h"
 #include "gnunet-service-ats_addresses.h"
 
+#define PROP_STABILITY_FACTOR 1.25
+
 /**
  * ATS proportional solver
  *