diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-02-19 18:12:01 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-02-19 18:12:01 +0000 |
commit | 865dc2bbc65f14d0bf74834df8972f9499977f86 (patch) | |
tree | a12d8ac81b102855e88eaf88199c05204a8418e9 /src/regex | |
parent | fc1ad6f40db1b739f5218f9aedb6d4863693fe94 (diff) | |
download | gnunet-865dc2bbc65f14d0bf74834df8972f9499977f86.tar.gz gnunet-865dc2bbc65f14d0bf74834df8972f9499977f86.zip |
- Remove non-distributed seach: buggy and not useful
- Do search with a maximum parallel factor, starting a new one when an old one is done or times out
Diffstat (limited to 'src/regex')
-rw-r--r-- | src/regex/gnunet-regex-profiler.c | 134 |
1 files changed, 72 insertions, 62 deletions
diff --git a/src/regex/gnunet-regex-profiler.c b/src/regex/gnunet-regex-profiler.c index a0516fe90..25d4874bc 100644 --- a/src/regex/gnunet-regex-profiler.c +++ b/src/regex/gnunet-regex-profiler.c | |||
@@ -36,6 +36,9 @@ | |||
36 | #include "gnunet_dht_service.h" | 36 | #include "gnunet_dht_service.h" |
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) | ||
40 | #define SEARCHES_IN_PARALLEL 10 | ||
41 | |||
39 | /** | 42 | /** |
40 | * DLL of operations | 43 | * DLL of operations |
41 | */ | 44 | */ |
@@ -183,6 +186,11 @@ struct RegexPeer | |||
183 | * The starting time of a profiling step. | 186 | * The starting time of a profiling step. |
184 | */ | 187 | */ |
185 | struct GNUNET_TIME_Absolute prof_start_time; | 188 | struct GNUNET_TIME_Absolute prof_start_time; |
189 | |||
190 | /** | ||
191 | * Operation timeout | ||
192 | */ | ||
193 | GNUNET_SCHEDULER_TaskIdentifier timeout; | ||
186 | }; | 194 | }; |
187 | 195 | ||
188 | 196 | ||
@@ -328,6 +336,11 @@ static char **search_strings; | |||
328 | static int num_search_strings; | 336 | static int num_search_strings; |
329 | 337 | ||
330 | /** | 338 | /** |
339 | * Index of peer/string search. | ||
340 | */ | ||
341 | static unsigned int peer_cnt; | ||
342 | |||
343 | /** | ||
331 | * Number of peers found with search strings. | 344 | * Number of peers found with search strings. |
332 | */ | 345 | */ |
333 | static unsigned int peers_found; | 346 | static unsigned int peers_found; |
@@ -369,13 +382,6 @@ static char *data_filename; | |||
369 | static unsigned int max_path_compression; | 382 | static unsigned int max_path_compression; |
370 | 383 | ||
371 | /** | 384 | /** |
372 | * If we should distribute the search evenly throught all peers (each | ||
373 | * peer searches for a string) or if only one peer should search for | ||
374 | * all strings. | ||
375 | */ | ||
376 | static int no_distributed_search; | ||
377 | |||
378 | /** | ||
379 | * Prefix used for regex announcing. We need to prefix the search | 385 | * Prefix used for regex announcing. We need to prefix the search |
380 | * strings with it, in order to find something. | 386 | * strings with it, in order to find something. |
381 | */ | 387 | */ |
@@ -784,9 +790,20 @@ do_collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
784 | 790 | ||
785 | 791 | ||
786 | /******************************************************************************/ | 792 | /******************************************************************************/ |
787 | /************************ MESH SERVICE CONNECTIONS **************************/ | 793 | /************************ REGEX FIND CONNECTIONS **************************/ |
788 | /******************************************************************************/ | 794 | /******************************************************************************/ |
789 | 795 | ||
796 | |||
797 | /** | ||
798 | * Start searching for the next string in the DHT. | ||
799 | * | ||
800 | * @param cls Index of the next peer in the peers array. | ||
801 | * @param tc TaskContext. | ||
802 | */ | ||
803 | static void | ||
804 | find_next_string (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
805 | |||
806 | |||
790 | /** | 807 | /** |
791 | * Method called when we've found a peer that announced a regex | 808 | * Method called when we've found a peer that announced a regex |
792 | * that matches our search string. Now get the statistics. | 809 | * that matches our search string. Now get the statistics. |
@@ -820,6 +837,13 @@ regex_found_handler (void *cls, | |||
820 | 837 | ||
821 | peers_found++; | 838 | peers_found++; |
822 | 839 | ||
840 | if (GNUNET_SCHEDULER_NO_TASK != peer->timeout) | ||
841 | { | ||
842 | GNUNET_SCHEDULER_cancel (peer->timeout); | ||
843 | peer->timeout = GNUNET_SCHEDULER_NO_TASK; | ||
844 | GNUNET_SCHEDULER_add_now (&find_next_string, NULL); | ||
845 | } | ||
846 | |||
823 | if (NULL == id) | 847 | if (NULL == id) |
824 | { | 848 | { |
825 | // FIXME not possible right now | 849 | // FIXME not possible right now |
@@ -926,63 +950,72 @@ static void | |||
926 | do_connect_by_string (void *cls, | 950 | do_connect_by_string (void *cls, |
927 | const struct GNUNET_SCHEDULER_TaskContext * tc) | 951 | const struct GNUNET_SCHEDULER_TaskContext * tc) |
928 | { | 952 | { |
953 | unsigned int i; | ||
954 | |||
929 | printf ("Starting string search.\n"); | 955 | printf ("Starting string search.\n"); |
930 | fflush (stdout); | 956 | fflush (stdout); |
931 | 957 | ||
932 | peers[0].search_str = search_strings[0]; | 958 | search_timeout_task = GNUNET_SCHEDULER_add_delayed (search_timeout, |
933 | peers[0].search_str_matched = GNUNET_NO; | 959 | &do_connect_by_string_timeout, NULL); |
960 | for (i = 0; i < SEARCHES_IN_PARALLEL; i++) | ||
961 | GNUNET_SCHEDULER_add_now (&find_next_string, NULL); | ||
962 | } | ||
934 | 963 | ||
935 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
936 | "Searching for string \"%s\" on peer %d with file %s\n", | ||
937 | peers[0].search_str, 0, peers[0].policy_file); | ||
938 | 964 | ||
939 | /* First connect to mesh service, then search for string. Next | 965 | /** |
940 | connect will be in mesh_connect_cb */ | 966 | * Search timed out. It might still complete in the future, |
941 | peers[0].op_handle = | 967 | * but we should start another one. |
942 | GNUNET_TESTBED_service_connect (NULL, | 968 | * |
943 | peers[0].peer_handle, | 969 | * @param cls Index of the next peer in the peers array. |
944 | "dht", | 970 | * @param tc TaskContext. |
945 | &dht_connect_cb, | 971 | */ |
946 | &peers[0], | 972 | static void |
947 | &dht_ca, | 973 | find_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
948 | &dht_da, | 974 | { |
949 | &peers[0]); | 975 | struct RegexPeer *p = cls; |
950 | 976 | ||
951 | search_timeout_task = GNUNET_SCHEDULER_add_delayed (search_timeout, | 977 | p->timeout = GNUNET_SCHEDULER_NO_TASK; |
952 | &do_connect_by_string_timeout, NULL); | 978 | |
979 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | ||
980 | return; | ||
981 | GNUNET_SCHEDULER_add_now (&find_next_string, NULL); | ||
953 | } | 982 | } |
954 | 983 | ||
984 | |||
955 | /** | 985 | /** |
956 | * Start searching for the next string in the DHT. | 986 | * Start searching for the next string in the DHT. |
957 | * | 987 | * |
958 | * @param cls Index of the next peer in the peers array. | 988 | * @param cls Index of the next peer in the peers array. |
959 | * @param tc TaskContext. | 989 | * @param tc TaskContext. |
960 | */ | 990 | */ |
961 | void | 991 | static void |
962 | find_next_string (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 992 | find_next_string (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
963 | { | 993 | { |
964 | long next_p = (long) cls; | 994 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) || |
965 | 995 | peer_cnt >= (num_search_strings - 1)) | |
966 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
967 | return; | 996 | return; |
968 | 997 | ||
998 | peers[peer_cnt].search_str = search_strings[peer_cnt]; | ||
999 | peers[peer_cnt].search_str_matched = GNUNET_NO; | ||
969 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1000 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
970 | "Searching for string \"%s\" on peer %d with file %s\n", | 1001 | "Searching for string \"%s\" on peer %d with file %s\n", |
971 | peers[next_p].search_str, next_p, peers[next_p].policy_file); | 1002 | peers[peer_cnt].search_str, |
1003 | peer_cnt, | ||
1004 | peers[peer_cnt].policy_file); | ||
972 | 1005 | ||
973 | /* FIXME | 1006 | peers[peer_cnt].op_handle = |
974 | * dont connect to a new dht for each peer, we might want to seach for n | ||
975 | * strings on m peers where n > m | ||
976 | */ | ||
977 | peers[next_p].op_handle = | ||
978 | GNUNET_TESTBED_service_connect (NULL, | 1007 | GNUNET_TESTBED_service_connect (NULL, |
979 | peers[next_p].peer_handle, | 1008 | peers[peer_cnt].peer_handle, |
980 | "dht", | 1009 | "dht", |
981 | &dht_connect_cb, | 1010 | &dht_connect_cb, |
982 | &peers[next_p], | 1011 | &peers[peer_cnt], |
983 | &dht_ca, | 1012 | &dht_ca, |
984 | &dht_da, | 1013 | &dht_da, |
985 | &peers[next_p]); | 1014 | &peers[peer_cnt]); |
1015 | peers[peer_cnt].timeout = GNUNET_SCHEDULER_add_delayed (FIND_TIMEOUT, | ||
1016 | &find_timeout, | ||
1017 | &peers[peer_cnt]); | ||
1018 | peer_cnt++; | ||
986 | } | 1019 | } |
987 | 1020 | ||
988 | 1021 | ||
@@ -1212,7 +1245,6 @@ announce_next_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1212 | &peers[next_p]); | 1245 | &peers[next_p]); |
1213 | } | 1246 | } |
1214 | 1247 | ||
1215 | |||
1216 | /** | 1248 | /** |
1217 | * DHT connect callback. Called when we are connected to the dht service for | 1249 | * DHT connect callback. Called when we are connected to the dht service for |
1218 | * the peer in 'cls'. If successfull we connect to the stats service of this | 1250 | * the peer in 'cls'. If successfull we connect to the stats service of this |
@@ -1228,8 +1260,6 @@ dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
1228 | void *ca_result, const char *emsg) | 1260 | void *ca_result, const char *emsg) |
1229 | { | 1261 | { |
1230 | struct RegexPeer *peer = (struct RegexPeer *) cls; | 1262 | struct RegexPeer *peer = (struct RegexPeer *) cls; |
1231 | static unsigned int peer_cnt; | ||
1232 | unsigned int next_p; | ||
1233 | 1263 | ||
1234 | if (NULL != emsg || NULL == op || NULL == ca_result) | 1264 | if (NULL != emsg || NULL == op || NULL == ca_result) |
1235 | { | 1265 | { |
@@ -1247,23 +1277,6 @@ dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
1247 | ®ex_found_handler, peer, | 1277 | ®ex_found_handler, peer, |
1248 | NULL); | 1278 | NULL); |
1249 | peer->prof_start_time = GNUNET_TIME_absolute_get (); | 1279 | peer->prof_start_time = GNUNET_TIME_absolute_get (); |
1250 | |||
1251 | if (peer_cnt < (num_search_strings - 1)) | ||
1252 | { | ||
1253 | if (GNUNET_YES == no_distributed_search) | ||
1254 | next_p = 0; | ||
1255 | else | ||
1256 | next_p = (++peer_cnt % num_peers); | ||
1257 | |||
1258 | peers[next_p].search_str = search_strings[next_p]; | ||
1259 | peers[next_p].search_str_matched = GNUNET_NO; | ||
1260 | |||
1261 | /* Don't start all searches at once */ | ||
1262 | /* TODO add some intelligence to the timeout */ | ||
1263 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
1264 | &find_next_string, | ||
1265 | (void *) (long) next_p); | ||
1266 | } | ||
1267 | } | 1280 | } |
1268 | 1281 | ||
1269 | 1282 | ||
@@ -2102,9 +2115,6 @@ main (int argc, char *const *argv) | |||
2102 | {'p', "max-path-compression", "MAX_PATH_COMPRESSION", | 2115 | {'p', "max-path-compression", "MAX_PATH_COMPRESSION", |
2103 | gettext_noop ("maximum path compression length"), | 2116 | gettext_noop ("maximum path compression length"), |
2104 | 1, &GNUNET_GETOPT_set_uint, &max_path_compression}, | 2117 | 1, &GNUNET_GETOPT_set_uint, &max_path_compression}, |
2105 | {'i', "no-distributed-search", "", | ||
2106 | gettext_noop ("if this option is set, only one peer is responsible for searching all strings"), | ||
2107 | 0, &GNUNET_GETOPT_set_one, &no_distributed_search}, | ||
2108 | GNUNET_GETOPT_OPTION_END | 2118 | GNUNET_GETOPT_OPTION_END |
2109 | }; | 2119 | }; |
2110 | int ret; | 2120 | int ret; |