[Proof of concept] Async non-blocking IO using task executor preference #2648
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.
This a PoC PR mostly for educational reasons. Don't expect any more work on this but I wanted to showcase that it is possible and it might be interesting for others in the community.
Motivation
During the adoption of our new
NIOAsyncChannel
we came across a few issues such as:NIOAsyncChannel
components and the underlying pipelineEventLoopFutures
. This leads to API problems higher up the stack where we cannot spell it nicely with async primitives.The first one can be fixed with new bootstraps but the last one is inherently tied to how our current networking stack works. After thinking about this more, I wanted to try if we could respell NIO with purely asynchronous primitives. This became possible via the newly introduced task executor preference feature that allows us to implement thread hops in normal async code.
Modification
This PR is mostly a showcase of how the very lowest level could work for a non-blocking networking stack that is written using concurrency primitives such as
TaskExecutor
s andAsyncSequence
. This PR shows three separate pieces working:IOExecutor: TaskExecutor
that spawns apthread
. This thread is running a loop to executeUnownedJob
s and knows how to handle I/O via a selector (kqueue)TCPConenction
that uses theIOExecutor
to handle non blocking reads and writes. It exposes them via anAsyncSequence
and andAsyncWriter
TCPListener
that can accept new inboundTCPConnection
s.TODOs