From 60231536315517b4133cbe80d430b8133dd42c55 Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Mon, 10 Apr 2023 15:27:33 -0700 Subject: hs_pow: modified approach to pqueue level thresholds This centralizes the logic for deciding on these magic thresholds, and tries to reduce them to just two: a min and max. The min should be a "nearly empty" threshold, indicating that the queue only contains work we expect to be able to complete very soon. The max level triggers a bulk culling process that reduces the queue to half that amount. This patch calculates both thresholds based on the torrc pqueue rate settings if they're present, and uses generic defaults if the user asked for an unlimited dequeue rate in torrc. Signed-off-by: Micah Elizabeth Scott --- src/feature/hs/hs_service.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (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 43598ad768..b2af881597 100644 --- a/src/feature/hs/hs_service.c +++ b/src/feature/hs/hs_service.c @@ -278,6 +278,12 @@ initialize_pow_defenses(hs_service_t *service) pow_state->rend_request_pqueue = smartlist_new(); pow_state->pop_pqueue_ev = NULL; + /* If we are using the pqueue rate limiter, calculate min and max queue + * levels based on those programmed rates. If not, we have generic + * defaults */ + pow_state->pqueue_low_level = 16; + pow_state->pqueue_high_level = 16384; + if (service->config.pow_queue_rate > 0 && service->config.pow_queue_burst >= service->config.pow_queue_rate) { pow_state->using_pqueue_bucket = 1; @@ -285,6 +291,11 @@ initialize_pow_defenses(hs_service_t *service) service->config.pow_queue_rate, service->config.pow_queue_burst, (uint32_t) approx_time()); + + pow_state->pqueue_low_level = MAX(8, service->config.pow_queue_rate / 4); + pow_state->pqueue_high_level = + service->config.pow_queue_burst + + service->config.pow_queue_rate * MAX_REND_TIMEOUT * 2; } /* We recalculate and update the suggested effort every HS_UPDATE_PERIOD @@ -2701,7 +2712,8 @@ update_suggested_effort(hs_service_t *service, time_t now) /* Increase when the top of queue is high-effort */ aimd_event = INCREASE; } - } else if (smartlist_len(pow_state->rend_request_pqueue) == 0) { + } else if (smartlist_len(pow_state->rend_request_pqueue) < + pow_state->pqueue_low_level) { /* Dec when the queue is empty now and had_queue wasn't set this period */ aimd_event = DECREASE; } -- cgit v1.2.3-54-g00ecf