gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r34852 - gnunet/src/rps


From: gnunet
Subject: [GNUnet-SVN] r34852 - gnunet/src/rps
Date: Fri, 9 Jan 2015 12:13:57 +0100

Author: ch3
Date: 2015-01-09 12:13:56 +0100 (Fri, 09 Jan 2015)
New Revision: 34852

Modified:
   gnunet/src/rps/gnunet-service-rps.c
   gnunet/src/rps/gnunet-service-rps_sampler.c
Log:
moved computation of request rate out of sampler

Modified: gnunet/src/rps/gnunet-service-rps.c
===================================================================
--- gnunet/src/rps/gnunet-service-rps.c 2015-01-09 07:23:18 UTC (rev 34851)
+++ gnunet/src/rps/gnunet-service-rps.c 2015-01-09 11:13:56 UTC (rev 34852)
@@ -153,6 +153,10 @@
  * /Housekeeping with peers
 ***********************************************************************/
 
+/***********************************************************************
+ * Globals
+***********************************************************************/
+
 /**
  * Set of all peers to keep track of them.
  */
@@ -201,8 +205,6 @@
  */
 
 
-
-
 /**
  * Identifier for the main task that runs periodically.
  */
@@ -258,7 +260,44 @@
 uint64_t g_i = 0;
 
 
+/**
+ * Request counter.
+ *
+ * Only needed in the beginning to check how many of the 64 deltas
+ * we already have
+ */
+static unsigned int req_counter;
+
+/**
+ * Time of the last request we received.
+ *
+ * Used to compute the expected request rate.
+ */
+static struct GNUNET_TIME_Absolute last_request;
+
+/**
+ * Size of #request_deltas.
+ */
+#define REQUEST_DELTAS_SIZE 64
+static unsigned int request_deltas_size = REQUEST_DELTAS_SIZE;
+
+/**
+ * Last 64 deltas between requests
+ */
+static struct GNUNET_TIME_Relative request_deltas[REQUEST_DELTAS_SIZE];
+
+/**
+ * The prediction of the rate of requests
+ */
+static struct GNUNET_TIME_Relative  request_rate;
+
+
 /***********************************************************************
+ * /Globals
+***********************************************************************/
+
+
+/***********************************************************************
  * Util functions
 ***********************************************************************/
 
@@ -392,6 +431,34 @@
 }
 
 
+/**
+ * Sum all time relatives of an array.
+  */
+  struct GNUNET_TIME_Relative
+T_relative_sum (const struct GNUNET_TIME_Relative *rel_array, uint64_t 
arr_size)
+{
+  struct GNUNET_TIME_Relative sum;
+  uint64_t i;
+
+  sum = GNUNET_TIME_UNIT_ZERO;
+  for ( i = 0 ; i < arr_size ; i++ )
+  {
+    sum = GNUNET_TIME_relative_add (sum, rel_array[i]);
+  }
+  return sum;
+}
+
+
+/**
+ * Compute the average of given time relatives.
+ */
+  struct GNUNET_TIME_Relative
+T_relative_avg (const struct GNUNET_TIME_Relative *rel_array, uint64_t 
arr_size)
+{
+  return GNUNET_TIME_relative_divide (T_relative_sum (rel_array, arr_size), 
arr_size); // FIXME find a way to devide that by arr_size
+}
+
+
 /***********************************************************************
  * /Util functions
 ***********************************************************************/
@@ -467,6 +534,25 @@
   const struct GNUNET_PeerIdentity *peers;
   //uint64_t i;
 
+
+  /* Estimate request rate */
+  if (request_deltas_size > req_counter)
+    req_counter++;
+  if ( 1 < req_counter)
+  {
+    /* Shift last request deltas to the right */
+    memcpy (&request_deltas[1],
+        request_deltas,
+        (req_counter - 1) * sizeof (struct GNUNET_TIME_Relative));
+    /* Add current delta to beginning */
+    request_deltas[0] = GNUNET_TIME_absolute_get_difference (last_request,
+        GNUNET_TIME_absolute_get ());
+    request_rate = T_relative_avg (request_deltas, req_counter);
+  }
+  last_request = GNUNET_TIME_absolute_get();
+  // TODO resize the size of the extended_samplers
+
+
   // TODO check message size
   msg = (struct GNUNET_RPS_CS_RequestMessage *) message;
   cli_ctx = GNUNET_SERVER_client_get_user_context (client, struct client_ctx);
@@ -781,15 +867,20 @@
   struct GNUNET_TIME_Relative time_next_round;
   struct GNUNET_TIME_Relative half_round_interval;
   unsigned int rand_delay;
-  
+
+  /* Compute random time value between .5 * round_interval and 1.5 
*round_interval */
   half_round_interval = GNUNET_TIME_relative_divide (round_interval, 2);
   do
   {
+  /*
+   * Compute random value between (0 and 1) * round_interval
+   * via multiplying round_interval with a 'fraction' (0 to value)/value
+   */
   rand_delay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 
UINT_MAX/10);
-  time_next_round = GNUNET_TIME_relative_multiply (time_next_round, 
rand_delay);
+  time_next_round = GNUNET_TIME_relative_multiply (round_interval,  
rand_delay);
   time_next_round = GNUNET_TIME_relative_divide   (time_next_round, 
UINT_MAX/10);
   time_next_round = GNUNET_TIME_relative_add      (time_next_round, 
half_round_interval);
-  } while (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != 
time_next_round.rel_value_us);
+  } while (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == 
time_next_round.rel_value_us);
 
   /* Schedule next round */
   do_round_task = GNUNET_SCHEDULER_add_delayed (round_interval, &do_round, 
NULL);
@@ -907,13 +998,14 @@
     do_round_task = NULL;
   }
 
-  GNUNET_NSE_disconnect(nse);
-  GNUNET_CADET_disconnect(cadet_handle);
-  GNUNET_free(own_identity);
-  RPS_sampler_destroy();
-  GNUNET_array_grow(gossip_list, gossip_list_size, 0);
-  GNUNET_array_grow(push_list, push_list_size, 0);
-  GNUNET_array_grow(pull_list, pull_list_size, 0);
+  GNUNET_NSE_disconnect (nse);
+  GNUNET_CADET_disconnect (cadet_handle);
+  GNUNET_free (own_identity);
+  RPS_sampler_destroy ();
+  GNUNET_array_grow (request_deltas, request_deltas_size, 0);
+  GNUNET_array_grow (gossip_list, gossip_list_size, 0);
+  GNUNET_array_grow (push_list, push_list_size, 0);
+  GNUNET_array_grow (pull_list, pull_list_size, 0);
 }
 
 

Modified: gnunet/src/rps/gnunet-service-rps_sampler.c
===================================================================
--- gnunet/src/rps/gnunet-service-rps_sampler.c 2015-01-09 07:23:18 UTC (rev 
34851)
+++ gnunet/src/rps/gnunet-service-rps_sampler.c 2015-01-09 11:13:56 UTC (rev 
34852)
@@ -156,63 +156,10 @@
 /**
  * Inedex to the sampler element that is the next to be returned
  */
-static uint64_t extended_samplers_index;
+static uint64_t client_get_index;
 
-/**
- * Request counter.
- *
- * Only needed in the beginning to check how many of the 64 deltas
- * we already have
- */
-static unsigned int req_counter;
 
 /**
- * Time of the last request we received.
- *
- * Used to compute the expected request rate.
- */
-static struct GNUNET_TIME_Absolute last_request;
-
-/**
- * Last 64 deltas between requests
- */
-static struct GNUNET_TIME_Relative request_deltas[64];
-
-/**
- * The prediction of the rate of requests
- */
-static struct GNUNET_TIME_Relative  request_rate;
-
-
-/**
- * Sum all time relatives of an array.
- */
-  struct GNUNET_TIME_Relative
-T_relative_sum (const struct GNUNET_TIME_Relative *rel_array, uint64_t 
arr_size)
-{
-  struct GNUNET_TIME_Relative sum;
-  uint64_t i;
-
-  sum = GNUNET_TIME_UNIT_ZERO;
-  for ( i = 0 ; i < arr_size ; i++ )
-  {
-    sum = GNUNET_TIME_relative_add (sum, rel_array[i]);
-  }
-  return sum;
-}
-
-/**
- * Compute the average of given time relatives.
- */
-  struct GNUNET_TIME_Relative
-T_relative_avg (const struct GNUNET_TIME_Relative *rel_array, uint64_t 
arr_size)
-{
-  return T_relative_sum (rel_array, arr_size); // FIXME find a way to devide 
that by arr_size
-}
-
-
-
-/**
  * Reinitialise a previously initialised sampler element.
  *
  * @param sampler pointer to the memory that keeps the value.
@@ -437,7 +384,7 @@
   RPS_sampler_resize (init_size);
   RPS_sampler_update_list (id); // no super nice desing but ok for the moment
 
-  extended_samplers_index = 0;
+  client_get_index = 0;
 
   //GNUNET_assert (init_size == sampler->sampler_size);
 }
@@ -516,6 +463,7 @@
   return peer;
 }
 
+
 /**
  * Get n random peers out of the sampled peers.
  *
@@ -564,28 +512,14 @@
 {
   struct GNUNET_PeerIdentity *peer;
 
-  if (64 > req_counter)
-    req_counter++;
-  if (1 < req_counter)
-  {
-    memcpy (&request_deltas[1],
-        request_deltas,
-        (req_counter - 1) * sizeof (struct GNUNET_TIME_Relative));
-    request_deltas[0] = GNUNET_TIME_absolute_get_difference (last_request,
-        GNUNET_TIME_absolute_get ());
-    request_rate = T_relative_avg (request_deltas, req_counter);
-  }
-  last_request = GNUNET_TIME_absolute_get();
-  // TODO resize the size of the extended_samplers
-
   // use _get_rand_peer_ ?
   peer = GNUNET_new (struct GNUNET_PeerIdentity);
-  *peer = sampler->sampler_elements[extended_samplers_index]->peer_id;
-  RPS_sampler_elem_reinit (sampler->sampler_elements[extended_samplers_index]);
-  if ( extended_samplers_index == sampler->sampler_size )
-    extended_samplers_index = 0;
+  *peer = sampler->sampler_elements[client_get_index]->peer_id;
+  RPS_sampler_elem_reinit (sampler->sampler_elements[client_get_index]);
+  if ( client_get_index == sampler->sampler_size )
+    client_get_index = 0;
   else
-    extended_samplers_index++;
+    client_get_index++;
   return peer;
 }
 
@@ -661,7 +595,6 @@
 RPS_sampler_destroy ()
 {
   RPS_sampler_resize (0);
-  GNUNET_free (request_deltas); // _array_grow()?
   GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, 0);
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]