diff options
author | Micah Elizabeth Scott <beth@torproject.org> | 2023-04-10 15:27:33 -0700 |
---|---|---|
committer | Micah Elizabeth Scott <beth@torproject.org> | 2023-05-10 07:41:37 -0700 |
commit | 60231536315517b4133cbe80d430b8133dd42c55 (patch) | |
tree | 084ed16a68e3343455f0bee58126b3f3c0ad82c7 /src/feature/hs/hs_service.c | |
parent | 50313d114f12769579e7f26258e0956a5bbcaa00 (diff) | |
download | tor-60231536315517b4133cbe80d430b8133dd42c55.tar.gz tor-60231536315517b4133cbe80d430b8133dd42c55.zip |
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 <beth@torproject.org>
Diffstat (limited to 'src/feature/hs/hs_service.c')
-rw-r--r-- | src/feature/hs/hs_service.c | 14 |
1 files changed, 13 insertions, 1 deletions
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; } |