StreamByteDistributor that is sensitive to stream priority and uses
Weighted Fair Queueing approach for distributing
bytes.
Inspiration for this distributor was taken from Linux's Completely Fair Scheduler to model the distribution of bytes to simulate an "ideal multi-tasking CPU", but in this case we are simulating an "ideal multi-tasking NIC".
Each write operation will use the allocationQuantum(int) to know how many more bytes should be allocated
relative to the next stream which wants to write. This is to balance fairness while also considering goodput.
| Modifier and Type | Class and Description |
|---|---|
| private static class | WeightedFairQueueByteDistributor.
Allows a correlation to be made between a stream and its old parent before a parent change occurs. |
| private class | WeightedFairQueueByteDistributor.
The remote flow control state for a single stream. |
| private static class | WeightedFairQueueByteDistributor.
A comparator for |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private int | allocationQuantum
The minimum number of bytes that we will attempt to allocate to a stream. |
| private final Http2Connection | |
| private final WeightedFairQueueByteDistributor. | |
| private static final int | DEFAULT_MAX_STATE_ONLY_SIZE
FireFox currently uses 5 streams to establish QoS classes. |
| pack-priv static final int | INITIAL_CHILDREN_MAP_SIZE
The initial size of the children map is chosen to be conservative on initial memory allocations under the assumption that most streams will have a small number of children. |
| private final int | |
| private final Http2Connection. | |
| private final IntObjectMap | stateOnlyMap
If there is no Http2Stream object, but we still persist priority information then this is where the state will reside. |
| private final PriorityQueue | stateOnlyRemovalQueue
This queue will hold streams that are not active and provides the capability to retain priority for streams which
have no |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | allocationQuantum(int
the amount of bytes that will be allocated to each stream. Must be > 0. allocationQuantum)Sets the amount of bytes that will be allocated to each stream. |
| public boolean | distribute(int
the maximum number of bytes to write. maxBytes, StreamByteDistributor.Implements io. maxBytes to those streams containing streamable bytes and
iterates across those streams to write the appropriate bytes.
|
| private int | distribute(int maxBytes, StreamByteDistributor.
|
| private int | distributeToChildren(int maxBytes, StreamByteDistributor.
It is a pre-condition that |
| pack-priv boolean | |
| pack-priv void | notifyParentChanged(List<WeightedFairQueueByteDistributor.
The events (top down order) which have changed eventsNotify all listeners of the priority tree change events (in ascending order) |
| pack-priv int | |
| private WeightedFairQueueByteDistributor. | |
| private WeightedFairQueueByteDistributor. | |
| public void | updateDependencyTree(int
The stream identifier associated with the child stream. childStreamId, int The stream identifier associated with the parent stream. May be parentStreamId, short 0,
to make childStreamId and immediate child of the connection.The weight which is used relative to other child streams for weight, boolean parentStreamId. This value
must be between 1 and 256 (inclusive).If exclusive)childStreamId should be the exclusive dependency of parentStreamId.Implements io. |
| public void | updateStreamableBytes(StreamByteDistributor.
Implements io. |
| allocationQuantum | back to summary |
|---|---|
| private int allocationQuantum The minimum number of bytes that we will attempt to allocate to a stream. This is to help improve goodput on a per-stream basis. | |
| connection | back to summary |
|---|---|
| private final Http2Connection connection | |
| connectionState | back to summary |
|---|---|
| private final WeightedFairQueueByteDistributor. | |
| DEFAULT_MAX_STATE_ONLY_SIZE | back to summary |
|---|---|
| private static final int DEFAULT_MAX_STATE_ONLY_SIZE FireFox currently uses 5 streams to establish QoS classes. | |
| INITIAL_CHILDREN_MAP_SIZE | back to summary |
|---|---|
| pack-priv static final int INITIAL_CHILDREN_MAP_SIZE The initial size of the children map is chosen to be conservative on initial memory allocations under the assumption that most streams will have a small number of children. This choice may be sub-optimal if when children are present there are many children (i.e. a web page which has many dependencies to load). Visible only for testing! | |
| maxStateOnlySize | back to summary |
|---|---|
| private final int maxStateOnlySize | |
| stateKey | back to summary |
|---|---|
| private final Http2Connection. | |
| stateOnlyMap | back to summary |
|---|---|
| private final IntObjectMap<WeightedFairQueueByteDistributor. If there is no Http2Stream object, but we still persist priority information then this is where the state will reside. | |
| stateOnlyRemovalQueue | back to summary |
|---|---|
| private final PriorityQueue<WeightedFairQueueByteDistributor. This queue will hold streams that are not active and provides the capability to retain priority for streams which
have no | |
| WeightedFairQueueByteDistributor | back to summary |
|---|---|
| public WeightedFairQueueByteDistributor(Http2Connection connection) | |
| WeightedFairQueueByteDistributor | back to summary |
|---|---|
| public WeightedFairQueueByteDistributor(Http2Connection connection, int maxStateOnlySize) | |
| allocationQuantum | back to summary |
|---|---|
| public void allocationQuantum(int allocationQuantum) Sets the amount of bytes that will be allocated to each stream. Defaults to 1KiB.
| |
| distribute | back to summary |
|---|---|
| public boolean distribute(int maxBytes, StreamByteDistributor. Implements io. Doc from io. Distributes up to The streamable bytes are not automatically updated by calling this method. It is up to the
caller to indicate the number of bytes streamable after the write by calling
| |
| distribute | back to summary |
|---|---|
| private int distribute(int maxBytes, StreamByteDistributor. | |
| distributeToChildren | back to summary |
|---|---|
| private int distributeToChildren(int maxBytes, StreamByteDistributor. It is a pre-condition that For the recursive caseIf a stream has no children (in the allocation tree) than that node must be active or it will not be in the allocation tree. If a node is active then it will not delegate to children and recursion ends.For the initial caseWe check connectionState.activeCountForTree == 0 before any allocation is done. So if the connection stream has no active children we don't get into this method. | |
| isChild | back to summary |
|---|---|
| pack-priv boolean isChild(int childId, int parentId, short weight) For testing only! | |
| notifyParentChanged | back to summary |
|---|---|
| pack-priv void notifyParentChanged(List<WeightedFairQueueByteDistributor. Notify all listeners of the priority tree change events (in ascending order)
| |
| numChildren | back to summary |
|---|---|
| pack-priv int numChildren(int streamId) For testing only! | |
| state | back to summary |
|---|---|
| private WeightedFairQueueByteDistributor. | |
| state | back to summary |
|---|---|
| private WeightedFairQueueByteDistributor. | |
| updateDependencyTree | back to summary |
|---|---|
| public void updateDependencyTree(int childStreamId, int parentStreamId, short weight, boolean exclusive) Implements io. Doc from io. Explicitly update the dependency tree. This method is called independently of stream state changes.
| |
| updateStreamableBytes | back to summary |
|---|---|
| public void updateStreamableBytes(StreamByteDistributor. Implements io. Doc from io. Called when the streamable bytes for a stream has changed. Until this method is called for the first time for a give stream, the stream is assumed to have no streamable bytes.
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final WeightedFairQueueByteDistributor. | |
| pack-priv final WeightedFairQueueByteDistributor. |
| Access | Constructor and Description |
|---|---|
| pack-priv | ParentChangedEvent(WeightedFairQueueByteDistributor.
The state who has had a parent change. state,The previous parent. oldParentCreate a new instance. |
| oldParent | back to summary |
|---|---|
| pack-priv final WeightedFairQueueByteDistributor. | |
| state | back to summary |
|---|---|
| pack-priv final WeightedFairQueueByteDistributor. | |
| ParentChangedEvent | back to summary |
|---|---|
| pack-priv ParentChangedEvent(WeightedFairQueueByteDistributor. Create a new instance.
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv int | activeCountForTree
Count of nodes rooted at this sub tree with |
| pack-priv IntObjectMap | |
| pack-priv int | |
| private byte | |
| pack-priv WeightedFairQueueByteDistributor. | |
| pack-priv long | pseudoTime
A pseudo time maintained for immediate children to base their |
| private final PriorityQueue | |
| private int | |
| pack-priv long | pseudoTimeToWrite
An estimate of when this node should be given the opportunity to write data. |
| private static final byte | |
| private static final byte | |
| private static final byte | |
| private int | |
| pack-priv Http2Stream | stream
Maybe |
| pack-priv int | |
| pack-priv final int | |
| pack-priv long | |
| pack-priv short |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv | |
| pack-priv | |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| pack-priv void | |
| private long | |
| private void | |
| private void | |
| pack-priv boolean | |
| pack-priv boolean | |
| pack-priv boolean | |
| pack-priv void | offerAndInitializePseudoTime(WeightedFairQueueByteDistributor.
The concept of pseudoTime can be influenced by priority tree manipulations or if a stream goes from "active" to "non-active". |
| pack-priv void | |
| pack-priv WeightedFairQueueByteDistributor. | |
| pack-priv WeightedFairQueueByteDistributor. | |
| public int | priorityQueueIndex(DefaultPriorityQueue<?> queue)
Implements io. priorityQueueIndex(DefaultPriorityQueue, int) for the value corresponding to
queue.
|
| public void | priorityQueueIndex(DefaultPriorityQueue<?>
The queue for which the index is being set. queue, int The index as used by i)DefaultPriorityQueue.Implements io. DefaultPriorityQueue to maintain state for an element in the queue.
|
| private IntObjectMap | Returns: The map of children prior to this operation, excludingstreamToRetain if present.Remove all children with the exception of |
| pack-priv void | removeChild(WeightedFairQueueByteDistributor.
Removes the child priority and moves any of its dependencies to being direct dependencies on this node. |
| pack-priv void | |
| private void | |
| pack-priv void | |
| private void | |
| pack-priv void | |
| pack-priv void | takeChild(WeightedFairQueueByteDistributor.
|
| pack-priv void | takeChild(Iterator<IntObjectMap.
Adds a child to this priority. |
| public String | |
| private void | |
| private void | |
| pack-priv void | |
| pack-priv void | updatePseudoTime(WeightedFairQueueByteDistributor.
Assumes the parents |
| pack-priv void | |
| pack-priv boolean | |
| pack-priv void |
| activeCountForTree | back to summary |
|---|---|
| pack-priv int activeCountForTree Count of nodes rooted at this sub tree with | |
| children | back to summary |
|---|---|
| pack-priv IntObjectMap<WeightedFairQueueByteDistributor. | |
| dependencyTreeDepth | back to summary |
|---|---|
| pack-priv int dependencyTreeDepth | |
| flags | back to summary |
|---|---|
| private byte flags | |
| parent | back to summary |
|---|---|
| pack-priv WeightedFairQueueByteDistributor. | |
| pseudoTime | back to summary |
|---|---|
| pack-priv long pseudoTime A pseudo time maintained for immediate children to base their | |
| pseudoTimeQueue | back to summary |
|---|---|
| private final PriorityQueue<WeightedFairQueueByteDistributor. | |
| pseudoTimeQueueIndex | back to summary |
|---|---|
| private int pseudoTimeQueueIndex | |
| pseudoTimeToWrite | back to summary |
|---|---|
| pack-priv long pseudoTimeToWrite An estimate of when this node should be given the opportunity to write data. | |
| STATE_IS_ACTIVE | back to summary |
|---|---|
| private static final byte STATE_IS_ACTIVE | |
| STATE_IS_DISTRIBUTING | back to summary |
|---|---|
| private static final byte STATE_IS_DISTRIBUTING | |
| STATE_STREAM_ACTIVATED | back to summary |
|---|---|
| private static final byte STATE_STREAM_ACTIVATED | |
| stateOnlyQueueIndex | back to summary |
|---|---|
| private int stateOnlyQueueIndex | |
| stream | back to summary |
|---|---|
| pack-priv Http2Stream stream Maybe | |
| streamableBytes | back to summary |
|---|---|
| pack-priv int streamableBytes | |
| streamId | back to summary |
|---|---|
| pack-priv final int streamId | |
| totalQueuedWeights | back to summary |
|---|---|
| pack-priv long totalQueuedWeights | |
| weight | back to summary |
|---|---|
| pack-priv short weight | |
| State | back to summary |
|---|---|
| pack-priv State(int streamId) | |
| State | back to summary |
|---|---|
| pack-priv State(Http2Stream stream) | |
| State | back to summary |
|---|---|
| pack-priv State(Http2Stream stream, int initialSize) | |
| State | back to summary |
|---|---|
| pack-priv State(int streamId, Http2Stream stream, int initialSize) | |
| activeCountChangeForTree | back to summary |
|---|---|
| pack-priv void activeCountChangeForTree(int increment) | |
| close | back to summary |
|---|---|
| pack-priv void close() | |
| getTotalWeight | back to summary |
|---|---|
| private long getTotalWeight() | |
| initChildren | back to summary |
|---|---|
| private void initChildren() | |
| initChildrenIfEmpty | back to summary |
|---|---|
| private void initChildrenIfEmpty() | |
| isActive | back to summary |
|---|---|
| pack-priv boolean isActive() | |
| isDescendantOf | back to summary |
|---|---|
| pack-priv boolean isDescendantOf(WeightedFairQueueByteDistributor. | |
| isDistributing | back to summary |
|---|---|
| pack-priv boolean isDistributing() | |
| offerAndInitializePseudoTime | back to summary |
|---|---|
| pack-priv void offerAndInitializePseudoTime(WeightedFairQueueByteDistributor. The concept of pseudoTime can be influenced by priority tree manipulations or if a stream goes from "active"
to "non-active". This method accounts for that by initializing the | |
| offerPseudoTimeQueue | back to summary |
|---|---|
| pack-priv void offerPseudoTimeQueue(WeightedFairQueueByteDistributor. | |
| peekPseudoTimeQueue | back to summary |
|---|---|
| pack-priv WeightedFairQueueByteDistributor. | |
| pollPseudoTimeQueue | back to summary |
|---|---|
| pack-priv WeightedFairQueueByteDistributor. Must only be called if the pseudoTimeQueue is non-empty! | |
| priorityQueueIndex | back to summary |
|---|---|
| public int priorityQueueIndex(DefaultPriorityQueue<?> queue) Implements io. Doc from io. Get the last value set by Throwing exceptions from this method will result in undefined behavior.
| |
| priorityQueueIndex | back to summary |
|---|---|
| public void priorityQueueIndex(DefaultPriorityQueue<?> queue, int i) Implements io. Doc from io. Used by Throwing exceptions from this method will result in undefined behavior.
| |
| removeAllChildrenExcept | back to summary |
|---|---|
| private IntObjectMap Remove all children with the exception of
| |
| removeChild | back to summary |
|---|---|
| pack-priv void removeChild(WeightedFairQueueByteDistributor. Removes the child priority and moves any of its dependencies to being direct dependencies on this node. | |
| removePseudoTimeQueue | back to summary |
|---|---|
| pack-priv void removePseudoTimeQueue(WeightedFairQueueByteDistributor. | |
| setActive | back to summary |
|---|---|
| private void setActive() | |
| setDistributing | back to summary |
|---|---|
| pack-priv void setDistributing() | |
| setParent | back to summary |
|---|---|
| private void setParent(WeightedFairQueueByteDistributor. | |
| setStreamReservedOrActivated | back to summary |
|---|---|
| pack-priv void setStreamReservedOrActivated() | |
| takeChild | back to summary |
|---|---|
| pack-priv void takeChild(WeightedFairQueueByteDistributor. | |
| takeChild | back to summary |
|---|---|
| pack-priv void takeChild(Iterator<IntObjectMap. Adds a child to this priority. If exclusive is set, any children of this node are moved to being dependent on the child. | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| toString | back to summary |
|---|---|
| private void toString(StringBuilder sb) | |
| unsetActive | back to summary |
|---|---|
| private void unsetActive() | |
| unsetDistributing | back to summary |
|---|---|
| pack-priv void unsetDistributing() | |
| updatePseudoTime | back to summary |
|---|---|
| pack-priv void updatePseudoTime(WeightedFairQueueByteDistributor. Assumes the parents | |
| updateStreamableBytes | back to summary |
|---|---|
| pack-priv void updateStreamableBytes(int newStreamableBytes, boolean isActive) | |
| wasStreamReservedOrActivated | back to summary |
|---|---|
| pack-priv boolean wasStreamReservedOrActivated() | |
| write | back to summary |
|---|---|
| pack-priv void write(int numBytes, StreamByteDistributor. | |
State which has no associated Http2Stream object. The general precedence is:
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final WeightedFairQueueByteDistributor. | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public int | compare(WeightedFairQueueByteDistributor.
the first object to be compared. o1,the second object to be compared. o2Implements java. |
| INSTANCE | back to summary |
|---|---|
| pack-priv static final WeightedFairQueueByteDistributor. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| StateOnlyComparator | back to summary |
|---|---|
| private StateOnlyComparator() | |
| compare | back to summary |
|---|---|
| public int compare(WeightedFairQueueByteDistributor. Implements java. Doc from java. Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
The implementor must ensure that
The implementor must also ensure that the relation is transitive:
Finally, the implementor must ensure that
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final WeightedFairQueueByteDistributor. | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public int | compare(WeightedFairQueueByteDistributor.
the first object to be compared. o1,the second object to be compared. o2Implements java. |
| INSTANCE | back to summary |
|---|---|
| pack-priv static final WeightedFairQueueByteDistributor. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| StatePseudoTimeComparator | back to summary |
|---|---|
| private StatePseudoTimeComparator() | |
| compare | back to summary |
|---|---|
| public int compare(WeightedFairQueueByteDistributor. Implements java. Doc from java. Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
The implementor must ensure that
The implementor must also ensure that the relation is transitive:
Finally, the implementor must ensure that
| |