-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add IsFlush to Pipelines ReadResult #25059
Comments
Some questions:
|
Also we're thinking https://github.com/dotnet/corefx/issues/27185 this plus cancellation be better to solve issues with smarter buffering. |
Its a signal; it may be validly ignored as you may do currently with Flush; for example if you don't have enough data to validly do something with. e.g. input socket flushes due to no more data; however isn't currently enough data to create a http request.
public virtual PipeAwaiter<FlushResult> WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)
{
this.Write(source.Span);
return FlushAsync(cancellationToken);
}
That should throw (and it should do currently anyway?)
You need something to unlock the Read (with given reason) when the amount is smaller; like |
That's why you cancel on timer, to yield the read. You a timer anyways, you don't know if a full flush is coming. |
You could use the same argument for |
Not really, you can't tell today if a Stream is buffering or not, each stream behaves differently in that regard. You can't even tell if Streams require flushing or not, so the state today is that you always Flush or you write and nothing happens (or you know what the Stream implementation does). |
I still don't completely understand. With Streams you don't always Flush; you do a bunch of Writes and then you Flush; you don't Flush on every Write. Which would be the same pattern as I'm proposing; e.g. you Write until you have nothing current left to Write and then you Flush; so it wouldn't need timers? |
I need to understand the scenario you're trying to implement, what it looks like today and what it would look like with the IsFlush flag. I'd also like to understand the decisions that consumers make based on IsFlush. For the nagaling scenario this is much less efficient as you potentially wake up the reader much too often. With dotnet/corefx#27185, the pipe implementation can just avoid the schedule if you're less than the threshold. Of course it's then up to you to either pass a cancellation token or something to implement a timeout if the size limit (MTU for example) hasn't been reached. |
With Lets iron out some questions in dotnet/corefx#27185 as it could achieve the same ends. |
Had a chat with @davidfowl, we're not doing this at this time. |
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process. This process is part of our issue cleanup automation. |
[Flags] internal enum ResultFlags : byte { None = 0x0, Canceled = 0x1, Completed = 0x2, + Flush = 0x4 }
And set for calls to
FlushAsync()
This allows the reader; if it chooses, to differentiate between a
WriteAsync()
and aFlushAsync()
(if the writer differentiates)Use case
If
WriteAsync
andFlushAsync
are differentiated; aTextWriter
type on a Pipeline does not need to maintain arrays of internal buffered data to have good performance but only needs a char (or two?) to maintain the outstanding surrogate pairs for encoding; the rest can be directly written to the Pipe.If they don't differentiate then it can't write directly to the Pipe as writing a very small chunk followed by a flush in a loop would have an unacceptable performance degradation; so its back to maintaining internal arrays and then writing in a large chunk 😢
/cc @davidfowl @pakrym @stephentoub
The text was updated successfully, but these errors were encountered: