Top Description Inners Fields Constructors Methods
io.netty5.handler.codec.http2

public final Class WeightedFairQueueByteDistributor

extends Object
implements StreamByteDistributor
Class Inheritance
All Implemented Interfaces
io.netty5.handler.codec.http2.StreamByteDistributor
Annotations
@UnstableApi
Imports
io.netty5.util.collection.IntCollections, .IntObjectHashMap, .IntObjectMap, io.netty5.util.internal.DefaultPriorityQueue, .EmptyPriorityQueue, .PriorityQueue, .PriorityQueueNode, .SystemPropertyUtil, .UnstableApi, java.io.Serializable, java.util.ArrayList, .Comparator, .Iterator, .List

A 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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
WeightedFairQueueByteDistributor.ParentChangedEvent

Allows a correlation to be made between a stream and its old parent before a parent change occurs.

private class
WeightedFairQueueByteDistributor.State

The remote flow control state for a single stream.

private static class
WeightedFairQueueByteDistributor.StateOnlyComparator

A comparator for State which has no associated Http2Stream object.

private static class

Field Summary

Modifier and TypeField 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.State
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.PropertyKey
private final IntObjectMap<WeightedFairQueueByteDistributor.State>
stateOnlyMap

If there is no Http2Stream object, but we still persist priority information then this is where the state will reside.

private final PriorityQueue<WeightedFairQueueByteDistributor.State>
stateOnlyRemovalQueue

This queue will hold streams that are not active and provides the capability to retain priority for streams which have no Http2Stream object.

Constructor Summary

AccessConstructor and Description
public
public
WeightedFairQueueByteDistributor(Http2Connection connection, int maxStateOnlySize)

Method Summary

Modifier and TypeMethod 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.Writer writer)

Implements io.netty5.handler.codec.http2.StreamByteDistributor.distribute.

Distributes up to maxBytes to those streams containing streamable bytes and iterates across those streams to write the appropriate bytes.
private int
private int
distributeToChildren(int maxBytes, StreamByteDistributor.Writer writer, WeightedFairQueueByteDistributor.State state)

It is a pre-condition that state.poll() returns a non-null value.

pack-priv boolean
isChild(int childId, int parentId, short weight)

For testing only!

pack-priv void
notifyParentChanged(List<WeightedFairQueueByteDistributor.ParentChangedEvent>
The events (top down order) which have changed
events
)

Notify all listeners of the priority tree change events (in ascending order)

pack-priv int
numChildren(int streamId)

For testing only!

private WeightedFairQueueByteDistributor.State
private WeightedFairQueueByteDistributor.State
state(int streamId)

public void
updateDependencyTree(int
The stream identifier associated with the child stream.
childStreamId
,
int
The stream identifier associated with the parent stream. May be 0, to make childStreamId and immediate child of the connection.
parentStreamId
,
short
The weight which is used relative to other child streams for parentStreamId. This value must be between 1 and 256 (inclusive).
weight
,
boolean
If childStreamId should be the exclusive dependency of parentStreamId.
exclusive
)

Implements io.netty5.handler.codec.http2.StreamByteDistributor.updateDependencyTree.

Explicitly update the dependency tree.
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait