From ec9e95cf1ee9aff6f2607f0b45e1d6d1f7ba4513 Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Wed, 13 Jul 2022 23:33:07 +0000 Subject: Implement AIMD effort estimation. Now, pow should auto-enable and auto-disable itself. --- src/feature/hs/hs_service.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'src/feature/hs/hs_service.c') diff --git a/src/feature/hs/hs_service.c b/src/feature/hs/hs_service.c index 045022f182..4f8a689290 100644 --- a/src/feature/hs/hs_service.c +++ b/src/feature/hs/hs_service.c @@ -2678,21 +2678,42 @@ update_suggested_effort(hs_service_t *service, time_t now) /* Make life easier */ hs_pow_service_state_t *pow_state = service->state.pow_state; - /* Calculate the new suggested effort. */ - /* TODO Check for overflow? */ - pow_state->suggested_effort = (uint32_t)(pow_state->total_effort / pow_state->rend_handled); + /* Calculate the new suggested effort, using an additive-increase + * multiplicative-decrease estimation scheme. */ + if (pow_state->max_trimmed_effort > pow_state->suggested_effort) { + /* If we trimmed a request above our suggested effort, re-estimate the + * effort */ + pow_state->suggested_effort = (uint32_t)(pow_state->total_effort / + pow_state->rend_handled); + } else if (pow_state->had_queue) { + /* If we had a queue during this period, and the current top of queue + * is at or above the suggested effort, we should re-estimate the effort. + * Otherwise, it can stay the same (no change to effort). */ + if (top_of_rend_pqueue_is_worthwhile(pow_state)) { + pow_state->suggested_effort = (uint32_t)(pow_state->total_effort / + pow_state->rend_handled); + } + } else { + /* If we were able to keep the queue drained the entire update period, + * multiplicative decrease the pow by 2/3. */ + pow_state->suggested_effort = 2*pow_state->suggested_effort/3; + } log_debug(LD_REND, "Recalculated suggested effort: %u", pow_state->suggested_effort); - /* Set suggested effort to max(min_effort, suggested_effort) */ + /* If the suggested effort has been decreased below the minimum, set it + * to zero: no pow needed again until we queue or trim */ if (pow_state->suggested_effort < pow_state->min_effort) { - pow_state->suggested_effort = pow_state->min_effort; + // XXX: Verify this disables pow being done at all. + pow_state->suggested_effort = 0; } /* Reset the total effort sum and number of rends for this update period. */ pow_state->total_effort = 0; pow_state->rend_handled = 0; + pow_state->max_trimmed_effort = 0; + pow_state->had_queue = 0; pow_state->next_effort_update = now + HS_UPDATE_PERIOD; } -- cgit v1.2.3-54-g00ecf