diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-04-30 17:20:14 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-04-30 17:20:14 +0200 |
commit | 0b72bb0cfe89fa5c16afdf9824ff162a9ff19168 (patch) | |
tree | 9f3bc0d5b4eef3b28ee84ef55eff63b081a13c44 /src/zonemaster/gnunet-service-zonemaster.c | |
parent | 4b5c6cceb0284774a161d426b606f40644abfb4c (diff) | |
download | gnunet-0b72bb0cfe89fa5c16afdf9824ff162a9ff19168.tar.gz gnunet-0b72bb0cfe89fa5c16afdf9824ff162a9ff19168.zip |
simplify velocity logic in zonemaster
Diffstat (limited to 'src/zonemaster/gnunet-service-zonemaster.c')
-rw-r--r-- | src/zonemaster/gnunet-service-zonemaster.c | 135 |
1 files changed, 77 insertions, 58 deletions
diff --git a/src/zonemaster/gnunet-service-zonemaster.c b/src/zonemaster/gnunet-service-zonemaster.c index f67fa6495..c4d9bcc17 100644 --- a/src/zonemaster/gnunet-service-zonemaster.c +++ b/src/zonemaster/gnunet-service-zonemaster.c | |||
@@ -37,11 +37,17 @@ | |||
37 | 37 | ||
38 | 38 | ||
39 | /** | 39 | /** |
40 | * How often should we (re)publish each record before | ||
41 | * it expires? | ||
42 | */ | ||
43 | #define PUBLISH_OPS_PER_EXPIRATION 4 | ||
44 | |||
45 | /** | ||
40 | * How often do we measure the delta between desired zone | 46 | * How often do we measure the delta between desired zone |
41 | * iteration speed and actual speed, and tell statistics | 47 | * iteration speed and actual speed, and tell statistics |
42 | * service about it? | 48 | * service about it? |
43 | */ | 49 | */ |
44 | #define DELTA_INTERVAL 1000 | 50 | #define DELTA_INTERVAL 100 |
45 | 51 | ||
46 | /** | 52 | /** |
47 | * How many records do we fetch in one shot from the namestore? | 53 | * How many records do we fetch in one shot from the namestore? |
@@ -60,12 +66,8 @@ | |||
60 | #define INITIAL_PUT_INTERVAL GNUNET_TIME_UNIT_MILLISECONDS | 66 | #define INITIAL_PUT_INTERVAL GNUNET_TIME_UNIT_MILLISECONDS |
61 | 67 | ||
62 | /** | 68 | /** |
63 | * The lower bound for the zone iteration interval | ||
64 | */ | ||
65 | #define MINIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_UNIT_SECONDS | ||
66 | |||
67 | /** | ||
68 | * The upper bound for the zone iteration interval | 69 | * The upper bound for the zone iteration interval |
70 | * (per record). | ||
69 | */ | 71 | */ |
70 | #define MAXIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) | 72 | #define MAXIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
71 | 73 | ||
@@ -206,9 +208,10 @@ static struct GNUNET_TIME_Relative next_put_interval; | |||
206 | static struct GNUNET_TIME_Relative min_relative_record_time; | 208 | static struct GNUNET_TIME_Relative min_relative_record_time; |
207 | 209 | ||
208 | /** | 210 | /** |
209 | * Zone iteration PUT interval. | 211 | * Minimum relative expiration time of records seem during the last |
212 | * zone iteration. | ||
210 | */ | 213 | */ |
211 | static struct GNUNET_TIME_Relative put_interval; | 214 | static struct GNUNET_TIME_Relative last_min_relative_record_time; |
212 | 215 | ||
213 | /** | 216 | /** |
214 | * Default time window for zone iteration | 217 | * Default time window for zone iteration |
@@ -269,6 +272,7 @@ shutdown_task (void *cls) | |||
269 | { | 272 | { |
270 | struct DhtPutActivity *ma; | 273 | struct DhtPutActivity *ma; |
271 | 274 | ||
275 | (void) cls; | ||
272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 276 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
273 | "Shutting down!\n"); | 277 | "Shutting down!\n"); |
274 | while (NULL != (ma = ma_head)) | 278 | while (NULL != (ma = ma_head)) |
@@ -330,11 +334,12 @@ shutdown_task (void *cls) | |||
330 | /** | 334 | /** |
331 | * Method called periodically that triggers iteration over authoritative records | 335 | * Method called periodically that triggers iteration over authoritative records |
332 | * | 336 | * |
333 | * @param cls closure | 337 | * @param cls NULL |
334 | */ | 338 | */ |
335 | static void | 339 | static void |
336 | publish_zone_namestore_next (void *cls) | 340 | publish_zone_namestore_next (void *cls) |
337 | { | 341 | { |
342 | (void) cls; | ||
338 | zone_publish_task = NULL; | 343 | zone_publish_task = NULL; |
339 | GNUNET_assert (NULL != namestore_iter); | 344 | GNUNET_assert (NULL != namestore_iter); |
340 | GNUNET_assert (0 == ns_iteration_left); | 345 | GNUNET_assert (0 == ns_iteration_left); |
@@ -401,6 +406,50 @@ check_zone_namestore_next () | |||
401 | 406 | ||
402 | 407 | ||
403 | /** | 408 | /** |
409 | * Calculate #next_put_interval. | ||
410 | */ | ||
411 | static void | ||
412 | calculate_put_interval () | ||
413 | { | ||
414 | if (0 == num_public_records) | ||
415 | { | ||
416 | /** | ||
417 | * If no records are known (startup) or none present | ||
418 | * we can safely set the interval to the value for a single | ||
419 | * record | ||
420 | */ | ||
421 | next_put_interval = zone_publish_time_window; | ||
422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | ||
423 | "No records in namestore database.\n"); | ||
424 | } | ||
425 | else | ||
426 | { | ||
427 | last_min_relative_record_time | ||
428 | = GNUNET_TIME_relative_min (last_min_relative_record_time, | ||
429 | min_relative_record_time); | ||
430 | zone_publish_time_window | ||
431 | = GNUNET_TIME_relative_min (GNUNET_TIME_relative_divide (last_min_relative_record_time, | ||
432 | PUBLISH_OPS_PER_EXPIRATION), | ||
433 | zone_publish_time_window_default); | ||
434 | next_put_interval | ||
435 | = GNUNET_TIME_relative_divide (zone_publish_time_window, | ||
436 | last_num_public_records); | ||
437 | next_put_interval | ||
438 | = GNUNET_TIME_relative_min (next_put_interval, | ||
439 | MAXIMUM_ZONE_ITERATION_INTERVAL); | ||
440 | } | ||
441 | GNUNET_STATISTICS_set (statistics, | ||
442 | "Minimum relative record expiration (in ms)", | ||
443 | last_min_relative_record_time.rel_value_us / 1000LL, | ||
444 | GNUNET_NO); | ||
445 | GNUNET_STATISTICS_set (statistics, | ||
446 | "Zone publication time window (in ms)", | ||
447 | zone_publish_time_window.rel_value_us / 1000LL, | ||
448 | GNUNET_NO); | ||
449 | } | ||
450 | |||
451 | |||
452 | /** | ||
404 | * Re-calculate our velocity and the desired velocity. | 453 | * Re-calculate our velocity and the desired velocity. |
405 | * We have succeeded in making #DELTA_INTERVAL puts, so | 454 | * We have succeeded in making #DELTA_INTERVAL puts, so |
406 | * now calculate the new desired delay between puts. | 455 | * now calculate the new desired delay between puts. |
@@ -422,18 +471,9 @@ update_velocity () | |||
422 | { | 471 | { |
423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 472 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
424 | "Last record count was lower than current record count. Reducing interval.\n"); | 473 | "Last record count was lower than current record count. Reducing interval.\n"); |
425 | put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window, | 474 | last_num_public_records = num_public_records * LATE_ITERATION_SPEEDUP_FACTOR; |
426 | num_public_records); | 475 | calculate_put_interval (); |
427 | next_put_interval = GNUNET_TIME_relative_divide (put_interval, | ||
428 | LATE_ITERATION_SPEEDUP_FACTOR); | ||
429 | } | 476 | } |
430 | else | ||
431 | { | ||
432 | next_put_interval = put_interval; | ||
433 | } | ||
434 | |||
435 | next_put_interval = GNUNET_TIME_relative_min (next_put_interval, | ||
436 | MAXIMUM_ZONE_ITERATION_INTERVAL); | ||
437 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 477 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
438 | "Desired global zone iteration interval is %s/record!\n", | 478 | "Desired global zone iteration interval is %s/record!\n", |
439 | GNUNET_STRINGS_relative_time_to_string (next_put_interval, | 479 | GNUNET_STRINGS_relative_time_to_string (next_put_interval, |
@@ -691,53 +731,27 @@ zone_iteration_finished (void *cls) | |||
691 | namestore_iter = NULL; | 731 | namestore_iter = NULL; |
692 | last_num_public_records = num_public_records; | 732 | last_num_public_records = num_public_records; |
693 | first_zone_iteration = GNUNET_NO; | 733 | first_zone_iteration = GNUNET_NO; |
694 | if (0 == num_public_records) | 734 | last_min_relative_record_time = min_relative_record_time; |
695 | { | 735 | calculate_put_interval (); |
696 | /** | ||
697 | * If no records are known (startup) or none present | ||
698 | * we can safely set the interval to the value for a single | ||
699 | * record | ||
700 | */ | ||
701 | put_interval = zone_publish_time_window; | ||
702 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | ||
703 | "No records in namestore database.\n"); | ||
704 | } | ||
705 | else | ||
706 | { | ||
707 | /* If records are present, next publication is based on the minimum | ||
708 | * relative expiration time of the records published divided by 4 | ||
709 | */ | ||
710 | zone_publish_time_window | ||
711 | = GNUNET_TIME_relative_min (GNUNET_TIME_relative_divide (min_relative_record_time, 4), | ||
712 | zone_publish_time_window_default); | ||
713 | put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window, | ||
714 | num_public_records); | ||
715 | } | ||
716 | /* reset for next iteration */ | 736 | /* reset for next iteration */ |
717 | min_relative_record_time = GNUNET_TIME_UNIT_FOREVER_REL; | 737 | min_relative_record_time |
718 | put_interval = GNUNET_TIME_relative_max (MINIMUM_ZONE_ITERATION_INTERVAL, | 738 | = GNUNET_TIME_relative_multiply (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY, |
719 | put_interval); | 739 | PUBLISH_OPS_PER_EXPIRATION); |
720 | put_interval = GNUNET_TIME_relative_min (put_interval, | ||
721 | MAXIMUM_ZONE_ITERATION_INTERVAL); | ||
722 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 740 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
723 | "Zone iteration finished. Adjusted zone iteration interval to %s\n", | 741 | "Zone iteration finished. Adjusted zone iteration interval to %s\n", |
724 | GNUNET_STRINGS_relative_time_to_string (put_interval, | 742 | GNUNET_STRINGS_relative_time_to_string (next_put_interval, |
725 | GNUNET_YES)); | 743 | GNUNET_YES)); |
726 | GNUNET_STATISTICS_set (statistics, | 744 | GNUNET_STATISTICS_set (statistics, |
727 | "Current zone iteration interval (in ms)", | 745 | "Current zone iteration interval (in ms)", |
728 | put_interval.rel_value_us / 1000LL, | 746 | next_put_interval.rel_value_us / 1000LL, |
729 | GNUNET_NO); | 747 | GNUNET_NO); |
730 | GNUNET_STATISTICS_update (statistics, | ||
731 | "Number of zone iterations", | ||
732 | 1, | ||
733 | GNUNET_NO); | ||
734 | GNUNET_STATISTICS_set (statistics, | 748 | GNUNET_STATISTICS_set (statistics, |
735 | "Number of public records in DHT", | 749 | "Number of public records in DHT", |
736 | last_num_public_records, | 750 | last_num_public_records, |
737 | GNUNET_NO); | 751 | GNUNET_NO); |
738 | GNUNET_assert (NULL == zone_publish_task); | 752 | GNUNET_assert (NULL == zone_publish_task); |
739 | if (0 == num_public_records) | 753 | if (0 == last_num_public_records) |
740 | zone_publish_task = GNUNET_SCHEDULER_add_delayed (put_interval, | 754 | zone_publish_task = GNUNET_SCHEDULER_add_delayed (next_put_interval, |
741 | &publish_zone_dht_start, | 755 | &publish_zone_dht_start, |
742 | NULL); | 756 | NULL); |
743 | else | 757 | else |
@@ -875,6 +889,7 @@ handle_monitor_event (void *cls, | |||
875 | unsigned int rd_public_count; | 889 | unsigned int rd_public_count; |
876 | struct DhtPutActivity *ma; | 890 | struct DhtPutActivity *ma; |
877 | 891 | ||
892 | (void) cls; | ||
878 | GNUNET_STATISTICS_update (statistics, | 893 | GNUNET_STATISTICS_update (statistics, |
879 | "Namestore monitor events received", | 894 | "Namestore monitor events received", |
880 | 1, | 895 | 1, |
@@ -976,8 +991,12 @@ run (void *cls, | |||
976 | unsigned long long max_parallel_bg_queries = 128; | 991 | unsigned long long max_parallel_bg_queries = 128; |
977 | 992 | ||
978 | (void) cls; | 993 | (void) cls; |
994 | (void) service; | ||
979 | last_put_100 = GNUNET_TIME_absolute_get (); /* first time! */ | 995 | last_put_100 = GNUNET_TIME_absolute_get (); /* first time! */ |
980 | min_relative_record_time = GNUNET_TIME_UNIT_FOREVER_REL; | 996 | min_relative_record_time |
997 | = GNUNET_TIME_relative_multiply (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY, | ||
998 | PUBLISH_OPS_PER_EXPIRATION); | ||
999 | next_put_interval = INITIAL_PUT_INTERVAL; | ||
981 | namestore_handle = GNUNET_NAMESTORE_connect (c); | 1000 | namestore_handle = GNUNET_NAMESTORE_connect (c); |
982 | if (NULL == namestore_handle) | 1001 | if (NULL == namestore_handle) |
983 | { | 1002 | { |
@@ -989,7 +1008,6 @@ run (void *cls, | |||
989 | cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c, | 1008 | cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c, |
990 | "namestore", | 1009 | "namestore", |
991 | "CACHE_KEYS"); | 1010 | "CACHE_KEYS"); |
992 | put_interval = INITIAL_PUT_INTERVAL; | ||
993 | zone_publish_time_window_default = DEFAULT_ZONE_PUBLISH_TIME_WINDOW; | 1011 | zone_publish_time_window_default = DEFAULT_ZONE_PUBLISH_TIME_WINDOW; |
994 | if (GNUNET_OK == | 1012 | if (GNUNET_OK == |
995 | GNUNET_CONFIGURATION_get_value_time (c, | 1013 | GNUNET_CONFIGURATION_get_value_time (c, |
@@ -1039,7 +1057,8 @@ run (void *cls, | |||
1039 | &monitor_sync_event, | 1057 | &monitor_sync_event, |
1040 | NULL); | 1058 | NULL); |
1041 | GNUNET_break (NULL != zmon); | 1059 | GNUNET_break (NULL != zmon); |
1042 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 1060 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
1061 | NULL); | ||
1043 | } | 1062 | } |
1044 | 1063 | ||
1045 | 1064 | ||