-improving fragmentation performance
authorChristian Grothoff <christian@grothoff.org>
Wed, 16 May 2012 14:59:28 +0000 (14:59 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 16 May 2012 14:59:28 +0000 (14:59 +0000)
src/fragmentation/defragmentation.c
src/fragmentation/fragmentation.c

index 061277c415c39e08612a8669b3a9a23100659ea1..cc6875a9ba70a4c89a2705cbffe8cadadf9f7b1a 100644 (file)
@@ -420,7 +420,9 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
   unsigned int bc;
   unsigned int b;
   unsigned int n;
+  unsigned int num_fragments;
   int duplicate;
+  int last;
 
   if (ntohs (msg->size) < sizeof (struct FragmentHeader))
   {
@@ -452,6 +454,12 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
     return GNUNET_SYSERR;
   }
   GNUNET_STATISTICS_update (dc->stats, _("# fragments received"), 1, GNUNET_NO);
+  num_fragments = (ntohs (msg->size) + dc->mtu - sizeof (struct FragmentHeader)-1) / (dc->mtu - sizeof (struct FragmentHeader));
+  last = 0;
+  for (mc = dc->head; NULL != mc; mc = mc->next)
+    if (mc->fragment_id > fid)
+      last++;
+  
   mc = dc->head;
   while ((NULL != mc) && (fid != mc->fragment_id))
     mc = mc->next;
@@ -530,10 +538,19 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
   }
   /* send ACK */
   if (mc->frag_times_write_offset - mc->frag_times_start_offset > 1)
+  { 
     dc->latency = estimate_latency (mc);
+    GNUNET_STATISTICS_set (dc->stats, _("# Defragmentation latency estimate (ms)"), 
+                          dc->latency.rel_value,
+                          GNUNET_NO);
+  }
   delay = GNUNET_TIME_relative_multiply (dc->latency, bc + 1);
-  if ((0 == mc->bits) || (GNUNET_YES == duplicate))     /* message complete or duplicate, ACK now! */
+  if ( (last + fid == num_fragments) ||
+       (0 == mc->bits) || 
+       (GNUNET_YES == duplicate))     
   {
+    /* message complete or duplicate or last missing fragment in
+       linear sequence; ACK now! */
     delay = GNUNET_TIME_UNIT_ZERO;
   }
   if (GNUNET_SCHEDULER_NO_TASK != mc->ack_task)
index ee867b04d045b03e28be7c9aadd38173ad9c0241..9c9fea251011eb3552c7566b5cbc44b3b44be843 100644 (file)
@@ -110,6 +110,11 @@ struct GNUNET_FRAGMENT_Context
    */
   unsigned int num_rounds;
 
+  /**
+   * How many transmission have we completed in this round?
+   */
+  unsigned int num_transmissions;
+
   /**
    * GNUNET_YES if we called 'proc' and are now waiting for 'GNUNET_FRAGMENT_transmission_done'
    */
@@ -151,13 +156,12 @@ transmit_next (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   GNUNET_assert (GNUNET_NO == fc->proc_busy);
   if (0 == fc->acks)
     return;                     /* all done */
-
   /* calculate delay */
   wrap = 0;
   while (0 == (fc->acks & (1LL << fc->next_transmission)))
   {
     fc->next_transmission = (fc->next_transmission + 1) % 64;
-    wrap |= (fc->next_transmission == 0);
+    wrap |= (0 == fc->next_transmission);
   }
   bit = fc->next_transmission;
   size = ntohs (fc->msg->size);
@@ -167,7 +171,7 @@ transmit_next (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
         sizeof (struct FragmentHeader);
   else
     fsize = fc->mtu;
-  if (fc->tracker != NULL)
+  if (NULL != fc->tracker)
     delay = GNUNET_BANDWIDTH_tracker_get_delay (fc->tracker, fsize);
   else
     delay = GNUNET_TIME_UNIT_ZERO;
@@ -223,11 +227,18 @@ transmit_next (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                                                                  fc->num_rounds));
     /* never use zero, need some time for ACK always */
     delay = GNUNET_TIME_relative_max (MIN_ACK_DELAY, delay);
-    fc->last_round = GNUNET_TIME_absolute_get ();
     fc->wack = GNUNET_YES;
+    fc->last_round = GNUNET_TIME_absolute_get ();
+    GNUNET_STATISTICS_update (fc->stats, _("# fragments wrap arounds"), 1,
+                              GNUNET_NO);
   }
+  GNUNET_STATISTICS_set (fc->stats, 
+                        _("# next delay for fragment transmission"), 
+                        delay.rel_value,
+                        GNUNET_NO);
   fc->proc_busy = GNUNET_YES;
   fc->delay_until = GNUNET_TIME_relative_to_absolute (delay);
+  fc->num_transmissions++;
   fc->proc (fc->proc_cls, &fh->header);
 }
 
@@ -262,7 +273,9 @@ GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
   struct GNUNET_FRAGMENT_Context *fc;
   size_t size;
   uint64_t bits;
-
+  
+  GNUNET_STATISTICS_set (stats, _("# expected ACK delay for fragments"), 
+                        delay.rel_value, GNUNET_NO);
   GNUNET_STATISTICS_update (stats, _("# messages fragmented"), 1, GNUNET_NO);
   GNUNET_assert (mtu >= 1024 + sizeof (struct FragmentHeader));
   size = ntohs (msg->size);
@@ -342,13 +355,15 @@ GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
   if (ntohl (fa->fragment_id) != fc->fragment_id)
     return GNUNET_SYSERR;       /* not our ACK */
   abits = GNUNET_ntohll (fa->bits);
-  if ((GNUNET_YES == fc->wack) && (abits == (fc->acks & abits)))
+  if ( (GNUNET_YES == fc->wack) &&
+       (0 != fc->num_transmissions) )
   {
     /* normal ACK, can update running average of delay... */
     fc->wack = GNUNET_NO;
     ndelay = GNUNET_TIME_absolute_get_duration (fc->last_round);
     fc->delay.rel_value =
-        (ndelay.rel_value * fc->num_rounds + 3 * fc->delay.rel_value) / 4;
+        (ndelay.rel_value / fc->num_transmissions + 3 * fc->delay.rel_value) / 4;
+    fc->num_transmissions = 0;
   }
   GNUNET_STATISTICS_update (fc->stats,
                             _("# fragment acknowledgements received"), 1,