Skip to content

Default pipelining to maxConcurrentStreams with allowH2 #4143

Closed

Description

@slagiewka

Bug Description

The recent H2CClient work (#4118) does it well. If pipelining is not set, it defaults to maxConcurrentStreams which makes sense. This however, is not a case when a regular Client (or its descendent Agent) is in use.

Being on a HTTP/2 connection is still limited to either the default (1) or requires manual setup.
Manual setup is inconvenient and confusing. Pipelining is a HTTP/1.1 concept.

Docs say nothing about adjust pipelining when using HTTP/2 multiplexing and actually link to the HTTP/1.1 RFC under pipelining.

Reproducible By

sever.js
import { fetch, Agent, setGlobalDispatcher, interceptors } from "undici";
import { createServer } from "node:http";
import { once } from "node:events";

setGlobalDispatcher(
new Agent({
  allowH2: true,
  connections: 10,
  //pipelining: 100,
}).compose([interceptors.dns(), interceptors.retry()]),
);

const server = createServer((req, res) => {
fetch("https://my-https2-server.com", {
  signal: AbortSignal.timeout(1_000),
})
  .then((result) => {
    return Array.fromAsync(result.body);
  })
  .then(() => {
    res.end("");
  })
  .catch((err) => {
    res.writeHead(500);
    res.end("internal server error");
  });
}).listen("3000");

await once(server, "listening");
console.log("server started on port 3000");

Then run the server:

node index.js

And load test it. Run the same with and without pipelining set.

hey -n 15000 -c 100 -q 300 -t "1" http://localhost:3000

Expected Behavior

Same performance with or without pipelining set.

Environment

Node 23, macOS 15.3, but it's not platform related, it seems.

Additional context

Should #2750 make HTTP/2 on by default, users will not benefit from HTTP/2 at all - it might behave pretty much the same as HTTP/1.1 connections with keep-alive + some TLS overhead...

Activity

  1. added
    bug
    on Apr 3, 2025
  2. metcoder95 commented on Apr 3, 2025

    @metcoder95
    Member

    I'm not sure this is a bug per-se, rather an improvement in the way we setup H2 (as undici was pointing to be only 1.1 compatible).

    Adding a new option multiplexing that defaults to maxConcurrentStreams should suffice (companioned of its documentation).

    Would you like to send a PR for that?

  3. added
    enhancement
    H2
    and removed
    bug
    on Apr 3, 2025
  4. slagiewka commented on Apr 5, 2025

    @slagiewka
    ContributorAuthor

    Adding a new option multiplexing that defaults to maxConcurrentStreams should suffice (companioned of its documentation).

    Would you like to send a PR for that?

    I started dabbing at that and I think it would make things confusing.
    With an example set up that tries to work with HTTP/2 we'd have the following settings:

    • connections
    • maxConcurrentStreams
    • multiplexing

    Assume we'd want to sustain 1_000 concurrent requests. I would then open:

    • 10 connections with
    • 100 maxConcurrentStreams and
    • 100 multiplexing (or previously - pipelining)

    The question that comes to mind: why would a user need to configure multiplexing separately? Is it necessary? Why isn't maxConcurrentStreams actually the equivalent of multiplexing? What would be the point of setting these to different values? If a user would want lower multiplexing/concurrency on a connection/session why wouldn't they also lower the maxConcurrentStreams?

    Even if someone would be afraid of the peer changing SETTINGS_MAX_CONCURRENT_STREAMS:

    • to something lower - they could still lower maxConcurrentStreams on their end to the same result as changing multiplexing
    • to something higher - undici will still send at most maxConcurrentStreams per session and ignore the higher allowance (unless undici starts respecting the value set by peer).

    The only difference now is that pipelining actually controls the level of multiplexing. Should this be omitted, users could use one toggle to control the behaviour or leave it to the defaults and enjoy multiplexing.

  5. metcoder95 commented on Apr 6, 2025

    @metcoder95
    Member

    connections

    connections does only applies to high level APIs like Agents/Pools, for low level ones like Clients this is of no help as each Client/Dispatcher maps to a single socket.

    Indeed, that's a good point; pipelining, as per the nature of undici was handling the pipelining concept from HTTP/1.1 but I never fully connected the concepts.

    Agree with you, maxConcurrentStreams should be use as pipelining equivalent and manage the number of concurrent requests matching the current streams.

    Sadly this will impose a breaking change, we can attempt to keep warnings over that and state that we will honor mostly maxConcurrentStreams.

    Feel free to open a PR so we can iterate over it.

  6. added a commit that references this issue on Apr 13, 2025
    810d7c6
  7. slagiewka commented on Apr 13, 2025

    @slagiewka
    ContributorAuthor

    Started #4158.

  8. added a commit that references this issue on Feb 14, 2026
    bc5c5f6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    H2enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions