Home / Class/ WeightedFairQueueByteDistributor Class — netty Architecture

WeightedFairQueueByteDistributor Class — netty Architecture

Architecture documentation for the WeightedFairQueueByteDistributor class in WeightedFairQueueByteDistributor.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  f6394c11_feeb_5e3e_8717_b7d2d36bbf34["WeightedFairQueueByteDistributor"]
  71cf42ec_8b96_e844_a28e_f91e8e96ff66["WeightedFairQueueByteDistributor.java"]
  f6394c11_feeb_5e3e_8717_b7d2d36bbf34 -->|defined in| 71cf42ec_8b96_e844_a28e_f91e8e96ff66
  0f84cad1_72bf_48c4_a975_f58d297dd3c2["WeightedFairQueueByteDistributor()"]
  f6394c11_feeb_5e3e_8717_b7d2d36bbf34 -->|method| 0f84cad1_72bf_48c4_a975_f58d297dd3c2
  33d23cb5_185a_3060_16b3_daf6707a6238["updateStreamableBytes()"]
  f6394c11_feeb_5e3e_8717_b7d2d36bbf34 -->|method| 33d23cb5_185a_3060_16b3_daf6707a6238
  ebb4ce48_a19b_1763_6677_772bd73eafff["updateDependencyTree()"]
  f6394c11_feeb_5e3e_8717_b7d2d36bbf34 -->|method| ebb4ce48_a19b_1763_6677_772bd73eafff
  a477195a_8699_0505_29de_529047b61e11["distribute()"]
  f6394c11_feeb_5e3e_8717_b7d2d36bbf34 -->|method| a477195a_8699_0505_29de_529047b61e11
  7ce4d636_6356_aee5_687d_ef7781b4722c["allocationQuantum()"]
  f6394c11_feeb_5e3e_8717_b7d2d36bbf34 -->|method| 7ce4d636_6356_aee5_687d_ef7781b4722c
  fee5801b_b90a_5512_05a6_7256df952cd8["distributeToChildren()"]
  f6394c11_feeb_5e3e_8717_b7d2d36bbf34 -->|method| fee5801b_b90a_5512_05a6_7256df952cd8
  fa3ca25f_05dd_7371_b6a8_9b6d9a3f7cb3["State()"]
  f6394c11_feeb_5e3e_8717_b7d2d36bbf34 -->|method| fa3ca25f_05dd_7371_b6a8_9b6d9a3f7cb3
  daf32ba4_709d_d1f9_81d5_29c2d914b743["isChild()"]
  f6394c11_feeb_5e3e_8717_b7d2d36bbf34 -->|method| daf32ba4_709d_d1f9_81d5_29c2d914b743
  c6821bac_6442_9638_44e8_4a99cc58a47a["numChildren()"]
  f6394c11_feeb_5e3e_8717_b7d2d36bbf34 -->|method| c6821bac_6442_9638_44e8_4a99cc58a47a
  25f3d9c7_29c4_05d1_8c21_d15e89a37789["notifyParentChanged()"]
  f6394c11_feeb_5e3e_8717_b7d2d36bbf34 -->|method| 25f3d9c7_29c4_05d1_8c21_d15e89a37789

Relationship Graph

Source Code

codec-http2/src/main/java/io/netty/handler/codec/http2/WeightedFairQueueByteDistributor.java lines 57–800

public final class WeightedFairQueueByteDistributor implements StreamByteDistributor {
    /**
     * 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!
     */
    static final int INITIAL_CHILDREN_MAP_SIZE =
            max(1, SystemPropertyUtil.getInt("io.netty.http2.childrenMapSize", 2));
    /**
     * FireFox currently uses 5 streams to establish QoS classes.
     */
    private static final int DEFAULT_MAX_STATE_ONLY_SIZE = 5;

    private final Http2Connection.PropertyKey stateKey;
    /**
     * If there is no Http2Stream object, but we still persist priority information then this is where the state will
     * reside.
     */
    private final IntObjectMap<State> stateOnlyMap;
    /**
     * This queue will hold streams that are not active and provides the capability to retain priority for streams which
     * have no {@link Http2Stream} object. See {@link StateOnlyComparator} for the priority comparator.
     */
    private final PriorityQueue<State> stateOnlyRemovalQueue;
    private final Http2Connection connection;
    private final State connectionState;
    /**
     * 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.
     */
    private int allocationQuantum = DEFAULT_MIN_ALLOCATION_CHUNK;
    private final int maxStateOnlySize;

    public WeightedFairQueueByteDistributor(Http2Connection connection) {
        this(connection, DEFAULT_MAX_STATE_ONLY_SIZE);
    }

    public WeightedFairQueueByteDistributor(Http2Connection connection, int maxStateOnlySize) {
        checkPositiveOrZero(maxStateOnlySize, "maxStateOnlySize");
        if (maxStateOnlySize == 0) {
            stateOnlyMap = IntCollections.emptyMap();
            stateOnlyRemovalQueue = EmptyPriorityQueue.instance();
        } else {
            stateOnlyMap = new IntObjectHashMap<State>(maxStateOnlySize);
            // +2 because we may exceed the limit by 2 if a new dependency has no associated Http2Stream object. We need
            // to create the State objects to put them into the dependency tree, which then impacts priority.
            stateOnlyRemovalQueue = new DefaultPriorityQueue<State>(StateOnlyComparator.INSTANCE, maxStateOnlySize + 2);
        }
        this.maxStateOnlySize = maxStateOnlySize;

        this.connection = connection;
        stateKey = connection.newKey();
        final Http2Stream connectionStream = connection.connectionStream();
        connectionStream.setProperty(stateKey, connectionState = new State(connectionStream, 16));

        // Register for notification of new streams.
        connection.addListener(new Http2ConnectionAdapter() {
            @Override
            public void onStreamAdded(Http2Stream stream) {
                State state = stateOnlyMap.remove(stream.id());
                if (state == null) {
                    state = new State(stream);
                    // Only the stream which was just added will change parents. So we only need an array of size 1.
                    List<ParentChangedEvent> events = new ArrayList<ParentChangedEvent>(1);
                    connectionState.takeChild(state, false, events);
                    notifyParentChanged(events);
                } else {
                    stateOnlyRemovalQueue.removeTyped(state);
                    state.stream = stream;
                }
                switch (stream.state()) {
                    case RESERVED_REMOTE:
                    case RESERVED_LOCAL:
                        state.setStreamReservedOrActivated();
                        // wasStreamReservedOrActivated is part of the comparator for stateOnlyRemovalQueue there is no
                        // need to reprioritize here because it will not be in stateOnlyRemovalQueue.
                        break;
                    default:

Frequently Asked Questions

What is the WeightedFairQueueByteDistributor class?
WeightedFairQueueByteDistributor is a class in the netty codebase, defined in codec-http2/src/main/java/io/netty/handler/codec/http2/WeightedFairQueueByteDistributor.java.
Where is WeightedFairQueueByteDistributor defined?
WeightedFairQueueByteDistributor is defined in codec-http2/src/main/java/io/netty/handler/codec/http2/WeightedFairQueueByteDistributor.java at line 57.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free