gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r27037 - gnunet/src/regex


From: gnunet
Subject: [GNUnet-SVN] r27037 - gnunet/src/regex
Date: Mon, 6 May 2013 14:59:01 +0200

Author: bartpolot
Date: 2013-05-06 14:59:01 +0200 (Mon, 06 May 2013)
New Revision: 27037

Modified:
   gnunet/src/regex/gnunet-regex-profiler.c
Log:
- speed up shutdown

Modified: gnunet/src/regex/gnunet-regex-profiler.c
===================================================================
--- gnunet/src/regex/gnunet-regex-profiler.c    2013-05-06 12:33:43 UTC (rev 
27036)
+++ gnunet/src/regex/gnunet-regex-profiler.c    2013-05-06 12:59:01 UTC (rev 
27037)
@@ -183,6 +183,10 @@
   struct GNUNET_TESTBED_Operation *daemon_op;
 };
 
+/**
+ * Set when shutting down to avoid making more queries.
+ */
+static int in_shutdown;
 
 /**
  * The array of peers; we fill this as the peers are given to us by the testbed
@@ -290,9 +294,9 @@
 static unsigned int parallel_searches;
 
 /**
- * Number of peers found with search strings.
+ * Number of strings found in the published regexes.
  */
-static unsigned int peers_found;
+static unsigned int strings_found;
 
 /**
  * Index of peer to start next announce/search.
@@ -747,14 +751,15 @@
     return;
   }
 
-  peers_found++;
+  strings_found++;
   parallel_searches--;
 
   if (GNUNET_SCHEDULER_NO_TASK != peer->timeout)
   {
     GNUNET_SCHEDULER_cancel (peer->timeout);
     peer->timeout = GNUNET_SCHEDULER_NO_TASK;
-    GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL);
+    if (GNUNET_NO == in_shutdown)
+      GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL);
   }
 
   if (NULL == id)
@@ -762,7 +767,7 @@
     // FIXME not possible right now
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "String matching timed out for string %s on peer %u (%i/%i)\n",
-                peer->search_str, peer->id, peers_found, num_search_strings);
+                peer->search_str, peer->id, strings_found, num_search_strings);
     peer->search_str_matched = GNUNET_SYSERR;
   }
   else
@@ -773,7 +778,7 @@
                 "String %s found on peer %u after %s (%i/%i) (%u||)\n",
                 peer->search_str, peer->id,
                 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO),
-                peers_found, num_search_strings, parallel_searches);
+                strings_found, num_search_strings, parallel_searches);
 
     peer->search_str_matched = GNUNET_YES;
 
@@ -799,7 +804,7 @@
   GNUNET_TESTBED_operation_done (peer->op_handle);
   peer->op_handle = NULL;
 
-  if (peers_found == num_search_strings)
+  if (strings_found == num_search_strings)
   {
     prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -823,14 +828,16 @@
  * @param tc the task context
  */
 static void
-search_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+search_timed_out (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
 {
+  unsigned int i;
+
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Finding matches to all strings did not succeed after %s.\n",
               GNUNET_STRINGS_relative_time_to_string (search_timeout_time,
                                                       GNUNET_NO));
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Found %i of %i strings\n", peers_found, num_search_strings);
+              "Found %i of %i strings\n", strings_found, num_search_strings);
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Search timed out after %s."
@@ -838,6 +845,15 @@
               GNUNET_STRINGS_relative_time_to_string (search_timeout_time,
                                                       GNUNET_NO));
 
+  in_shutdown = GNUNET_YES;
+  for (i = 0; i < num_peers; i++)
+  {
+    if (NULL != peers[i].op_handle)
+    {
+      GNUNET_TESTBED_operation_done (peers[i].op_handle);
+      peers[i].op_handle = NULL;
+    }
+  }
   GNUNET_SCHEDULER_add_now (&do_collect_stats, NULL);
 }
 
@@ -850,7 +866,7 @@
  * @param tc TaskContext.
  */
 static void
-find_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+find_timed_out (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct RegexPeer *p = cls;
 
@@ -859,10 +875,13 @@
   if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
     return;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-              "Searching for string \"%s\" on peer %d timed out. Starting new 
search.\n",
+              "Searching for string \"%s\" on peer %d timed out."
+              "Starting new search: %d.\n",
               p->search_str,
-              p->id);
-  GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL);
+              p->id,
+              !in_shutdown);
+  if (GNUNET_NO == in_shutdown)
+    GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL);
 }
 
 
@@ -898,7 +917,7 @@
                                     &peers[search_peer]);
   GNUNET_assert (NULL != peers[search_peer].op_handle);
   peers[search_peer].timeout = GNUNET_SCHEDULER_add_delayed (FIND_TIMEOUT,
-                                                          &find_timeout,
+                                                          &find_timed_out,
                                                           &peers[search_peer]);
 }
 
@@ -1123,7 +1142,7 @@
   }
   GNUNET_SCHEDULER_add_now (&do_announce, NULL);
   search_timeout_task =
-      GNUNET_SCHEDULER_add_delayed (search_timeout_time, &search_timeout, 
NULL);
+      GNUNET_SCHEDULER_add_delayed (search_timeout_time, &search_timed_out, 
NULL);
 }
 
 /**
@@ -1242,7 +1261,9 @@
 {
   unsigned int nsearchstrs;
   unsigned int i;
-  
+
+  in_shutdown = GNUNET_NO;
+
   /* Check config */
   if (NULL == config)
   {
@@ -1397,7 +1418,7 @@
      gettext_noop ("name of the file for writing statistics"),
      GNUNET_YES, &GNUNET_GETOPT_set_string, &data_filename},
     {'t', "matching-timeout", "TIMEOUT",
-      gettext_noop ("wait TIMEOUT before considering a string match as 
failed"),
+      gettext_noop ("wait TIMEOUT before ending the experiment"),
       GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_timeout_time },
     {'n', "num-search-strings", "COUNT",
       gettext_noop ("number of search strings to read from search strings 
file"),




reply via email to

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