Add AsynchronizedFileSink for non-blocking PCAP recording#253
Open
RaghavRoy145 wants to merge 4 commits intoapple:mainfrom
Open
Add AsynchronizedFileSink for non-blocking PCAP recording#253RaghavRoy145 wants to merge 4 commits intoapple:mainfrom
RaghavRoy145 wants to merge 4 commits intoapple:mainfrom
Conversation
Motivation: The current PCAP recording functionality uses SynchronizedFileSink, which blocks the event loop, this patch attempts an introduction of AsynchronizedFileSink,which uses Swift's concurrency model to perform non-blocking file writes. This patch attempts to address swift-server/async-http-client#239. This change also ensures that debugging via PCAP recording remains accessible while preventing the event loop from stalling. Modifications: - Implemented AsynchronizedFileSink thread-safe, non-blocking writes. - Provided unit tests to verify correct behavior. Result: - Users can enable non-blocking PCAP recording using AsynchronizedFileSink, improving debugging without risking connection pool performance. - Test coverage ensures the new implementation works as expected.
Lukasa
reviewed
Mar 20, 2025
| } | ||
| } | ||
|
|
||
| public final class AsynchronizedFileSink { |
Contributor
There was a problem hiding this comment.
I think a better version of this uses _NIOFileSystem to provide the async file I/O APIs. That will also avoid the unsafe code. @glbrntt how do we feel about taking that dependency here?
Author
There was a problem hiding this comment.
Oh I didn't consider this, mostly took inspiration from the implementation of SynchronizedFileSink, though I don't think using the filesystem instead would be too tough. Let me know!
Contributor
There was a problem hiding this comment.
I'm a little hesitant to do it before we've made the FilePath changes as that may well have unavoidable API breaks.
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.
Motivation:
The current PCAP recording functionality uses SynchronizedFileSink, which blocks the event loop, this patch introduces AsynchronizedFileSink,which uses Swift's concurrency model to perform non-blocking file writes. This patch attempts to address swift-server/async-http-client#239.
This change also ensures that debugging via PCAP recording remains accessible while preventing the event loop from stalling.
Modifications:
Result: