]> git.ipfire.org Git - thirdparty/rspamd.git/commit
[Feature] proxy: implement token bucket load balancing for upstreams
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 3 Feb 2026 11:42:27 +0000 (11:42 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 3 Feb 2026 11:42:27 +0000 (11:42 +0000)
commite0b89eb6a258342d49c73b8fe0f1c8174b5c1322
treeebebefd04cfdf7f7ad4dcab9c12bccb37398f194
parent56e4bc3764e2deb80c5a4578a66dec48b15a90a2
[Feature] proxy: implement token bucket load balancing for upstreams

Add weighted load balancing algorithm that considers message size and
current backend load when selecting upstreams. Each upstream has a token
pool that gets depleted proportionally to message size and replenished
when requests complete successfully.

- Add RSPAMD_UPSTREAM_TOKEN_BUCKET rotation type
- Implement min-heap based selection for O(log n) upstream selection
- Reserve tokens proportional to message size (base_cost + size/scale)
- Return tokens on success (restores available) or failure (lost)
- Fall back to least-loaded upstream when all are token-exhausted
- Add UCL configuration: token_bucket { max_tokens, scale, min_tokens, base_cost }
src/libutil/upstream.c
src/libutil/upstream.h
src/rspamd_proxy.c