Repository navigation
Conversation
…ocesses
salt.utils.process.SubprocessList.cleanup() was calling
``proc.join(0.01)`` unconditionally on every tracked entry, including
live processes. salt.minion wires cleanup_subprocesses() as a 200ms
PeriodicCallback (see ``add_periodic_callback("cleanup",
self.cleanup_subprocesses, interval=0.2)``), so with N live children
each cycle blocked the ioloop for up to N*10ms inside
``multiprocessing.Process.join -> _popen.wait -> wait([sentinel],
timeout) -> selectors.select``. Under resource-fanout load py-spy
caught the minion's main thread in exactly this stack repeatedly, and
the job-return drain rate was ~3 jobs/s. Skipping the join on live
children raised it to ~12.5 jobs/s on the same workload (4x).
Live processes don't need joining -- ``is_alive()`` is a non-blocking
``waitpid(WNOHANG)`` check. Skip live ones; only ``join()`` dead
ones, which returns instantly because the exit status is already
cached. Thread entries (``hasattr(proc, "exitcode") == False``) fall
through the same way because ``is_alive()`` on a dead thread also
returns False.
Regression guarded by two new functional tests in
tests/pytests/functional/utils/test_process.py:
- test_subprocess_list_cleanup_does_not_block_on_live_processes:
adds 50 live children to a SubprocessList and asserts cleanup()
returns in well under the old N*10ms = 500ms bound.
- test_subprocess_list_cleanup_reaps_dead_processes: guards that
the non-blocking fast path still reaps an already-exited child.
This branch was previously deployed
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.
Summary
salt.utils.process.SubprocessList.cleanup()was callingproc.join(0.01)unconditionally on every tracked entry, including live processes.salt.minionwirescleanup_subprocesses()as a 200msPeriodicCallback, so with N live children each cycle blocked the minion's ioloop for up to N*10ms insidemultiprocessing.Process.join -> _popen.wait -> selectors.select.join()on live children raised it to ~12.5 jobs/s on the same workload (4x improvement).is_alive()(non-blockingwaitpid(WNOHANG)) to decide whether to reap, and onlyjoin()s dead children (returns instantly, exit status is already cached). Thread entries fall through the same way becauseis_alive()on a dead thread also returns False.Test plan
test_subprocess_list_cleanup_does_not_block_on_live_processes: adds 50 live children to aSubprocessListand assertscleanup()returns well under the old N*10ms = 500ms bound.test_subprocess_list_cleanup_reaps_dead_processes: guards that the non-blocking fast path still reaps an already-exited child.test_subprocess_list_fdsstill passes.