diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-03-18 18:03:52 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-03-18 18:03:52 +0000 |
commit | ca39427d26e560d3ca74580825e1635b1dae4166 (patch) | |
tree | 9e03384adf7b2a76707ebabbeb04ec4f9ee538e9 /src/regex | |
parent | cb7ec932e36aec4b8c00bb8c71dc3068dc368865 (diff) | |
download | gnunet-ca39427d26e560d3ca74580825e1635b1dae4166.tar.gz gnunet-ca39427d26e560d3ca74580825e1635b1dae4166.zip |
- Change profiler to start search with a delay realtive to the announcement
Diffstat (limited to 'src/regex')
-rw-r--r-- | src/regex/gnunet-regex-profiler.c | 141 |
1 files changed, 73 insertions, 68 deletions
diff --git a/src/regex/gnunet-regex-profiler.c b/src/regex/gnunet-regex-profiler.c index 6adbd15b2..991cd40f3 100644 --- a/src/regex/gnunet-regex-profiler.c +++ b/src/regex/gnunet-regex-profiler.c | |||
@@ -37,7 +37,7 @@ | |||
37 | #include "gnunet_testbed_service.h" | 37 | #include "gnunet_testbed_service.h" |
38 | 38 | ||
39 | #define FIND_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90) | 39 | #define FIND_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90) |
40 | #define SEARCHES_IN_PARALLEL 10 | 40 | #define SEARCHES_IN_PARALLEL 100 |
41 | #define ANNOUNCE_DELAY GNUNET_TIME_relative_multiply(\ | 41 | #define ANNOUNCE_DELAY GNUNET_TIME_relative_multiply(\ |
42 | GNUNET_TIME_UNIT_MILLISECONDS,\ | 42 | GNUNET_TIME_UNIT_MILLISECONDS,\ |
43 | 300) | 43 | 300) |
@@ -352,6 +352,11 @@ static unsigned int peer_cnt; | |||
352 | static unsigned int peers_found; | 352 | static unsigned int peers_found; |
353 | 353 | ||
354 | /** | 354 | /** |
355 | * Index of peer to start next announce/search.. | ||
356 | */ | ||
357 | static unsigned int search_index; | ||
358 | |||
359 | /** | ||
355 | * Search task identifier | 360 | * Search task identifier |
356 | */ | 361 | */ |
357 | static GNUNET_SCHEDULER_TaskIdentifier search_task; | 362 | static GNUNET_SCHEDULER_TaskIdentifier search_task; |
@@ -364,7 +369,7 @@ static GNUNET_SCHEDULER_TaskIdentifier search_timeout_task; | |||
364 | /** | 369 | /** |
365 | * Search timeout in seconds. | 370 | * Search timeout in seconds. |
366 | */ | 371 | */ |
367 | static struct GNUNET_TIME_Relative search_timeout = { 60000 }; | 372 | static struct GNUNET_TIME_Relative search_timeout_time = { 60000 }; |
368 | 373 | ||
369 | /** | 374 | /** |
370 | * How long do we wait before starting the search? | 375 | * How long do we wait before starting the search? |
@@ -460,6 +465,16 @@ static void | |||
460 | do_collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 465 | do_collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
461 | 466 | ||
462 | 467 | ||
468 | /** | ||
469 | * Start announcing the next regex in the DHT. | ||
470 | * | ||
471 | * @param cls Index of the next peer in the peers array. | ||
472 | * @param tc TaskContext. | ||
473 | */ | ||
474 | static void | ||
475 | announce_next_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
476 | |||
477 | |||
463 | /******************************************************************************/ | 478 | /******************************************************************************/ |
464 | /******************************** SHUTDOWN **********************************/ | 479 | /******************************** SHUTDOWN **********************************/ |
465 | /******************************************************************************/ | 480 | /******************************************************************************/ |
@@ -787,7 +802,7 @@ do_collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
787 | * @param tc TaskContext. | 802 | * @param tc TaskContext. |
788 | */ | 803 | */ |
789 | static void | 804 | static void |
790 | find_next_string (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 805 | find_string (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
791 | 806 | ||
792 | 807 | ||
793 | /** | 808 | /** |
@@ -828,7 +843,7 @@ regex_found_handler (void *cls, | |||
828 | { | 843 | { |
829 | GNUNET_SCHEDULER_cancel (peer->timeout); | 844 | GNUNET_SCHEDULER_cancel (peer->timeout); |
830 | peer->timeout = GNUNET_SCHEDULER_NO_TASK; | 845 | peer->timeout = GNUNET_SCHEDULER_NO_TASK; |
831 | GNUNET_SCHEDULER_add_delayed (SEARCH_DELAY, &find_next_string, NULL); | 846 | GNUNET_SCHEDULER_add_delayed (SEARCH_DELAY, &announce_next_regex, NULL); |
832 | } | 847 | } |
833 | 848 | ||
834 | if (NULL == id) | 849 | if (NULL == id) |
@@ -899,19 +914,20 @@ regex_found_handler (void *cls, | |||
899 | * @param tc the task context | 914 | * @param tc the task context |
900 | */ | 915 | */ |
901 | static void | 916 | static void |
902 | do_connect_by_string_timeout (void *cls, | 917 | search_timeout (void *cls, |
903 | const struct GNUNET_SCHEDULER_TaskContext * tc) | 918 | const struct GNUNET_SCHEDULER_TaskContext * tc) |
904 | { | 919 | { |
905 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 920 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
906 | "Finding matches to all strings did not succeed after %s.\n", | 921 | "Finding matches to all strings did not succeed after %s.\n", |
907 | GNUNET_STRINGS_relative_time_to_string (search_timeout, GNUNET_NO)); | 922 | GNUNET_STRINGS_relative_time_to_string (search_timeout_time, |
923 | GNUNET_NO)); | ||
908 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 924 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
909 | "Found %i of %i strings\n", peers_found, num_search_strings); | 925 | "Found %i of %i strings\n", peers_found, num_search_strings); |
910 | 926 | ||
911 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 927 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
912 | "Search timed out after %s." | 928 | "Search timed out after %s." |
913 | "Collecting stats and shutting down.\n", | 929 | "Collecting stats and shutting down.\n", |
914 | GNUNET_STRINGS_relative_time_to_string (search_timeout, | 930 | GNUNET_STRINGS_relative_time_to_string (search_timeout_time, |
915 | GNUNET_NO)); | 931 | GNUNET_NO)); |
916 | 932 | ||
917 | GNUNET_SCHEDULER_add_now (&do_collect_stats, NULL); | 933 | GNUNET_SCHEDULER_add_now (&do_collect_stats, NULL); |
@@ -919,29 +935,6 @@ do_connect_by_string_timeout (void *cls, | |||
919 | 935 | ||
920 | 936 | ||
921 | /** | 937 | /** |
922 | * Connect by string task that is run to search for a string in the | ||
923 | * NFA. It first connects to the mesh service and when a connection is | ||
924 | * established it starts to search for the string. | ||
925 | * | ||
926 | * @param cls NULL | ||
927 | * @param tc the task context | ||
928 | */ | ||
929 | static void | ||
930 | do_connect_by_string (void *cls, | ||
931 | const struct GNUNET_SCHEDULER_TaskContext * tc) | ||
932 | { | ||
933 | unsigned int i; | ||
934 | |||
935 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting string search.\n"); | ||
936 | |||
937 | search_timeout_task = GNUNET_SCHEDULER_add_delayed (search_timeout, | ||
938 | &do_connect_by_string_timeout, NULL); | ||
939 | for (i = 0; i < SEARCHES_IN_PARALLEL; i++) | ||
940 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &find_next_string, NULL); | ||
941 | } | ||
942 | |||
943 | |||
944 | /** | ||
945 | * Search timed out. It might still complete in the future, | 938 | * Search timed out. It might still complete in the future, |
946 | * but we should start another one. | 939 | * but we should start another one. |
947 | * | 940 | * |
@@ -961,18 +954,18 @@ find_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
961 | "Searching for string \"%s\" on peer %d timed out. Starting new search.\n", | 954 | "Searching for string \"%s\" on peer %d timed out. Starting new search.\n", |
962 | p->search_str, | 955 | p->search_str, |
963 | p->id); | 956 | p->id); |
964 | GNUNET_SCHEDULER_add_now (&find_next_string, NULL); | 957 | GNUNET_SCHEDULER_add_now (&announce_next_regex, NULL); |
965 | } | 958 | } |
966 | 959 | ||
967 | 960 | ||
968 | /** | 961 | /** |
969 | * Start searching for the next string in the DHT. | 962 | * Start searching for a string in the DHT. |
970 | * | 963 | * |
971 | * @param cls Index of the next peer in the peers array. | 964 | * @param cls Index of the next peer in the peers array. |
972 | * @param tc TaskContext. | 965 | * @param tc TaskContext. |
973 | */ | 966 | */ |
974 | static void | 967 | static void |
975 | find_next_string (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 968 | find_string (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
976 | { | 969 | { |
977 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) || | 970 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) || |
978 | peer_cnt >= num_search_strings) | 971 | peer_cnt >= num_search_strings) |
@@ -1004,17 +997,6 @@ find_next_string (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1004 | } | 997 | } |
1005 | 998 | ||
1006 | 999 | ||
1007 | |||
1008 | /** | ||
1009 | * Start announcing the next regex in the DHT. | ||
1010 | * | ||
1011 | * @param cls Index of the next peer in the peers array. | ||
1012 | * @param tc TaskContext. | ||
1013 | */ | ||
1014 | static void | ||
1015 | announce_next_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
1016 | |||
1017 | |||
1018 | /** | 1000 | /** |
1019 | * ARM connect adapter. Opens a connection to the ARM service. | 1001 | * ARM connect adapter. Opens a connection to the ARM service. |
1020 | * | 1002 | * |
@@ -1072,14 +1054,22 @@ arm_op_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1072 | peer->op_handle = NULL; | 1054 | peer->op_handle = NULL; |
1073 | } | 1055 | } |
1074 | 1056 | ||
1057 | |||
1058 | /** | ||
1059 | * Callback called when arm has started the daemon we asked for. | ||
1060 | * | ||
1061 | * @param cls Closure (). | ||
1062 | * @param arm Arm handle. | ||
1063 | * @param rs Status of the request. | ||
1064 | * @param service Service we asked to start (deamon). | ||
1065 | * @param result Result of the request. | ||
1066 | */ | ||
1075 | static void | 1067 | static void |
1076 | arm_start_cb (void *cls, struct GNUNET_ARM_Handle *arm, | 1068 | arm_start_cb (void *cls, struct GNUNET_ARM_Handle *arm, |
1077 | enum GNUNET_ARM_RequestStatus rs, const char *service, | 1069 | enum GNUNET_ARM_RequestStatus rs, const char *service, |
1078 | enum GNUNET_ARM_Result result) | 1070 | enum GNUNET_ARM_Result result) |
1079 | { | 1071 | { |
1080 | struct RegexPeer *peer = (struct RegexPeer *) cls; | 1072 | struct RegexPeer *peer = (struct RegexPeer *) cls; |
1081 | static unsigned int arm_peer_cnt; | ||
1082 | unsigned int next_p; | ||
1083 | 1073 | ||
1084 | if (rs != GNUNET_ARM_REQUEST_SENT_OK) | 1074 | if (rs != GNUNET_ARM_REQUEST_SENT_OK) |
1085 | { | 1075 | { |
@@ -1101,12 +1091,24 @@ arm_start_cb (void *cls, struct GNUNET_ARM_Handle *arm, | |||
1101 | case GNUNET_ARM_RESULT_STARTING: | 1091 | case GNUNET_ARM_RESULT_STARTING: |
1102 | GNUNET_SCHEDULER_add_now (&arm_op_done, peer); | 1092 | GNUNET_SCHEDULER_add_now (&arm_op_done, peer); |
1103 | 1093 | ||
1104 | if (arm_peer_cnt < (num_peers - 1)) | 1094 | if (search_index < (num_peers - 1)) |
1105 | { | 1095 | { |
1106 | next_p = (++arm_peer_cnt % num_peers); | 1096 | long search_peer; |
1107 | GNUNET_SCHEDULER_add_delayed (ANNOUNCE_DELAY, | 1097 | unsigned int i = 0; |
1108 | &announce_next_regex, | 1098 | |
1109 | (void *) (long) next_p); | 1099 | /* Find a peer to look for a string matching the regex announced */ |
1100 | search_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1101 | num_peers); | ||
1102 | for (i = 0; peers[search_peer].search_str != NULL; i++) | ||
1103 | { | ||
1104 | search_peer = (search_peer + 1) % num_peers; | ||
1105 | if (i > num_peers) | ||
1106 | GNUNET_abort (); /* we run out of peers, must be a bug */ | ||
1107 | } | ||
1108 | peers[search_peer].search_str = search_strings[search_index]; | ||
1109 | GNUNET_SCHEDULER_add_delayed (SEARCH_DELAY, | ||
1110 | &find_string, | ||
1111 | (void *) search_peer); | ||
1110 | } | 1112 | } |
1111 | else | 1113 | else |
1112 | { | 1114 | { |
@@ -1115,9 +1117,10 @@ arm_start_cb (void *cls, struct GNUNET_ARM_Handle *arm, | |||
1115 | " Waiting %s to start string searches\n", | 1117 | " Waiting %s to start string searches\n", |
1116 | GNUNET_STRINGS_relative_time_to_string (search_delay, | 1118 | GNUNET_STRINGS_relative_time_to_string (search_delay, |
1117 | GNUNET_NO)); | 1119 | GNUNET_NO)); |
1118 | GNUNET_SCHEDULER_add_delayed (search_delay, | 1120 | /* FIXME start GLOBAL timeout to abort experiment */ |
1119 | do_connect_by_string, | 1121 | search_timeout_task = GNUNET_SCHEDULER_add_delayed (search_timeout_time, |
1120 | NULL); | 1122 | &search_timeout, |
1123 | NULL); | ||
1121 | } | 1124 | } |
1122 | break; | 1125 | break; |
1123 | 1126 | ||
@@ -1172,46 +1175,47 @@ do_announce (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1172 | { | 1175 | { |
1173 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting announce.\n"); | 1176 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting announce.\n"); |
1174 | 1177 | ||
1178 | for (search_index = 0; search_index < SEARCHES_IN_PARALLEL; search_index++) | ||
1179 | { | ||
1175 | /* First connect to arm service, then announce. Next | 1180 | /* First connect to arm service, then announce. Next |
1176 | announce will be in arm_connect_cb */ | 1181 | announce will be in arm_connect_cb */ |
1177 | peers[0].op_handle = | 1182 | peers[search_index].op_handle = |
1178 | GNUNET_TESTBED_service_connect (NULL, | 1183 | GNUNET_TESTBED_service_connect (NULL, |
1179 | peers[0].peer_handle, | 1184 | peers[search_index].peer_handle, |
1180 | "arm", | 1185 | "arm", |
1181 | &arm_connect_cb, | 1186 | &arm_connect_cb, |
1182 | &peers[0], | 1187 | &peers[search_index], |
1183 | &arm_ca, | 1188 | &arm_ca, |
1184 | &arm_da, | 1189 | &arm_da, |
1185 | &peers[0]); | 1190 | &peers[search_index]); |
1186 | 1191 | parallel_searches++; | |
1192 | } | ||
1187 | } | 1193 | } |
1188 | 1194 | ||
1189 | 1195 | ||
1190 | /** | 1196 | /** |
1191 | * Start announcing the next regex in the DHT. | 1197 | * Start announcing the next regex in the DHT. |
1192 | * | 1198 | * |
1193 | * @param cls Index of the next peer in the peers array. | 1199 | * @param cls Closure (unused). |
1194 | * @param tc TaskContext. | 1200 | * @param tc TaskContext. |
1195 | */ | 1201 | */ |
1196 | static void | 1202 | static void |
1197 | announce_next_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1203 | announce_next_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1198 | { | 1204 | { |
1199 | long next_p = (long) cls; | ||
1200 | |||
1201 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1205 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1202 | return; | 1206 | return; |
1203 | 1207 | ||
1204 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting daemon %ld\n", next_p); | 1208 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting daemon %u\n", search_index); |
1205 | 1209 | ||
1206 | peers[next_p].op_handle = | 1210 | peers[search_index].op_handle = |
1207 | GNUNET_TESTBED_service_connect (NULL, | 1211 | GNUNET_TESTBED_service_connect (NULL, |
1208 | peers[next_p].peer_handle, | 1212 | peers[search_index].peer_handle, |
1209 | "arm", | 1213 | "arm", |
1210 | &arm_connect_cb, | 1214 | &arm_connect_cb, |
1211 | &peers[next_p], | 1215 | &peers[search_index], |
1212 | &arm_ca, | 1216 | &arm_ca, |
1213 | &arm_da, | 1217 | &arm_da, |
1214 | &peers[next_p]); | 1218 | &peers[search_index]); |
1215 | } | 1219 | } |
1216 | 1220 | ||
1217 | /** | 1221 | /** |
@@ -2091,7 +2095,8 @@ main (int argc, char *const *argv) | |||
2091 | GNUNET_YES, &GNUNET_GETOPT_set_uint, &linking_factor }, | 2095 | GNUNET_YES, &GNUNET_GETOPT_set_uint, &linking_factor }, |
2092 | {'t', "matching-timeout", "TIMEOUT", | 2096 | {'t', "matching-timeout", "TIMEOUT", |
2093 | gettext_noop ("wait TIMEOUT before considering a string match as failed"), | 2097 | gettext_noop ("wait TIMEOUT before considering a string match as failed"), |
2094 | GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_timeout }, | 2098 | GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_timeout_time |
2099 | }, | ||
2095 | {'s', "search-delay", "DELAY", | 2100 | {'s', "search-delay", "DELAY", |
2096 | gettext_noop ("wait DELAY before starting string search"), | 2101 | gettext_noop ("wait DELAY before starting string search"), |
2097 | GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_delay }, | 2102 | GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_delay }, |