Add member_order (fifo/lifo) + demand-history cull#110
Open
seriyps wants to merge 1 commit into
Open
Conversation
Introduces two related changes:
1. `member_order => fifo | lifo` pool config option (default `lifo`,
preserving existing stack behaviour). `fifo` uses an OTP `queue()`
as the free-member structure, producing round-robin dispatch where
the longest-idle worker is always handed out next. The free-member
abstraction (`free_push/pop/delete/fold/take_n/convert`) hides the
list-vs-queue difference from all call sites; `free_count` is now
exclusively managed by these helpers.
2. Pool-level demand-history cull replaces the per-worker `max_age`
idle-time check. A fixed-capacity OTP-queue ring buffer (head =
current bucket, capacity = ceil(max_age/bucket_size)) tracks peak
concurrent in-use count; at each cull tick the pool sizes to that
peak (floored at `init_count`). This gives LIFO and FIFO pools
identical shrinkage behaviour for the same config, and correctly
handles FIFO rotation where workers never accumulate idle time.
`max_age` now means "demand memory window"; `cull_interval` default
changed from {1,min} to {15,sec} so defaults satisfy CI <= MA.
Hot-upgrade (vsn 5->6) reconstructs the demand buffer from member
`time` timestamps.
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
member_order => lifo | fifopool config (lifois the default and preservesall existing behaviour).
fifouses an OTP queue as the free-member structure,handing out the longest-idle worker first (round-robin rotation).
Replace the per-worker
max_ageidle-time cull gate with pool-level demandhistory: a fixed-capacity queue ring buffer (head = current bucket) tracks peak
concurrent in-use count over a rolling
max_agewindow. At each cull tick the poolsizes to that peak (floored at
init_count). This gives LIFO and FIFO identicalshrinkage behaviour for the same config — FIFO workers never go idle under rotation,
so the old per-worker check never fired for them.
max_agenow means "demand memory window" rather than "individual worker idle time".Practical behaviour for LIFO pools is essentially unchanged; FIFO pools now cull
correctly.
cull_intervaldefault changed from{1, min}to{15, sec}so thedefaults satisfy
cull_interval ≤ max_age.Fixed-size pools (
init_count == max_count) skip demand tracking entirely(
demand_buf = undefined) — cull never fires for them anyway.Hot upgrade v5 → v6:
demand_bufis reconstructed from membertimetimestamps.Benchmark (OTP 27.3, vs master baseline)
LIFO path overhead is within noise (0–5%) for all existing benchmarks; the cull-heavy
benchmark improves by ~8%. FIFO adds ~10–15% vs LIFO for single take/return
(queue vs list-head), negligible for drain-all and concurrent patterns.