Use a more efficient strategy for waiting on processes
notgull opened this issue · comments
Right now, we use SIGPROC
to wait for process events on Unix and thread pooling to wait for process events on Windows. This is a very inefficient strategy that doesn't scale for many child processes, like using poll()
for I/O notification.
Most operating systems have better ways of handling events like this.
- Linux has
pidfd
, which can be registered directly intoasync-io
. - BSD has
EVFILT_PROC
, which is now exposed inasync-io
. - Windows has waitable handles, which need to be exposed in
async-io
. They can also be made more efficient on thepolling
side, see smol-rs/async-io#25
Will look into this
How this would probably be done:
- Split the signal-handling logic out of
Reaper
and move it to asignal.rs
file. - Create an alternative
pidfd.rs
file that implements theReaper
logic usingAsync<OwnedFd>
andpidfd_open
. Child::wait
should be implemented by callingreadable()
on the PIDFD to wait.- Zombie processes should be pushed into an executor that replaces the
reap()
function.
Sorry for the delay!
Will start working on this tomorrow
@mamaicode Great! Let me know if you need any guidance; I can hop in a Matrix/Discord call for pair programming if needed.
pidfd
has been implemented for Linux. However, we should also be able to implement this for Windows and BSD as well.