diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-04-29 10:56:15 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-04-29 10:56:15 +0200 |
commit | ce2864cfaa27e55096b480bf35db5f8cee2a5e7e (patch) | |
tree | be47c017d1467870000aa1a507eab3c995304179 /src/zonemaster | |
parent | 823215c974ccb1ef3cad9eb1082999cd1b910416 (diff) | |
download | gnunet-ce2864cfaa27e55096b480bf35db5f8cee2a5e7e.tar.gz gnunet-ce2864cfaa27e55096b480bf35db5f8cee2a5e7e.zip |
add option to disable namecache, add velocity calculation and delay correction to zonemaster, fix some ftbfs from recent NAMESTORE API change
Diffstat (limited to 'src/zonemaster')
-rw-r--r-- | src/zonemaster/gnunet-service-zonemaster.c | 95 |
1 files changed, 89 insertions, 6 deletions
diff --git a/src/zonemaster/gnunet-service-zonemaster.c b/src/zonemaster/gnunet-service-zonemaster.c index 518d5f572..25baf4396 100644 --- a/src/zonemaster/gnunet-service-zonemaster.c +++ b/src/zonemaster/gnunet-service-zonemaster.c | |||
@@ -272,6 +272,14 @@ publish_zone_dht_start (void *cls); | |||
272 | 272 | ||
273 | 273 | ||
274 | /** | 274 | /** |
275 | * How often do we measure the delta between desired zone | ||
276 | * iteration speed and actual speed, and tell statistics | ||
277 | * service about it? | ||
278 | */ | ||
279 | #define DELTA_INTERVAL 100 | ||
280 | |||
281 | |||
282 | /** | ||
275 | * Continuation called from DHT once the PUT operation is done. | 283 | * Continuation called from DHT once the PUT operation is done. |
276 | * | 284 | * |
277 | * @param cls closure, NULL if called from regular iteration, | 285 | * @param cls closure, NULL if called from regular iteration, |
@@ -283,7 +291,11 @@ dht_put_continuation (void *cls, | |||
283 | int success) | 291 | int success) |
284 | { | 292 | { |
285 | struct MonitorActivity *ma = cls; | 293 | struct MonitorActivity *ma = cls; |
294 | static unsigned long long put_cnt; | ||
295 | static struct GNUNET_TIME_Absolute last_put_100; | ||
296 | static struct GNUNET_TIME_Relative sub_delta; | ||
286 | struct GNUNET_TIME_Relative next_put_interval; | 297 | struct GNUNET_TIME_Relative next_put_interval; |
298 | struct GNUNET_TIME_Relative delay; | ||
287 | 299 | ||
288 | num_public_records++; | 300 | num_public_records++; |
289 | if (NULL == ma) | 301 | if (NULL == ma) |
@@ -300,20 +312,91 @@ dht_put_continuation (void *cls, | |||
300 | LATE_ITERATION_SPEEDUP_FACTOR); | 312 | LATE_ITERATION_SPEEDUP_FACTOR); |
301 | } | 313 | } |
302 | else | 314 | else |
315 | { | ||
303 | next_put_interval = put_interval; | 316 | next_put_interval = put_interval; |
317 | } | ||
304 | next_put_interval = GNUNET_TIME_relative_min (next_put_interval, | 318 | next_put_interval = GNUNET_TIME_relative_min (next_put_interval, |
305 | MAXIMUM_ZONE_ITERATION_INTERVAL); | 319 | MAXIMUM_ZONE_ITERATION_INTERVAL); |
306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 320 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
307 | "PUT complete, next PUT in %s!\n", | 321 | "PUT complete, next PUT in %s!\n", |
308 | GNUNET_STRINGS_relative_time_to_string (next_put_interval, | 322 | GNUNET_STRINGS_relative_time_to_string (next_put_interval, |
309 | GNUNET_YES)); | 323 | GNUNET_YES)); |
310 | 324 | /* compute velocities and delay corrections to apply */ | |
311 | GNUNET_STATISTICS_set (statistics, | 325 | if (0 == put_cnt) |
312 | "Current zone iteration interval (ms)", | 326 | last_put_100 = GNUNET_TIME_absolute_get (); /* first time! */ |
313 | next_put_interval.rel_value_us / 1000LL, | 327 | put_cnt++; |
314 | GNUNET_NO); | 328 | if (0 == put_cnt % DELTA_INTERVAL) |
329 | { | ||
330 | struct GNUNET_TIME_Relative delta; | ||
331 | unsigned long long pct = 0; | ||
332 | |||
333 | /* How fast were we really? */ | ||
334 | delta = GNUNET_TIME_absolute_get_duration (last_put_100); | ||
335 | delta.rel_value_us /= DELTA_INTERVAL; | ||
336 | last_put_100 = GNUNET_TIME_absolute_get (); | ||
337 | /* Tell statistics actual vs. desired speed */ | ||
338 | GNUNET_STATISTICS_set (statistics, | ||
339 | "Target zone iteration velocity (μs)", | ||
340 | next_put_interval.rel_value_us, | ||
341 | GNUNET_NO); | ||
342 | GNUNET_STATISTICS_set (statistics, | ||
343 | "Current zone iteration velocity (μs)", | ||
344 | delta.rel_value_us, | ||
345 | GNUNET_NO); | ||
346 | /* update "sub_delta" based on difference, taking | ||
347 | previous sub_delta into account! */ | ||
348 | if (next_put_interval.rel_value_us > delta.rel_value_us) | ||
349 | { | ||
350 | /* We were too fast, reduce sub_delta! */ | ||
351 | struct GNUNET_TIME_Relative corr; | ||
352 | |||
353 | corr = GNUNET_TIME_relative_subtract (next_put_interval, | ||
354 | delta); | ||
355 | if (sub_delta.rel_value_us > delta.rel_value_us) | ||
356 | { | ||
357 | /* Reduce sub_delta by corr */ | ||
358 | sub_delta = GNUNET_TIME_relative_subtract (sub_delta, | ||
359 | corr); | ||
360 | } | ||
361 | else | ||
362 | { | ||
363 | /* We're doing fine with waiting the full time, this | ||
364 | should theoretically only happen if we run at | ||
365 | infinite speed. */ | ||
366 | sub_delta = GNUNET_TIME_UNIT_ZERO; | ||
367 | } | ||
368 | } | ||
369 | else if (next_put_interval.rel_value_us < delta.rel_value_us) | ||
370 | { | ||
371 | /* We were too slow, increase sub_delta! */ | ||
372 | struct GNUNET_TIME_Relative corr; | ||
373 | |||
374 | corr = GNUNET_TIME_relative_subtract (delta, | ||
375 | next_put_interval); | ||
376 | sub_delta = GNUNET_TIME_relative_add (sub_delta, | ||
377 | corr); | ||
378 | if (sub_delta.rel_value_us > next_put_interval.rel_value_us) | ||
379 | { | ||
380 | /* CPU overload detected, we cannot go at desired speed, | ||
381 | as this would mean using a negative delay. */ | ||
382 | sub_delta = next_put_interval; | ||
383 | /* compute how much faster we would want to be for | ||
384 | the desired velocity */ | ||
385 | if (0 == next_put_interval.rel_value_us) | ||
386 | pct = UINT64_MAX; /* desired speed is infinity ... */ | ||
387 | else | ||
388 | pct = sub_delta.rel_value_us * 100 / next_put_interval.rel_value_us; | ||
389 | } | ||
390 | } | ||
391 | GNUNET_STATISTICS_set (statistics, | ||
392 | "% speed increase needed for target velocity", | ||
393 | pct, | ||
394 | GNUNET_NO); | ||
395 | } /* end of periodic velocity calculations */ | ||
396 | delay = GNUNET_TIME_relative_subtract (next_put_interval, | ||
397 | sub_delta); | ||
315 | GNUNET_assert (NULL == zone_publish_task); | 398 | GNUNET_assert (NULL == zone_publish_task); |
316 | zone_publish_task = GNUNET_SCHEDULER_add_delayed (next_put_interval, | 399 | zone_publish_task = GNUNET_SCHEDULER_add_delayed (delay, |
317 | &publish_zone_dht_next, | 400 | &publish_zone_dht_next, |
318 | NULL); | 401 | NULL); |
319 | } | 402 | } |