Skip to content

Investigate AsyncStream alternative for output streaming #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
iCharlesHu opened this issue May 23, 2025 · 3 comments
Closed

Investigate AsyncStream alternative for output streaming #51

iCharlesHu opened this issue May 23, 2025 · 3 comments
Assignees

Comments

@iCharlesHu
Copy link
Contributor

Currently we rely on AsyncStream to bridge the "pull" based AsyncSequence consumer and "push" based DispatchIO (and soon epoll) producer. However, this could lead to the .unbounded buffer to grow infinitely if the consumer consumes slower than production. We should investigate an alternative

@weissi
Copy link

weissi commented May 24, 2025

and soon epoll

Where are you intending to run the epoll? A new thread pool just for Subprocess? Or a new thread for each process? Neither sound ideal

@iCharlesHu
Copy link
Contributor Author

and soon epoll

Where are you intending to run the epoll? A new thread pool just for Subprocess? Or a new thread for each process? Neither sound ideal

I'm still experimenting, but the current plan is to one new thread for the parent process (via static let singleton), so it doesn't grow with the amount of subprocess spawned.

@iCharlesHu
Copy link
Contributor Author

iCharlesHu commented May 30, 2025

After studying apple/swift-async-algorithms#305, I've come to the conclusion that unfortunately we simply can't make the read option "push-based" if we want to rely on DispatchIO. This is simply because no matter what kind of back pressure mechanism the stream itself implements, we can't translate that pressure to DispatchIO and ask it to slow down since it doesn't support back pressure itself (blocking the io handler is a no-go).

Instead of using an AsyncStream alternative, we simply just don't rely on AsyncStream and revert back to using withCheckedThrowingContinuation to fetch buffer chunk by chunk asynchronously.

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

No branches or pull requests

2 participants