Skip to content

Conversation

@hmmr
Copy link

@hmmr hmmr commented May 22, 2025

This PR provides functions to get and set the size of core node worker pools, intended to be used by callbacks (implemented in OpenRiak/kv_index_tictactree#4) of riak admin tictacaae commands. See this discussion and eventually OpenRiak/riak#13.

@martinsumner
Copy link
Contributor

I'm not clear that set_size will work. When the pool is initialised, it uses the size to pre-populate the queue with the right number of workers:

poolboy/src/poolboy.erl

Lines 132 to 139 in 8c28a49

init([], _WorkerArgs, #state{size=Size, supervisor=Sup, max_overflow=MaxOverflow}=State) ->
Workers = prepopulate(Size, Sup),
StartState = case Size of
Size when Size < 1, MaxOverflow < 1 -> full;
Size when Size < 1 -> overflow;
Size -> ready
end,
{ok, StartState, State#state{workers=Workers}}.

What will happen if we change the size (up or down) without changing the number of workers? Unless it is obvious, some sort of test is required.

@hmmr hmmr changed the title get/set_pool_size WIP get/set_pool_size Sep 7, 2025
@hmmr hmmr force-pushed the tiot/openriak-3.2/tictacaae-and-nextgenrepl-cli-commands branch from ffd51af to a2fe397 Compare September 9, 2025 22:17
This changeset introduces three new functions:

* `poolboy:set_pool_size/2,3` and `poolboy:get_pool_size/1`, which can
  be used to resize a running poolboy process dynamically;

* `poolboy:status_ext/1`, which in addition to the items returned by
  `status/1`, also reports the values of `size` and `latched_size`.

The new size is assigned to a new state record field,
`latched_size`. If it is greater than the current size, new checkouts
will succeed even in a `full` state, until the actual size,
incremented per checkout, grows and matches the latched_size.

If `latched_size` is smaller than current size, no immediate action is
taken on those currently checked-out workers which are now in excess
of the latched size. Instead, as they are checked in, they are
dismissed until the actual size decreases to match latched size.

The `set_pool_size/3` variant also allows to set the value of
max_overflow.

One limitation is that after setting a new size, the state of the
poolboy process (as returned by `poolboy:status` or `status_ext`), may
not reflect the actual state of the pooloy fsm wrt its ability to
accept new checkouts. This condition is temporary and the status will
resume normal reporting once `size` converges with `latched_size`.

This changeset is needed for
tiot/openriak-3.4/tictacaae-and-nextgenrepl-cli-commands branches in
riak_kv and riak_core.

pool dynamic resize for overflow = 0

pool dynamic resize for overflow > 0, too

wip towards more comprehensive tests

wip reasonably good

wip spurious

wip need to tweak asserts in test

wip finalizing

more extensive test, with fixes resulting therefrom

address possible case of pool stop returning too early before pool start
@hmmr hmmr force-pushed the tiot/openriak-3.2/tictacaae-and-nextgenrepl-cli-commands branch from e111539 to 7c28495 Compare September 22, 2025 22:22
@hmmr hmmr changed the title WIP get/set_pool_size get/set_pool_size Sep 22, 2025
@hmmr
Copy link
Author

hmmr commented Sep 22, 2025

Now this is done with proper amount of attention, and a more meaningful test. More details in the squashed commit description above.

@hmmr
Copy link
Author

hmmr commented Dec 4, 2025

No longer part of TicTacAAE set of PRs (OpenRiak/riak_kv#31, OpenRiak/riak#13) because the changes in this PR (required to enable the three poolsize-changing CLI commands) are touching parts that are too critical and best left alone, for the minor convenience of having an option to tweak worker poolsizes. So closing.

@hmmr hmmr closed this Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants