-
Notifications
You must be signed in to change notification settings - Fork 161
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
Port precise flow control to writable streams #318
Comments
Questions: What should we expose?I see two choices:
How should the
|
I think |
|
OK, this makes sense. I am still kind of unclear whether the producer or the stream should be setting the high water mark, but if we assume the stream, then this seems correct.
This seems like a potentially big problem. I think it would mean that unless the producer controls the high water mark, then waitForDesiredSize(n) is never very useful. Because you never know if you might end up waiting forever. Maybe one fix is that if n > highWaterMark, we notify you anyway, when desiredSize = highWaterMark.
Hmm, what do you think of making it work like (1) or (2)? Also, if we make these require positive, then for HWM = 0 writable streams they all reduce to the same thing. Probably that is OK. |
I have one other worry about desiredSize. Do you see it working in practice for UA created streams? E.g. let's take some examples (no comment on whether these will actually be implemented):
Do you think it will be reasonable for UAs to come up with high water marks for all of these, in order to govern desiredSize? Maybe in some cases the HWM will just be zero---is that OK as a default? |
Ah, yeah. That works. Notification threshold would be set to min(hightWaterMark, n)
(1) and (2) would work but changed signal is more flexible (yeah, HWM=0 would behave as them). What's the reason you preferred them than changed signal? Simplicity? I understand that the name "ready" isn't good name for "changed" signal, though.
Yeah. When HWM of 0 is used, desiredSize would be 0 or negative. The problem is that pipeTo() should be designed to (possibly by having some mode to) be able to push data to such a writable stream. "Push only when non-negative" would work? |
Current pipeTo() is: read() and wait for dest.ready. When data is read and dest is ready, write the read data to dest. For this kind of HWM=0 writable streams, pipeTo() should read() anyway when desiredSize becomes non-negative. I.e. non-negative desiredSize is treated as "ready". The actual value of desiredSize would be used to update precise pulling on readable stream to control amount to pull, but read() invocation happens anyway. Maybe this works? |
Yeah, basically simplicity. I cannot figure out the use case for the generic changed signal. The generic changed signal seems to not be very aligned with the high water mark idea. That is, I think two valid default strategies are either you should always be writing when desiredSize > 0 (1), or you should wait until the stream is drained and desiredSize = HWM (2). Anything more customizable can be taken care of by specific calls to waitForDesiredSize(n), with a parameter. (Remember, we are just trying to decide the default for In fact, maybe it does not matter too much. I think you can get (4) with I also noticed when reviewing Node streams that their Given this I propose:
I think this works if we say waitForDesiredSize waits for >= min(highWaterMark, n). So in this case it will be equivalent to waitForDesiredSize(0), which fulfills as soon as the queue drains. |
I was supposing cases where:
When the amount of data in WQ decreases a little, i.e. desiredSize increases, we should immediately tell that to RQ so that P can start producing more data. This argument supports (4). (5) is useful when:
(3) and (4) work but we can reduce number of notifications by (5).
Oh, OK. Then I slightly prefer using (1) for But as you wondered in the second paragraph for different topic, if our sizes are non-integer, the behavior cannot be realized by
Yeah, right.
Ah, ... I think I'm fine with this, too. |
Just a reminder here, the ready signal always fires the |
After #317, readable streams will have precise flow control. We should add something similar to writable streams. However, the shape of it will likely depend on the resolution of #316.
The text was updated successfully, but these errors were encountered: