Skip to content

Commit 071609f

Browse files
authored
feat: add sending data benchmark (#2905)
* feat: add post benchmark * fixup * apply suggestions from code review * apply suggestions from code review
1 parent 2505e42 commit 071609f

File tree

4 files changed

+478
-11
lines changed

4 files changed

+478
-11
lines changed

.github/workflows/bench.yml

+43
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,46 @@ jobs:
4949
- name: Run Benchmark
5050
run: npm run bench
5151
working-directory: ./benchmarks
52+
53+
benchmark_post_current:
54+
name: benchmark (sending data) current
55+
runs-on: ubuntu-latest
56+
steps:
57+
- name: Checkout Code
58+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
59+
with:
60+
persist-credentials: false
61+
ref: ${{ github.base_ref }}
62+
- name: Setup Node
63+
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
64+
with:
65+
node-version: lts/*
66+
- name: Install Modules for undici
67+
run: npm i --ignore-scripts --omit=dev
68+
- name: Install Modules for Benchmarks
69+
run: npm i
70+
working-directory: ./benchmarks
71+
- name: Run Benchmark
72+
run: npm run bench-post
73+
working-directory: ./benchmarks
74+
75+
benchmark_post_branch:
76+
name: benchmark (sending data) branch
77+
runs-on: ubuntu-latest
78+
steps:
79+
- name: Checkout Code
80+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
81+
with:
82+
persist-credentials: false
83+
- name: Setup Node
84+
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
85+
with:
86+
node-version: lts/*
87+
- name: Install Modules for undici
88+
run: npm i --ignore-scripts --omit=dev
89+
- name: Install Modules for Benchmarks
90+
run: npm i
91+
working-directory: ./benchmarks
92+
- name: Run Benchmark
93+
run: npm run bench-post
94+
working-directory: ./benchmarks

benchmarks/benchmark.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,16 @@ if (process.env.PORT) {
3434
dest.socketPath = path.join(os.tmpdir(), 'undici.sock')
3535
}
3636

37+
/** @type {http.RequestOptions} */
3738
const httpBaseOptions = {
3839
protocol: 'http:',
3940
hostname: 'localhost',
4041
method: 'GET',
4142
path: '/',
42-
query: {
43-
frappucino: 'muffin',
44-
goat: 'scone',
45-
pond: 'moose',
46-
foo: ['bar', 'baz', 'bal'],
47-
bool: true,
48-
numberKey: 256
49-
},
5043
...dest
5144
}
5245

46+
/** @type {http.RequestOptions} */
5347
const httpNoKeepAliveOptions = {
5448
...httpBaseOptions,
5549
agent: new http.Agent({
@@ -58,6 +52,7 @@ const httpNoKeepAliveOptions = {
5852
})
5953
}
6054

55+
/** @type {http.RequestOptions} */
6156
const httpKeepAliveOptions = {
6257
...httpBaseOptions,
6358
agent: new http.Agent({
@@ -142,7 +137,11 @@ class SimpleRequest {
142137
}
143138

144139
function makeParallelRequests (cb) {
145-
return Promise.all(Array.from(Array(parallelRequests)).map(() => new Promise(cb)))
140+
const promises = new Array(parallelRequests)
141+
for (let i = 0; i < parallelRequests; ++i) {
142+
promises[i] = new Promise(cb)
143+
}
144+
return Promise.all(promises)
146145
}
147146

148147
function printResults (results) {
@@ -303,7 +302,7 @@ if (process.env.PORT) {
303302

304303
experiments.got = () => {
305304
return makeParallelRequests(resolve => {
306-
got.get(dest.url, null, { http: gotAgent }).then(res => {
305+
got.get(dest.url, { agent: { http: gotAgent } }).then(res => {
307306
res.pipe(new Writable({
308307
write (chunk, encoding, callback) {
309308
callback()

benchmarks/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
"name": "benchmarks",
33
"scripts": {
44
"bench": "PORT=3042 concurrently -k -s first npm:bench:server npm:bench:run",
5+
"bench-post": "PORT=3042 concurrently -k -s first npm:bench:server npm:bench-post:run",
56
"bench:server": "node ./server.js",
67
"prebench:run": "node ./wait.js",
7-
"bench:run": "SAMPLES=100 CONNECTIONS=50 node ./benchmark.js"
8+
"bench:run": "SAMPLES=100 CONNECTIONS=50 node ./benchmark.js",
9+
"prebench-post:run": "node ./wait.js",
10+
"bench-post:run": "SAMPLES=100 CONNECTIONS=50 node ./post-benchmark.js"
811
},
912
"dependencies": {
1013
"axios": "^1.6.7",

0 commit comments

Comments
 (0)