From a8a0a32d3a48588146ffd5059337eaf5fb7769ba Mon Sep 17 00:00:00 2001 From: tsctx <91457664+tsctx@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:41:16 +0900 Subject: [PATCH 1/4] fix(benchmark): set body correctly --- benchmarks/post-benchmark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/post-benchmark.js b/benchmarks/post-benchmark.js index 829fc389476..36952e4ccaa 100644 --- a/benchmarks/post-benchmark.js +++ b/benchmarks/post-benchmark.js @@ -357,7 +357,7 @@ if (process.env.PORT) { method: 'POST', headers, agent: requestAgent, - data + body: data } experiments.request = () => { return makeParallelRequests(resolve => { From 906fec9743dbc4853ba118bbd29192ec49408077 Mon Sep 17 00:00:00 2001 From: tsctx <91457664+tsctx@users.noreply.github.com> Date: Mon, 4 Mar 2024 17:28:35 +0900 Subject: [PATCH 2/4] fix: `undici.pipeline` set body correctly --- benchmarks/post-benchmark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/post-benchmark.js b/benchmarks/post-benchmark.js index 36952e4ccaa..d5606a1ecb5 100644 --- a/benchmarks/post-benchmark.js +++ b/benchmarks/post-benchmark.js @@ -234,7 +234,7 @@ const experiments = { .pipeline(undiciOptions, data => { return data.body }) - .end() + .end(data) .pipe( new Writable({ write (chunk, encoding, callback) { From bdb5978b7bfd40f84ca4dd5766a16305c673ae01 Mon Sep 17 00:00:00 2001 From: tsctx <91457664+tsctx@users.noreply.github.com> Date: Mon, 4 Mar 2024 18:03:54 +0900 Subject: [PATCH 3/4] fix: maybe fix `undici.pipeline` --- benchmarks/post-benchmark.js | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/benchmarks/post-benchmark.js b/benchmarks/post-benchmark.js index d5606a1ecb5..040fcc8ae70 100644 --- a/benchmarks/post-benchmark.js +++ b/benchmarks/post-benchmark.js @@ -3,9 +3,8 @@ const http = require('node:http') const os = require('node:os') const path = require('node:path') -const { Writable } = require('node:stream') +const { Writable, Readable, pipeline } = require('node:stream') const { isMainThread } = require('node:worker_threads') - const { Pool, Client, fetch, Agent, setGlobalDispatcher } = require('..') let nodeFetch @@ -230,19 +229,28 @@ const experiments = { }, 'undici - pipeline' () { return makeParallelRequests(resolve => { - dispatcher - .pipeline(undiciOptions, data => { + pipeline( + new Readable({ + read () { + this.push(data) + this.push(null) + } + }), + dispatcher.pipeline(undiciOptions, data => { return data.body - }) - .end(data) - .pipe( - new Writable({ - write (chunk, encoding, callback) { - callback() - } - }) - ) - .on('finish', resolve) + }), + new Writable({ + write (chunk, encoding, callback) { + callback() + } + }), + (err) => { + if (err !== null) { + console.log(err) + } + resolve() + } + ) }) }, 'undici - request' () { From d8c1f1301a08c9b036fdcb13a57a2b6aa4806cc7 Mon Sep 17 00:00:00 2001 From: tsctx <91457664+tsctx@users.noreply.github.com> Date: Mon, 4 Mar 2024 18:07:00 +0900 Subject: [PATCH 4/4] fixup --- benchmarks/post-benchmark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/post-benchmark.js b/benchmarks/post-benchmark.js index 040fcc8ae70..80c23a67b92 100644 --- a/benchmarks/post-benchmark.js +++ b/benchmarks/post-benchmark.js @@ -245,7 +245,7 @@ const experiments = { } }), (err) => { - if (err !== null) { + if (err != null) { console.log(err) } resolve()