diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-05-06 12:59:01 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-05-06 12:59:01 +0000 |
commit | 629389ce6a11921b5324f236bc3b4fd497ada9ac (patch) | |
tree | 00251894929fac87f540aecdedff855c9ac08f35 /src/regex | |
parent | 5a5b055a63c56b5c2581c10a9704f596dba612e2 (diff) | |
download | gnunet-629389ce6a11921b5324f236bc3b4fd497ada9ac.tar.gz gnunet-629389ce6a11921b5324f236bc3b4fd497ada9ac.zip |
- speed up shutdown
Diffstat (limited to 'src/regex')
-rw-r--r-- | src/regex/gnunet-regex-profiler.c | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/src/regex/gnunet-regex-profiler.c b/src/regex/gnunet-regex-profiler.c index 1764884b9..a533f04c9 100644 --- a/src/regex/gnunet-regex-profiler.c +++ b/src/regex/gnunet-regex-profiler.c | |||
@@ -183,6 +183,10 @@ struct RegexPeer | |||
183 | struct GNUNET_TESTBED_Operation *daemon_op; | 183 | struct GNUNET_TESTBED_Operation *daemon_op; |
184 | }; | 184 | }; |
185 | 185 | ||
186 | /** | ||
187 | * Set when shutting down to avoid making more queries. | ||
188 | */ | ||
189 | static int in_shutdown; | ||
186 | 190 | ||
187 | /** | 191 | /** |
188 | * The array of peers; we fill this as the peers are given to us by the testbed | 192 | * The array of peers; we fill this as the peers are given to us by the testbed |
@@ -290,9 +294,9 @@ static long long unsigned int init_parallel_searches; | |||
290 | static unsigned int parallel_searches; | 294 | static unsigned int parallel_searches; |
291 | 295 | ||
292 | /** | 296 | /** |
293 | * Number of peers found with search strings. | 297 | * Number of strings found in the published regexes. |
294 | */ | 298 | */ |
295 | static unsigned int peers_found; | 299 | static unsigned int strings_found; |
296 | 300 | ||
297 | /** | 301 | /** |
298 | * Index of peer to start next announce/search. | 302 | * Index of peer to start next announce/search. |
@@ -747,14 +751,15 @@ regex_found_handler (void *cls, | |||
747 | return; | 751 | return; |
748 | } | 752 | } |
749 | 753 | ||
750 | peers_found++; | 754 | strings_found++; |
751 | parallel_searches--; | 755 | parallel_searches--; |
752 | 756 | ||
753 | if (GNUNET_SCHEDULER_NO_TASK != peer->timeout) | 757 | if (GNUNET_SCHEDULER_NO_TASK != peer->timeout) |
754 | { | 758 | { |
755 | GNUNET_SCHEDULER_cancel (peer->timeout); | 759 | GNUNET_SCHEDULER_cancel (peer->timeout); |
756 | peer->timeout = GNUNET_SCHEDULER_NO_TASK; | 760 | peer->timeout = GNUNET_SCHEDULER_NO_TASK; |
757 | GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL); | 761 | if (GNUNET_NO == in_shutdown) |
762 | GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL); | ||
758 | } | 763 | } |
759 | 764 | ||
760 | if (NULL == id) | 765 | if (NULL == id) |
@@ -762,7 +767,7 @@ regex_found_handler (void *cls, | |||
762 | // FIXME not possible right now | 767 | // FIXME not possible right now |
763 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 768 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
764 | "String matching timed out for string %s on peer %u (%i/%i)\n", | 769 | "String matching timed out for string %s on peer %u (%i/%i)\n", |
765 | peer->search_str, peer->id, peers_found, num_search_strings); | 770 | peer->search_str, peer->id, strings_found, num_search_strings); |
766 | peer->search_str_matched = GNUNET_SYSERR; | 771 | peer->search_str_matched = GNUNET_SYSERR; |
767 | } | 772 | } |
768 | else | 773 | else |
@@ -773,7 +778,7 @@ regex_found_handler (void *cls, | |||
773 | "String %s found on peer %u after %s (%i/%i) (%u||)\n", | 778 | "String %s found on peer %u after %s (%i/%i) (%u||)\n", |
774 | peer->search_str, peer->id, | 779 | peer->search_str, peer->id, |
775 | GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO), | 780 | GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO), |
776 | peers_found, num_search_strings, parallel_searches); | 781 | strings_found, num_search_strings, parallel_searches); |
777 | 782 | ||
778 | peer->search_str_matched = GNUNET_YES; | 783 | peer->search_str_matched = GNUNET_YES; |
779 | 784 | ||
@@ -799,7 +804,7 @@ regex_found_handler (void *cls, | |||
799 | GNUNET_TESTBED_operation_done (peer->op_handle); | 804 | GNUNET_TESTBED_operation_done (peer->op_handle); |
800 | peer->op_handle = NULL; | 805 | peer->op_handle = NULL; |
801 | 806 | ||
802 | if (peers_found == num_search_strings) | 807 | if (strings_found == num_search_strings) |
803 | { | 808 | { |
804 | prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time); | 809 | prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time); |
805 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 810 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -823,14 +828,16 @@ regex_found_handler (void *cls, | |||
823 | * @param tc the task context | 828 | * @param tc the task context |
824 | */ | 829 | */ |
825 | static void | 830 | static void |
826 | search_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 831 | search_timed_out (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) |
827 | { | 832 | { |
833 | unsigned int i; | ||
834 | |||
828 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 835 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
829 | "Finding matches to all strings did not succeed after %s.\n", | 836 | "Finding matches to all strings did not succeed after %s.\n", |
830 | GNUNET_STRINGS_relative_time_to_string (search_timeout_time, | 837 | GNUNET_STRINGS_relative_time_to_string (search_timeout_time, |
831 | GNUNET_NO)); | 838 | GNUNET_NO)); |
832 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 839 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
833 | "Found %i of %i strings\n", peers_found, num_search_strings); | 840 | "Found %i of %i strings\n", strings_found, num_search_strings); |
834 | 841 | ||
835 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 842 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
836 | "Search timed out after %s." | 843 | "Search timed out after %s." |
@@ -838,6 +845,15 @@ search_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
838 | GNUNET_STRINGS_relative_time_to_string (search_timeout_time, | 845 | GNUNET_STRINGS_relative_time_to_string (search_timeout_time, |
839 | GNUNET_NO)); | 846 | GNUNET_NO)); |
840 | 847 | ||
848 | in_shutdown = GNUNET_YES; | ||
849 | for (i = 0; i < num_peers; i++) | ||
850 | { | ||
851 | if (NULL != peers[i].op_handle) | ||
852 | { | ||
853 | GNUNET_TESTBED_operation_done (peers[i].op_handle); | ||
854 | peers[i].op_handle = NULL; | ||
855 | } | ||
856 | } | ||
841 | GNUNET_SCHEDULER_add_now (&do_collect_stats, NULL); | 857 | GNUNET_SCHEDULER_add_now (&do_collect_stats, NULL); |
842 | } | 858 | } |
843 | 859 | ||
@@ -850,7 +866,7 @@ search_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
850 | * @param tc TaskContext. | 866 | * @param tc TaskContext. |
851 | */ | 867 | */ |
852 | static void | 868 | static void |
853 | find_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 869 | find_timed_out (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
854 | { | 870 | { |
855 | struct RegexPeer *p = cls; | 871 | struct RegexPeer *p = cls; |
856 | 872 | ||
@@ -859,10 +875,13 @@ find_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
859 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 875 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
860 | return; | 876 | return; |
861 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 877 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
862 | "Searching for string \"%s\" on peer %d timed out. Starting new search.\n", | 878 | "Searching for string \"%s\" on peer %d timed out." |
879 | "Starting new search: %d.\n", | ||
863 | p->search_str, | 880 | p->search_str, |
864 | p->id); | 881 | p->id, |
865 | GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL); | 882 | !in_shutdown); |
883 | if (GNUNET_NO == in_shutdown) | ||
884 | GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL); | ||
866 | } | 885 | } |
867 | 886 | ||
868 | 887 | ||
@@ -898,7 +917,7 @@ find_string (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
898 | &peers[search_peer]); | 917 | &peers[search_peer]); |
899 | GNUNET_assert (NULL != peers[search_peer].op_handle); | 918 | GNUNET_assert (NULL != peers[search_peer].op_handle); |
900 | peers[search_peer].timeout = GNUNET_SCHEDULER_add_delayed (FIND_TIMEOUT, | 919 | peers[search_peer].timeout = GNUNET_SCHEDULER_add_delayed (FIND_TIMEOUT, |
901 | &find_timeout, | 920 | &find_timed_out, |
902 | &peers[search_peer]); | 921 | &peers[search_peer]); |
903 | } | 922 | } |
904 | 923 | ||
@@ -1123,7 +1142,7 @@ test_master (void *cls, | |||
1123 | } | 1142 | } |
1124 | GNUNET_SCHEDULER_add_now (&do_announce, NULL); | 1143 | GNUNET_SCHEDULER_add_now (&do_announce, NULL); |
1125 | search_timeout_task = | 1144 | search_timeout_task = |
1126 | GNUNET_SCHEDULER_add_delayed (search_timeout_time, &search_timeout, NULL); | 1145 | GNUNET_SCHEDULER_add_delayed (search_timeout_time, &search_timed_out, NULL); |
1127 | } | 1146 | } |
1128 | 1147 | ||
1129 | /** | 1148 | /** |
@@ -1242,7 +1261,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
1242 | { | 1261 | { |
1243 | unsigned int nsearchstrs; | 1262 | unsigned int nsearchstrs; |
1244 | unsigned int i; | 1263 | unsigned int i; |
1245 | 1264 | ||
1265 | in_shutdown = GNUNET_NO; | ||
1266 | |||
1246 | /* Check config */ | 1267 | /* Check config */ |
1247 | if (NULL == config) | 1268 | if (NULL == config) |
1248 | { | 1269 | { |
@@ -1397,7 +1418,7 @@ main (int argc, char *const *argv) | |||
1397 | gettext_noop ("name of the file for writing statistics"), | 1418 | gettext_noop ("name of the file for writing statistics"), |
1398 | GNUNET_YES, &GNUNET_GETOPT_set_string, &data_filename}, | 1419 | GNUNET_YES, &GNUNET_GETOPT_set_string, &data_filename}, |
1399 | {'t', "matching-timeout", "TIMEOUT", | 1420 | {'t', "matching-timeout", "TIMEOUT", |
1400 | gettext_noop ("wait TIMEOUT before considering a string match as failed"), | 1421 | gettext_noop ("wait TIMEOUT before ending the experiment"), |
1401 | GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_timeout_time }, | 1422 | GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_timeout_time }, |
1402 | {'n', "num-search-strings", "COUNT", | 1423 | {'n', "num-search-strings", "COUNT", |
1403 | gettext_noop ("number of search strings to read from search strings file"), | 1424 | gettext_noop ("number of search strings to read from search strings file"), |