Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set pipelining to 4 by default #3846

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/docs/api/Client.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Returns: `Client`
* **keepAliveTimeoutThreshold** `number | null` (optional) - Default: `2e3` - A number of milliseconds subtracted from server *keep-alive* hints when overriding `keepAliveTimeout` to account for timing inaccuracies caused by e.g. transport latency. Defaults to 2 seconds.
* **maxHeaderSize** `number | null` (optional) - Default: `--max-http-header-size` or `16384` - The maximum length of request headers in bytes. Defaults to Node.js' --max-http-header-size or 16KiB.
* **maxResponseSize** `number | null` (optional) - Default: `-1` - The maximum length of response body in bytes. Set to `-1` to disable.
* **pipelining** `number | null` (optional) - Default: `1` - The amount of concurrent requests to be sent over the single TCP/TLS connection according to [RFC7230](https://tools.ietf.org/html/rfc7230#section-6.3.2). Carefully consider your workload and environment before enabling concurrent requests as pipelining may reduce performance if used incorrectly. Pipelining is sensitive to network stack settings as well as head of line blocking caused by e.g. long running requests. Set to `0` to disable keep-alive connections.
* **pipelining** `number | null` (optional) - Default: `4` - The amount of concurrent requests to be sent over the single TCP/TLS connection according to [RFC7230](https://tools.ietf.org/html/rfc7230#section-6.3.2). Carefully consider your workload and environment before enabling concurrent requests as pipelining may reduce performance if used incorrectly. Pipelining is sensitive to network stack settings as well as head of line blocking caused by e.g. long running requests. Note that the `blocking` option applies. Set to `0` to disable keep-alive connections.
* **connect** `ConnectOptions | Function | null` (optional) - Default: `null`.
* **strictContentLength** `Boolean` (optional) - Default: `true` - Whether to treat request content length mismatches as errors. If true, an error is thrown when the request content-length header doesn't match the length of the request body.
* **autoSelectFamily**: `boolean` (optional) - Default: depends on local Node version, on Node 18.13.0 and above is `false`. Enables a family autodetection algorithm that loosely implements section 5 of [RFC 8305](https://tools.ietf.org/html/rfc8305#section-5). See [here](https://nodejs.org/api/net.html#socketconnectoptions-connectlistener) for more details. This option is ignored if not supported by the current Node version.
Expand Down
2 changes: 1 addition & 1 deletion lib/dispatcher/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class Client extends DispatcherBase {

this[kUrl] = util.parseOrigin(url)
this[kConnector] = connect
this[kPipelining] = pipelining != null ? pipelining : 1
this[kPipelining] = pipelining != null ? pipelining : 4
this[kMaxHeadersSize] = maxHeaderSize
this[kKeepAliveDefaultTimeout] = keepAliveTimeout == null ? 4e3 : keepAliveTimeout
this[kKeepAliveMaxTimeout] = keepAliveMaxTimeout == null ? 600e3 : keepAliveMaxTimeout
Expand Down
1 change: 1 addition & 0 deletions lib/web/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2070,6 +2070,7 @@ async function httpNetworkFetch (
{
body: null,
abort: null,
blocking: true,

onConnect (abort) {
// TODO (fix): Do we need connection here?
Expand Down
2 changes: 1 addition & 1 deletion test/client-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ test('stream GET destroy res', async (t) => {
after(() => server.close())

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
const client = new Client(`http://localhost:${server.address().port}`, { pipelining: 1 })
after(() => client.close())

client.stream({
Expand Down
2 changes: 1 addition & 1 deletion test/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ test('increase pipelining', async (t) => {
after(() => server.close())

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
const client = new Client(`http://localhost:${server.address().port}`, { pipelining: 1 })
after(() => client.destroy())

client.request({
Expand Down
4 changes: 2 additions & 2 deletions test/close-and-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ test('close should still reconnect', async (t) => {
after(() => server.close())

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
const client = new Client(`http://localhost:${server.address().port}`, { pipelining: 1 })
after(() => client.destroy())

t.ok(makeRequest())
Expand Down Expand Up @@ -200,7 +200,7 @@ test('close should call callback once finished', async (t) => {
after(() => server.close())

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
const client = new Client(`http://localhost:${server.address().port}`, { pipelining: 1 })
after(() => client.destroy())

t.ok(makeRequest())
Expand Down
3 changes: 2 additions & 1 deletion test/http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,8 @@ test('#2364 - Concurrent aborts', async t => {
connect: {
rejectUnauthorized: false
},
allowH2: true
allowH2: true,
pipelining: 1
})

t = tspl(t, { plan: 10 })
Expand Down
5 changes: 3 additions & 2 deletions test/inflight-and-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { tspl } = require('@matteo.collina/tspl')
const { test } = require('node:test')
const { request } = require('..')
const { request, Agent } = require('..')
const http = require('node:http')

test('inflight and close', async (t) => {
Expand All @@ -14,7 +14,8 @@ test('inflight and close', async (t) => {
res.socket.end() // Close the connection immediately with every response
}).listen(0, '127.0.0.1', function () {
const url = `http://127.0.0.1:${this.address().port}`
request(url)
const dispatcher = new Agent({ pipelining: 1 })
request(url, { dispatcher })
.then(({ statusCode, headers, body }) => {
t.ok(true, 'first response')
body.resume()
Expand Down
3 changes: 3 additions & 0 deletions test/wpt/runner/worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ import {
// TODO(@KhafraDev): export these in index.js
import { Cache } from '../../../lib/web/cache/cache.js'
import { CacheStorage } from '../../../lib/web/cache/cachestorage.js'
import { Agent, setGlobalDispatcher } from '../../../index.js'
import { webcrypto } from 'node:crypto'

const { initScripts, meta, test, url, path } = workerData

setGlobalDispatcher(new Agent({ pipelining: 1 }))

process.on('uncaughtException', (err) => {
parentPort.postMessage({
type: 'error',
Expand Down
Loading