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

feat: add sending data benchmark #2905

Merged
merged 4 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
43 changes: 43 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,46 @@ jobs:
- name: Run Benchmark
run: npm run bench
working-directory: ./benchmarks

benchmark_post_current:
name: post benchmark current
tsctx marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
persist-credentials: false
ref: ${{ github.base_ref }}
- name: Setup Node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: lts/*
- name: Install Modules for undici
run: npm i --ignore-scripts --omit=dev
- name: Install Modules for Benchmarks
run: npm i
working-directory: ./benchmarks
- name: Run Benchmark
run: npm run bench-post
working-directory: ./benchmarks

benchmark_post_branch:
name: post benchmark branch
tsctx marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
persist-credentials: false
- name: Setup Node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: lts/*
- name: Install Modules for undici
run: npm i --ignore-scripts --omit=dev
- name: Install Modules for Benchmarks
run: npm i
working-directory: ./benchmarks
- name: Run Benchmark
run: npm run bench-post
working-directory: ./benchmarks
19 changes: 9 additions & 10 deletions benchmarks/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,16 @@ if (process.env.PORT) {
dest.socketPath = path.join(os.tmpdir(), 'undici.sock')
}

/** @type {http.RequestOptions} */
const httpBaseOptions = {
protocol: 'http:',
hostname: 'localhost',
method: 'GET',
path: '/',
query: {
frappucino: 'muffin',
goat: 'scone',
pond: 'moose',
foo: ['bar', 'baz', 'bal'],
bool: true,
numberKey: 256
},
Comment on lines -42 to -49
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an invalid option and is not used.

...dest
}

/** @type {http.RequestOptions} */
const httpNoKeepAliveOptions = {
...httpBaseOptions,
agent: new http.Agent({
Expand All @@ -58,6 +52,7 @@ const httpNoKeepAliveOptions = {
})
}

/** @type {http.RequestOptions} */
const httpKeepAliveOptions = {
...httpBaseOptions,
agent: new http.Agent({
Expand Down Expand Up @@ -142,7 +137,11 @@ class SimpleRequest {
}

function makeParallelRequests (cb) {
return Promise.all(Array.from(Array(parallelRequests)).map(() => new Promise(cb)))
const promises = new Array(parallelRequests)
for (let i = 0; i < parallelRequests; ++i) {
promises[i] = new Promise(cb)
}
return Promise.all(promises)
Comment on lines +140 to +144
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reduce overhead

}

function printResults (results) {
Expand Down Expand Up @@ -303,7 +302,7 @@ if (process.env.PORT) {

experiments.got = () => {
return makeParallelRequests(resolve => {
got.get(dest.url, null, { http: gotAgent }).then(res => {
got.get(dest.url, { agent: { http: gotAgent } }).then(res => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The agent is not configured correctly.

res.pipe(new Writable({
write (chunk, encoding, callback) {
callback()
Expand Down
5 changes: 4 additions & 1 deletion benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
"name": "benchmarks",
"scripts": {
"bench": "PORT=3042 concurrently -k -s first npm:bench:server npm:bench:run",
"bench-post": "PORT=3042 concurrently -k -s first npm:bench:server npm:bench-post:run",
"bench:server": "node ./server.js",
"prebench:run": "node ./wait.js",
"bench:run": "SAMPLES=100 CONNECTIONS=50 node ./benchmark.js"
"bench:run": "SAMPLES=100 CONNECTIONS=50 node ./benchmark.js",
"prebench-post:run": "node ./wait.js",
"bench-post:run": "SAMPLES=100 CONNECTIONS=50 node ./post-benchmark.js"
},
"dependencies": {
"axios": "^1.6.7",
Expand Down
Loading
Loading