Class WeightedFairQueueByteDistributor
java.lang.Object
io.netty.handler.codec.http2.WeightedFairQueueByteDistributor
- All Implemented Interfaces:
StreamByteDistributor
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 Class Summary
Nested classes/interfaces inherited from interface StreamByteDistributor
StreamByteDistributor.StreamState, StreamByteDistributor.Writer -
Constructor Summary
ConstructorsConstructorDescriptionWeightedFairQueueByteDistributor(Http2Connection connection) WeightedFairQueueByteDistributor(Http2Connection connection, int maxStateOnlySize) -
Method Summary
Modifier and TypeMethodDescriptionvoidallocationQuantum(int allocationQuantum) Sets the amount of bytes that will be allocated to each stream.booleandistribute(int maxBytes, StreamByteDistributor.Writer writer) Distributes up tomaxBytesto those streams containing streamable bytes and iterates across those streams to write the appropriate bytes.voidupdateDependencyTree(int childStreamId, int parentStreamId, short weight, boolean exclusive) Explicitly update the dependency tree.voidCalled when the streamable bytes for a stream has changed.
-
Constructor Details
-
WeightedFairQueueByteDistributor
-
WeightedFairQueueByteDistributor
-
-
Method Details
-
updateStreamableBytes
Description copied from interface:StreamByteDistributorCalled 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.- Specified by:
updateStreamableBytesin interfaceStreamByteDistributor
-
updateDependencyTree
public void updateDependencyTree(int childStreamId, int parentStreamId, short weight, boolean exclusive) Description copied from interface:StreamByteDistributorExplicitly update the dependency tree. This method is called independently of stream state changes.- Specified by:
updateDependencyTreein interfaceStreamByteDistributor- Parameters:
childStreamId- The stream identifier associated with the child stream.parentStreamId- The stream identifier associated with the parent stream. May be0, to makechildStreamIdand immediate child of the connection.weight- The weight which is used relative to other child streams forparentStreamId. This value must be between 1 and 256 (inclusive).exclusive- IfchildStreamIdshould be the exclusive dependency ofparentStreamId.
-
distribute
Description copied from interface:StreamByteDistributorDistributes up tomaxBytesto those streams containing streamable bytes and iterates across those streams to write the appropriate bytes. Criteria for traversing streams is undefined and it is up to the implementation to determine when to stop at a given stream.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
StreamByteDistributor.updateStreamableBytes(StreamState).- Specified by:
distributein interfaceStreamByteDistributor- Parameters:
maxBytes- the maximum number of bytes to write.- Returns:
trueif there are still streamable bytes that have not yet been written, otherwisefalse.- Throws:
Http2Exception- If an internal exception occurs and internal connection state would otherwise be corrupted.
-
allocationQuantum
public void allocationQuantum(int allocationQuantum) Sets the amount of bytes that will be allocated to each stream. Defaults to 1KiB.- Parameters:
allocationQuantum- the amount of bytes that will be allocated to each stream. Must be > 0.
-