gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r7442 - GNUnet/src/applications/fs/fsui


From: gnunet
Subject: [GNUnet-SVN] r7442 - GNUnet/src/applications/fs/fsui
Date: Wed, 16 Jul 2008 23:42:30 -0600 (MDT)

Author: grothoff
Date: 2008-07-16 23:42:30 -0600 (Wed, 16 Jul 2008)
New Revision: 7442

Modified:
   GNUnet/src/applications/fs/fsui/deserialize.c
   GNUnet/src/applications/fs/fsui/download.c
   GNUnet/src/applications/fs/fsui/fsui.h
Log:
fixing Mantis 1387

Modified: GNUnet/src/applications/fs/fsui/deserialize.c
===================================================================
--- GNUnet/src/applications/fs/fsui/deserialize.c       2008-07-17 05:10:36 UTC 
(rev 7441)
+++ GNUnet/src/applications/fs/fsui/deserialize.c       2008-07-17 05:42:30 UTC 
(rev 7442)
@@ -307,6 +307,8 @@
       GNUNET_free (ret);
       return NULL;
     }
+  ret->lastProgressTime = GNUNET_get_time();
+  ret->progressBits = 1;
   fixState (&ret->state);
   ret->filename = GNUNET_malloc (big + 1);
   ret->filename[big] = '\0';

Modified: GNUnet/src/applications/fs/fsui/download.c
===================================================================
--- GNUnet/src/applications/fs/fsui/download.c  2008-07-17 05:10:36 UTC (rev 
7441)
+++ GNUnet/src/applications/fs/fsui/download.c  2008-07-17 05:42:30 UTC (rev 
7442)
@@ -205,7 +205,39 @@
 }
 
 
+/**
+ * Update the progress bits (shifting).
+ */
+static void
+update_progress_bits(GNUNET_CronTime now,
+                    GNUNET_FSUI_DownloadList * dl)
+{
+  GNUNET_CronTime delta;
+  unsigned int minutes;
 
+  if (now < dl->lastProgressTime)
+    {
+      GNUNET_GE_BREAK(NULL, 0);
+      return;
+    }
+  delta = now - dl->lastProgressTime;
+  minutes = delta / GNUNET_CRON_MINUTES;
+  if (minutes == 0)
+    return;
+  if (minutes > 64)
+    {
+      dl->progressBits = 0;
+      dl->lastProgressTime = now;
+      return;
+    }
+  dl->progressBits <<= minutes;
+  if (dl->progressBits == 0)
+    dl->lastProgressTime = now;
+  else
+    dl->lastProgressTime += minutes * GNUNET_CRON_MINUTES;
+}
+
+
 /**
  * Progress notification from ECRS.  Tell FSUI client.
  */
@@ -222,6 +254,9 @@
   GNUNET_CronTime now;
   GNUNET_CronTime run_time;
 
+  now = GNUNET_get_time ();
+  update_progress_bits(now, dl);
+  dl->progressBits |= 1;
   if (dl->total + 1 == totalBytes)
     {
       /* error! */
@@ -256,7 +291,6 @@
   event.data.DownloadProgress.completed = dl->completed;
   event.data.DownloadProgress.total = dl->total;
   event.data.DownloadProgress.last_offset = lastBlockOffset;
-  now = GNUNET_get_time ();
   run_time = now - dl->startTime;
   if ((dl->total == 0) || (dl->completed == 0))
     {
@@ -338,6 +372,8 @@
   dl->total = GNUNET_ECRS_uri_get_file_size (uri);
   dl->child = NULL;
   dl->cctx = NULL;
+  dl->lastProgressTime = GNUNET_get_time();
+  dl->progressBits = 1;
   /* signal start! */
   event.type = GNUNET_FSUI_download_started;
   event.data.DownloadStarted.dc.pos = dl;
@@ -411,6 +447,7 @@
   struct GNUNET_GE_Context *ectx;
   GNUNET_FSUI_DownloadList *dpos;
   GNUNET_FSUI_Event event;
+  GNUNET_CronTime now;
   int ret;
 
   if (list == NULL)
@@ -425,10 +462,13 @@
                  list->ctx->activeDownloadThreads, list->ctx->threadPoolSize);
 #endif
   ret = GNUNET_NO;
+  now = GNUNET_get_time();
   /* should this one be started? */
   if ((list->ctx->threadPoolSize
        > list->ctx->activeDownloadThreads) &&
       (list->state == GNUNET_FSUI_PENDING) &&
+      ( (list->block_resume < now) ||
+       (list->ctx->threadPoolSize > list->ctx->activeDownloadThreads + 1) ) &&
       ((list->total > list->completed) || (list->total == 0)))
     {
 #if DEBUG_DTM
@@ -438,7 +478,7 @@
                      list->filename);
 #endif
       list->state = GNUNET_FSUI_ACTIVE;
-      list->startTime = GNUNET_get_time () - list->runTime;
+      list->startTime = now - list->runTime;
       list->handle =
         GNUNET_ECRS_file_download_partial_start (list->ctx->ectx,
                                                  list->ctx->cfg,
@@ -451,17 +491,27 @@
                                                  GNUNET_NO,
                                                  &downloadProgressCallback,
                                                  list);
+      list->progressBits = 1;
+      list->lastProgressTime = now;
       if (list->handle != NULL)
         list->ctx->activeDownloadThreads++;
       else
         list->state = GNUNET_FSUI_ERROR_JOINED;
     }
-
+  if (list->state == GNUNET_FSUI_ACTIVE)
+    update_progress_bits(now, list);
   /* should this one be stopped? */
-  if ((list->ctx->threadPoolSize
-       < list->ctx->activeDownloadThreads)
-      && (list->state == GNUNET_FSUI_ACTIVE))
+  if ( (list->state == GNUNET_FSUI_ACTIVE) &&
+       ( (list->ctx->threadPoolSize
+         < list->ctx->activeDownloadThreads) ||
+        ( (list->ctx->threadPoolSize == list->ctx->activeDownloadThreads) &&
+          (0 == (list->progressBits & GNUNET_FSUI_DL_KILL_TIME_MASK)) ) ) )
     {
+      if ( (list->ctx->threadPoolSize == list->ctx->activeDownloadThreads) &&
+          (0 == (list->progressBits & GNUNET_FSUI_DL_KILL_TIME_MASK)) )
+       list->block_resume = now + GNUNET_FSUI_DL_KILL_PERIOD;  
+      else
+       list->block_resume = 0;
 #if DEBUG_DTM
       GNUNET_GE_LOG (ectx,
                      GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
@@ -582,7 +632,7 @@
       GNUNET_ECRS_file_download_partial_stop (dl->handle);
       dl->handle = NULL;
       dl->ctx->activeDownloadThreads--;
-      dl->runTime = GNUNET_get_time () - dl->startTime;
+      dl->runTime = GNUNET_get_time() - dl->startTime;
       event.type = GNUNET_FSUI_download_aborted;
       event.data.DownloadAborted.dc.pos = dl;
       event.data.DownloadAborted.dc.cctx = dl->cctx;
@@ -663,7 +713,7 @@
       GNUNET_GE_ASSERT (ctx->ectx, dl->handle != NULL);
       GNUNET_ECRS_file_download_partial_stop (dl->handle);
       dl->handle = NULL;
-      dl->runTime = GNUNET_get_time () - dl->startTime;
+      dl->runTime = GNUNET_get_time() - dl->startTime;
       GNUNET_mutex_lock (ctx->lock);
       dl->ctx->activeDownloadThreads--;
       GNUNET_mutex_unlock (ctx->lock);

Modified: GNUnet/src/applications/fs/fsui/fsui.h
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui.h      2008-07-17 05:10:36 UTC (rev 
7441)
+++ GNUnet/src/applications/fs/fsui/fsui.h      2008-07-17 05:42:30 UTC (rev 
7442)
@@ -48,7 +48,37 @@
  */
 #define GNUNET_FSUI_HARD_PROBE_LIMIT 128
 
+
 /**
+ * If we have more downloads pending then we
+ * can support concurrently, after how much
+ * runtime of a download (without progress)
+ * should we consider pausing it to give others
+ * a chance?  Specified as a bit-mask where 
+ * each bit represents a minute of time.
+ * (0xFF == 8 minutes, 0x7FFF == 15 minutes).
+ * Note that all legal values correspond to
+ * values computable using "(1 << (N+1))-1"
+ * Where "N" would be the number of minutes
+ * without progress.  A 64-bit value is
+ * permissable.<p>
+ *
+ * Note that downloads will NOT be automatically
+ * paused even if they do not make any progress
+ * UNLESS all download threads are in use.
+ */
+#define GNUNET_FSUI_DL_KILL_TIME_MASK 0x7FFF
+
+/**
+ * If a download was paused because it failed
+ * to make any progress and because other downloads
+ * were pending, how long until we may try it again
+ * (assuming that our download queues continue to
+ * be entirely filled the whole time)?
+ */
+#define GNUNET_FSUI_DL_KILL_PERIOD (6 * GNUNET_CRON_HOURS)
+
+/**
  * Track record for a given result.
  */
 struct SearchResultList
@@ -236,6 +266,12 @@
   unsigned long long completed;
 
   /**
+   * Bit (1 << T) is set to 1 if we made any progress
+   * "T" minutes ago.
+   */
+  unsigned long long progressBits;
+
+  /**
    * URI for this download.
    */
   GNUNET_ECRS_FileInfo fi;
@@ -307,6 +343,18 @@
   GNUNET_CronTime runTime;
 
   /**
+   * Last time we updated (shifted) our progressBits.
+   */
+  GNUNET_CronTime lastProgressTime;
+
+  /**
+   * How long is this thread blocked from resuming if
+   * all download queues are busy? (only
+   * valid if the thread state is FSUI_PENDING).
+   */
+  GNUNET_CronTime block_resume;
+
+  /**
    * Is this a recursive download? (GNUNET_YES/GNUNET_NO)
    * Also set to GNUNET_NO once the recursive downloads
    * have been triggered!





reply via email to

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