GeezerVison is showing github.com — HTTP/2 Priority Tree Event Notification · Issue #2779 · netty/netty
HTTP/2 Priority Tree Event Notification #2779DescriptionThrough investigation and discussion in PR #2775 there needs to be more investigation into the current implementation of the Http2Connection.Listener interface with respect to tree restructuring and listener notification. ActivityScottmitch commented on Aug 17, 2014 The HTTP/1.x translation layer needs to be notified when ever a node's parent changes. The interface for Http2Connection.Listener.streamPriorityChanged lends itself to this but is not invoked for all parent change events. Should this be invoked in a different spot(s)? For example is the DefaultHttp2OutboundFlowController$streamPriorityChanged method correctly updating state with the current invocation of streamPriorityChanged in DefaultHttp2Connection? Scottmitch commented on Aug 17, 2014 Here is the initial discussion extracted from PR #2775
@nmittler - I would like to make some changes to support tracking the priority information in the HTTP/1.x headers.
Change Summary
- Add method:
Http2Connection.Listener.parentChange(Http2Stream stream, Http2Stream oldParent) which is invoked in DefaultHttp2Connection.addChild (and possibly other spots).
- Re-order
stream.setPriority(...) calls to be after the onXXXRead(...) calls in AbstractHttp2ConnectionHandler
Potential negatives
- The new parentChange method is fine grained and will be invoked once for each listener for each parent change.
DefaultHttp2OutboundFlowController consumes priority listener events and may be impacted (although I don't think it will be because I don't think I need to change the onXXXWrite flow).
- (Regardless of implementation) Depending on when the stream events come in it may be past the HTTP/1.x message flow and the event may be ignored.
Justification
The HTTP/1.x headers currently list
- Parent Stream Id
- Is Exclusive
- Weight
Weight and IsExclusive can be obtained reliably from the onXXXRead methods. The parent stream id is currently not being kept up to date in all situations (if tree operations move a node unrelated to the onXXXRead method). To mitigate this I would like to add a method to the listener interface that is invoked when a parent link changes.
After this change there will still be an ordering issue between when the priority tree events are dispatched (via stream.setPriority(...)) and the onHeadersRead or onPriorityRead event. The ordering issue is if I subscribe the the priority tree listener interface for events it is possible (in fact likely) that I will not know that the stream exists (because the onXXXRead method hasn't been called). So to solve this I would need to move the stream.setPriority(...) method to be after the onXXXRead method. Scottmitch commented on Aug 17, 2014 @nmittler - Can you explain the conditional statements leading up to setting the stream priority when a header is read on line 862 on master? For example what if the first header message contains prioritization information, will we be setting the priority on the stream? Also what if the stream is in the half-closed local state? nmittler commented on Aug 17, 2014 @Scottmitch maybe we can generalize this change a bit. The current Listener interface has two event handlers:
streamPriorityChanged(Http2Stream stream, Http2Stream previousParent) for simple changes, possibly just changing the parent.
streamPrioritySubtreeChanged(Http2Stream stream, Http2Stream subtreeRoot) when a node was made to be dependent on one of its descendants. In this case, the subtree starts at the new parent (previously was the descendant).
These events were tailored for use by the outbound flow controller logic, but I think we can simplify this interface so it will work for all use cases.
streamPriorityChanging(Http2Stream stream, Http2Stream previousParent) Called for all affected nodes before they are moved or their subtree is restructured. Need to think about it more, but event order may matter (bottom-up?) to make sure that the outbound flow controller properly removes weight calculations up the tree.
streamPriorityChanged(Http2Stream stream, Http2Stream newParent);
Called after each affect node's priority has changed or it's final position in the tree has been restored. Again, event order may matter (top-down?) ... need to iron out the details.
We likely will want to do this for all affected nodes in order:
- streamPriorityChanging for all nodes about to be affected
- make all the changes to the tree/nodes.
- streamPriorityChanged for all nodes that were affected.
Thoughts? Scottmitch commented on Aug 18, 2014 The generalization you suggest is exactly what I had in mind. I agree the order of events should be well coordinated to avoid notification at incorrect times when manipulation is still occurring and also to handle the case that you currently are handling when a node is moved into its child tree structure. nmittler commented on Aug 18, 2014 @Scottmitch ok sounds great! Let's get the draft 14 framing PR cherrypicked and I can start working on this. Scottmitch commented on Aug 18, 2014 @nmittler - We can handle the coordination between http2 core codec and the http translation layer in the same manner as the draft-14 updates (I will ultimately submit a PR based upon your cherry picked changes). nmittler commented on Aug 18, 2014 @Scottmitch so your PR will be blocked on the priority changes? Would it be easier for you to just take over this bug and incorporate the changes into your PR? Scottmitch commented on Aug 18, 2014 @nmittler - Do you mean handle this as part of PR #2778? If so I think it would be best to handle this as a separate PR to break up concerns. In terms of who does the work on the listener interface (and related) changes and I can take a stab at it if you want. nmittler commented on Aug 18, 2014 @Scottmitch that was my thought, since I didn't want to further block #2778. However, if you can implement it without the priority changes for now, that would definitely make it easier to divide up the work ... and I'll just take care of this in parallel. Will that work? Scottmitch commented on Aug 18, 2014 @nmittler - That sounds ideal. Feel free to work on this. I can apply the updates to the HTTP/1.x translation layer after #2778 is accepted (and likely work with you in parallel again to ensure compatibility/timely completion of my changes). Scottmitch commented on Aug 19, 2014 Here is an example (which can be made more minimal if necessary) of the non-restructure case which demonstrates the issue and may make a good test case.
Initial State
Each of the following nodes represents a stream, and the letter is representative of their stream ID.
A
/ | \
B C D
/ \ / \ / \
E F G H I J
- Call
C.setPriority(D, 4, true) from DefaultHttp2Connection
End Result
A
/ \
B D
/ \ |
E F C
/ / \ \
G H I J
Current Implementation Result
notifyPriorityChanged(C, A) is called but is the priorityBytes in DefaultHttp2OutboundFlowController for I and J ever added into C (and up the tree)?
- There is no notification for I and J even though their parents have changed (new functionality requested by this issue).
nmittler commented on Aug 19, 2014 @Scottmitch So I think the new logic would do the following:
- streamPriorityChanging for C, G, H, I, and J
- Update the tree
- streamPriorityChanged for G, H, I, J, and C
Does that sound right to you? Scottmitch commented on Aug 19, 2014 @nmittler - I made need some clarification on the meaning of streamPriorityChang[ed|ing] but are G, H, I, and J changing priority? I am fixed on the mindset of notifying when parents change and so I may have tunnel vision.
I think the nodes that are changing priority (if priority is the sum of all immediate decedent priorities) are (bottom up): C, D, A.
The nodes that are changing parents are (top down): C (from A to D), I and J (from D to C) nmittler commented on Aug 19, 2014 Getting notified for each element in the affected subtree(s) is useful for the outbound flow controller, which maintains state (i.e. total number of pending bytes for the subtree) at each node. I was imagining that streamPriorityChanging would allow the flow controller to remove the pending bytes upward in the tree for that node. When streamPriorityChanged is invoked, it would then add the pending bytes up the tree for that node ... if it was assigned a new parent, that's fine.
So all of these events are useful for this case, but will they cause confusion for other cases? We can always throw a ton of documentation at the interface :) Scottmitch commented on Aug 19, 2014 I think I see where you are coming from by referencing incrementPriorityBytes. I think my mental model of the interface was a bit different:
Notify in a top down manner
parentChanging(Http2Stream stream, Http2Stream newParent)
tree changes happen here
parentChanged(Http2Stream stream, Http2Stream oldParent)
This structures the interface more around general tree operations and I think decreases the chances of clients missing relevant events (or double counting some events). I would need to think about how this generalizes to the case when we are moving a node into its decedent sub-tree.
I put the changing events in italics because I'm not sure if they are needed?
In the previous example the order of events -> and resulting flow controller operations:
parentChanged(C, A) -> subtract C.priority from A up to root, add C.priority to C.parent up to root
parentChanged(I, D) -> subtract I.priority from D up to root, add I.priority to I.parent up to root
parentChanged(J, D) -> subtract J.priority from D up to root, add J.priority to J.parent up to root Scottmitch commented on Aug 19, 2014 Lets try an example where a node is moved into its own sub-tree. The spec conveniently has an example for this case http://http2.github.io/http2-spec/index.html#rfc.section.5.3.3.
Non-exclusive order of events
parentChanged(D, C) -> subtract D.priority from C up to root, add D.priority to D.parent up to root
parentChanged(A, ?) -> subtract A.priority from ? up to root, add A.priority to A.parent up to root
Exclusive order of events
parentChanged(D, C) -> subtract D.priority from C up to root, add D.priority to D.parent up to root
parentChanged(A, ?) -> subtract A.priority from ? up to root, add A.priority to A.parent up to root
parentChanged(F, D) -> subtract F.priority from D up to root, add F.priority to F.parent up to root
I think these both work, but does it generalize?
This interface also facilitates the information I am after, being able to generate messages when individual node parent change events occur. If this generalizes then it also reduces the required interface for priority tree events from 2 to 1. Scottmitch commented on Aug 21, 2014 nmittler commented on Aug 22, 2014 Scottmitch commented on Aug 22, 2014
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|