mirror of
https://github.com/mailscope/kumomta.git
synced 2026-08-20 11:28:17 +00:00
c13dde9ecb
I've been recently troubleshooting a couple of systems with high memory usage, and in one of them there were very large amounts of memory being allocated to ready queues. That could be partially mitigated by reducing `max_ready` to a more reasonable and small value, but it is difficult to compute the right balance between large-enough for high throughput and small-enough to keep memory usage reasonable. This commit switches away from crossbeam's ArrayQueue, which pre-allocates sufficient space to hold exactly `max_ready` messages for each instantiated ready queue, and to a newly introduced MessageList, which is an intrusive doubly-linked list. The intrusive list, in exchange for some small additional overhead per-Message, requires no auxilliary additional memory allocations to track the membership of that Message in some other list. That means that `max_ready` is no longer a pre-allocated minimum amount of additional storage, and changes the memory overhead from `O(number-of-queues * max_ready)` to `O(number-of-ready-messages)`, which is typically a lot smaller. This is independent of the individual messages metadata and bodies that are nominally associated with being in a ready queue.