From 84b60e4e46a44fca499e91acbb753f7e980bcc66 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 13 Nov 2023 14:05:38 +1300 Subject: [PATCH 1/5] add benchmark for larger payloads --- .../Busboy_comparison-busboy-Node_20.json | 10 +++++ ...boy_comparison-fastify-busboy-Node_20.json | 10 +++++ .../Busboy_comparison-multipasta-Node_20.json | 10 +++++ benchmarks/busboy/contestants/busboy.js | 18 ++++---- .../busboy/contestants/fastify-busboy.js | 19 ++++---- benchmarks/busboy/contestants/multipasta.js | 37 ++++++++++++++++ benchmarks/busboy/data.js | 43 ++++++++++++++----- benchmarks/busboy/executioner.js | 16 ++++++- benchmarks/busboy/validator.js | 4 +- benchmarks/common/commonBuilder.js | 20 ++++----- benchmarks/package.json | 3 +- package.json | 1 + 12 files changed, 144 insertions(+), 47 deletions(-) create mode 100644 benchmarks/_results/Busboy_comparison-busboy-Node_20.json create mode 100644 benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json create mode 100644 benchmarks/_results/Busboy_comparison-multipasta-Node_20.json create mode 100644 benchmarks/busboy/contestants/multipasta.js diff --git a/benchmarks/_results/Busboy_comparison-busboy-Node_20.json b/benchmarks/_results/Busboy_comparison-busboy-Node_20.json new file mode 100644 index 0000000..46d11bc --- /dev/null +++ b/benchmarks/_results/Busboy_comparison-busboy-Node_20.json @@ -0,0 +1,10 @@ +{ + "runtimeVersion": "20.9.0, V8 11.3.244.8-node.16", + "benchmarkName": "Busboy comparison", + "benchmarkEntryName": "busboy", + "benchmarkCycles": 100, + "benchmarkCycleSamples": 50, + "warmupCycles": 10, + "meanTimeNs": 554046.5630555556, + "meanTimeMs": 0.5540465630555556 +} \ No newline at end of file diff --git a/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json b/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json new file mode 100644 index 0000000..9a4eb67 --- /dev/null +++ b/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json @@ -0,0 +1,10 @@ +{ + "runtimeVersion": "20.9.0, V8 11.3.244.8-node.16", + "benchmarkName": "Busboy comparison", + "benchmarkEntryName": "fastify-busboy", + "benchmarkCycles": 100, + "benchmarkCycleSamples": 50, + "warmupCycles": 10, + "meanTimeNs": 756240.5419444444, + "meanTimeMs": 0.7562405419444445 +} \ No newline at end of file diff --git a/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json b/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json new file mode 100644 index 0000000..e71dc05 --- /dev/null +++ b/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json @@ -0,0 +1,10 @@ +{ + "runtimeVersion": "20.9.0, V8 11.3.244.8-node.16", + "benchmarkName": "Busboy comparison", + "benchmarkEntryName": "multipasta", + "benchmarkCycles": 100, + "benchmarkCycleSamples": 50, + "warmupCycles": 10, + "meanTimeNs": 294519.3063888889, + "meanTimeMs": 0.2945193063888889 +} \ No newline at end of file diff --git a/benchmarks/busboy/contestants/busboy.js b/benchmarks/busboy/contestants/busboy.js index 6cb3414..a72e04b 100644 --- a/benchmarks/busboy/contestants/busboy.js +++ b/benchmarks/busboy/contestants/busboy.js @@ -1,7 +1,7 @@ 'use strict' const Busboy = require('busboy') -const { buffer, boundary } = require('../data') +const { buffers, boundary } = require('../data') function process () { const busboy = Busboy({ @@ -9,27 +9,25 @@ function process () { 'content-type': 'multipart/form-data; boundary=' + boundary } }) - let processedData = '' + let processedSize = 0 return new Promise((resolve, reject) => { busboy.on('file', (field, file, filename, encoding, mimetype) => { - // console.log('read file') file.on('data', (data) => { - processedData += data.toString() - // console.log(`File [${filename}] got ${data.length} bytes`); - }) - file.on('end', (fieldname) => { - // console.log(`File [${fieldname}] Finished`); + processedSize += data.length }) }) + busboy.on('field', (field, value) => { + processedSize += value.length + }) busboy.on('error', function (err) { reject(err) }) busboy.on('finish', function () { - resolve(processedData) + resolve(processedSize) }) - busboy.write(buffer, () => { }) + for (const buffer of buffers) { busboy.write(buffer, () => { }) } busboy.end() }) diff --git a/benchmarks/busboy/contestants/fastify-busboy.js b/benchmarks/busboy/contestants/fastify-busboy.js index 6750f77..376d164 100644 --- a/benchmarks/busboy/contestants/fastify-busboy.js +++ b/benchmarks/busboy/contestants/fastify-busboy.js @@ -1,7 +1,7 @@ 'use strict' const Busboy = require('../../../lib/main') -const { buffer, boundary } = require('../data') +const { buffers, boundary } = require('../data') function process () { const busboy = new Busboy({ @@ -10,27 +10,26 @@ function process () { } }) - let processedData = '' + let processedSize = 0 return new Promise((resolve, reject) => { busboy.on('file', (field, file, filename, encoding, mimetype) => { - // console.log('read file') file.on('data', (data) => { - processedData += data.toString() - // console.log(`File [${filename}] got ${data.length} bytes`); - }) - file.on('end', (fieldname) => { - // console.log(`File [${fieldname}] Finished`); + processedSize += data.length }) }) + busboy.on('field', (field, value) => { + processedSize += value.length + }) busboy.on('error', function (err) { reject(err) }) busboy.on('finish', function () { - resolve(processedData) + resolve(processedSize) }) - busboy.write(buffer, () => { }) + + for (const buffer of buffers) { busboy.write(buffer, () => { }) } busboy.end() }) diff --git a/benchmarks/busboy/contestants/multipasta.js b/benchmarks/busboy/contestants/multipasta.js new file mode 100644 index 0000000..c56e642 --- /dev/null +++ b/benchmarks/busboy/contestants/multipasta.js @@ -0,0 +1,37 @@ +'use strict' + +const MP = require('multipasta') +const { buffers, boundary } = require('../data') + +function process () { + return new Promise((resolve, reject) => { + let processedSize = 0 + const parser = MP.make({ + headers: { + 'content-type': 'multipart/form-data; boundary=' + boundary + }, + onField (_info, value) { + processedSize += value.length + }, + onFile (_info) { + return function (chunk) { + if (chunk !== null) { + processedSize += chunk.length + } + } + }, + onError (err) { + reject(err) + }, + onDone () { + resolve(processedSize) + } + }) + for (const buffer of buffers) { parser.write(buffer) } + parser.end() + }) +} + +module.exports = { + process +} diff --git a/benchmarks/busboy/data.js b/benchmarks/busboy/data.js index 4fdefae..b062ebd 100644 --- a/benchmarks/busboy/data.js +++ b/benchmarks/busboy/data.js @@ -1,8 +1,11 @@ 'use strict' const boundary = '-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k' -const randomContent = Buffer.from(makeString(1024 * 500), 'utf8') -const buffer = createMultipartBuffer(boundary) +const fileContent = Buffer.from(makeString(1024 * 512), 'utf8') +const fileCount = 2 +const fieldContent = Buffer.from(makeString(128), 'utf8') +const fieldCount = 10 +const buffers = createMultipartBuffer(boundary) function makeString (length) { let result = '' @@ -17,18 +20,38 @@ function makeString (length) { function createMultipartBuffer (boundary) { const payload = [ - '--' + boundary, - 'Content-Disposition: form-data; name="upload_file_0"; filename="1k_a.dat"', - 'Content-Type: application/octet-stream', - '', - randomContent, + /* eslint-disable no-array-constructor */ + ...Array.from({ length: fieldCount }, (_, i) => [ + '--' + boundary, + `Content-Disposition: form-data; name="field_${i}"`, + 'Content-Type: application/octet-stream', + '', + fieldContent + ]).flat(), + /* eslint-disable no-array-constructor */ + ...Array.from({ length: fileCount }, (_, i) => [ + '--' + boundary, + `Content-Disposition: form-data; name="file_${i}"; filename="file.dat"`, + 'Content-Type: application/octet-stream', + '', + fileContent + ]).flat(), '--' + boundary + '--' ].join('\r\n') - return Buffer.from(payload, 'ascii') + const buf = Buffer.from(payload, 'ascii') + // split into 1400 byte chunks to simulate network packets + const buffers = [] + for (let i = 0; i < buf.length; i += 1400) { + buffers.push(buf.subarray(i, i + 1400)) + } + return buffers } module.exports = { boundary, - buffer, - randomContent + buffers, + fileContent, + fileCount, + fieldContent, + fieldCount } diff --git a/benchmarks/busboy/executioner.js b/benchmarks/busboy/executioner.js index 524912c..7efcd47 100644 --- a/benchmarks/busboy/executioner.js +++ b/benchmarks/busboy/executioner.js @@ -2,6 +2,7 @@ const { process: processBusboy } = require('./contestants/busboy') const { process: processFastify } = require('./contestants/fastify-busboy') +const { process: processMultipasta } = require('./contestants/multipasta') const { getCommonBuilder } = require('../common/commonBuilder') const { validateAccuracy } = require('./validator') const { resolveContestant } = require('../common/contestantResolver') @@ -9,7 +10,8 @@ const { outputResults } = require('../common/resultUtils') const contestants = { busboy: measureBusboy, - fastify: measureFastify + fastify: measureFastify, + multipasta: measureMultipasta } async function measureBusboy () { @@ -32,6 +34,16 @@ async function measureFastify () { outputResults(benchmark, benchmarkResults) } +async function measureMultipasta () { + const benchmark = getCommonBuilder() + .benchmarkName('Busboy comparison') + .benchmarkEntryName('multipasta') + .asyncFunctionUnderTest(processMultipasta) + .build() + const benchmarkResults = await benchmark.executeAsync() + outputResults(benchmark, benchmarkResults) +} + function execute () { return validateAccuracy(processBusboy()) .then(() => { @@ -43,7 +55,7 @@ function execute () { }).then(() => { console.log('all done') }).catch((err) => { - console.error(`Something went wrong: ${err.message}`) + console.error('Something went wrong', err) }) } diff --git a/benchmarks/busboy/validator.js b/benchmarks/busboy/validator.js index a86cc33..c6512dd 100644 --- a/benchmarks/busboy/validator.js +++ b/benchmarks/busboy/validator.js @@ -1,9 +1,9 @@ 'use strict' const { validateEqual } = require('validation-utils') -const { randomContent } = require('./data') +const { fileContent, fileCount, fieldContent, fieldCount } = require('./data') -const EXPECTED_RESULT = randomContent.toString() +const EXPECTED_RESULT = (fileContent.length * fileCount) + (fieldContent.length * fieldCount) async function validateAccuracy (actualResultPromise) { const result = await actualResultPromise diff --git a/benchmarks/common/commonBuilder.js b/benchmarks/common/commonBuilder.js index b5707aa..3f143d2 100644 --- a/benchmarks/common/commonBuilder.js +++ b/benchmarks/common/commonBuilder.js @@ -13,32 +13,28 @@ const options = getopts(process.argv.slice(1), { const PRESET = { LOW: (builder) => { - return builder - .warmupCycles(1000) - .benchmarkCycles(1000) + return builder.warmupCycles(5).benchmarkCycles(50) }, MEDIUM: (builder) => { - return builder - .warmupCycles(1000) - .benchmarkCycles(2000) + return builder.warmupCycles(10).benchmarkCycles(100) }, HIGH: (builder) => { - return builder - .warmupCycles(1000) - .benchmarkCycles(10000) + return builder.warmupCycles(50).benchmarkCycles(500) } } function getCommonBuilder () { const presetId = options.preset || 'MEDIUM' - const preset = validateNotNil(PRESET[presetId.toUpperCase()], `Unknown preset: ${presetId}`) + const preset = validateNotNil( + PRESET[presetId.toUpperCase()], + `Unknown preset: ${presetId}` + ) const builder = new BenchmarkBuilder() preset(builder) - return builder - .benchmarkCycleSamples(50) + return builder.benchmarkCycleSamples(50) } module.exports = { diff --git a/benchmarks/package.json b/benchmarks/package.json index 2574b8b..b377639 100644 --- a/benchmarks/package.json +++ b/benchmarks/package.json @@ -13,7 +13,8 @@ "install-node": "nvm install 17.2.0 && nvm install 16.13.1 && nvm install 14.18.2 && nvm install 12.22.7", "benchmark-busboy": "node busboy/executioner.js -c 0", "benchmark-fastify": "node busboy/executioner.js -c 1", - "benchmark-all": "npm run benchmark-busboy -- -p high && npm run benchmark-fastify -- -p high", + "benchmark-multipasta": "node busboy/executioner.js -c 2", + "benchmark-all": "npm run benchmark-busboy -- -p high && npm run benchmark-fastify -- -p high && npm run benchmark-multipasta -- -p high", "benchmark-all-medium": "npm run benchmark-busboy -- -p medium && npm run benchmark-fastify -- -p medium", "benchmark-all-low": "npm run benchmark-busboy -- -p low && npm run benchmark-fastify -- -p low", "combine-results": "node common/resultsCombinator.js -r _results -p 6" diff --git a/package.json b/package.json index 4be895c..4d81ce1 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "devDependencies": { "@types/node": "^20.1.0", "busboy": "^1.0.0", + "multipasta": "^0.1.11", "photofinish": "^1.8.0", "snazzy": "^9.0.0", "standard": "^17.0.0", From 5debaf6f45b3563f1fea8adacfec61eb59e5807f Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 13 Nov 2023 14:11:16 +1300 Subject: [PATCH 2/5] update results --- benchmarks/_results/Busboy_comparison-busboy-Node_20.json | 8 ++++---- .../Busboy_comparison-fastify-busboy-Node_20.json | 8 ++++---- .../_results/Busboy_comparison-multipasta-Node_20.json | 8 ++++---- benchmarks/_results/results.md | 7 +++++++ benchmarks/package.json | 4 ++-- 5 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 benchmarks/_results/results.md diff --git a/benchmarks/_results/Busboy_comparison-busboy-Node_20.json b/benchmarks/_results/Busboy_comparison-busboy-Node_20.json index 46d11bc..b5ff871 100644 --- a/benchmarks/_results/Busboy_comparison-busboy-Node_20.json +++ b/benchmarks/_results/Busboy_comparison-busboy-Node_20.json @@ -2,9 +2,9 @@ "runtimeVersion": "20.9.0, V8 11.3.244.8-node.16", "benchmarkName": "Busboy comparison", "benchmarkEntryName": "busboy", - "benchmarkCycles": 100, + "benchmarkCycles": 500, "benchmarkCycleSamples": 50, - "warmupCycles": 10, - "meanTimeNs": 554046.5630555556, - "meanTimeMs": 0.5540465630555556 + "warmupCycles": 50, + "meanTimeNs": 566429.1632040885, + "meanTimeMs": 0.5664291632040884 } \ No newline at end of file diff --git a/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json b/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json index 9a4eb67..bc41df5 100644 --- a/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json +++ b/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json @@ -2,9 +2,9 @@ "runtimeVersion": "20.9.0, V8 11.3.244.8-node.16", "benchmarkName": "Busboy comparison", "benchmarkEntryName": "fastify-busboy", - "benchmarkCycles": 100, + "benchmarkCycles": 500, "benchmarkCycleSamples": 50, - "warmupCycles": 10, - "meanTimeNs": 756240.5419444444, - "meanTimeMs": 0.7562405419444445 + "warmupCycles": 50, + "meanTimeNs": 750653.2907616243, + "meanTimeMs": 0.7506532907616243 } \ No newline at end of file diff --git a/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json b/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json index e71dc05..46ec07c 100644 --- a/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json +++ b/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json @@ -2,9 +2,9 @@ "runtimeVersion": "20.9.0, V8 11.3.244.8-node.16", "benchmarkName": "Busboy comparison", "benchmarkEntryName": "multipasta", - "benchmarkCycles": 100, + "benchmarkCycles": 500, "benchmarkCycleSamples": 50, - "warmupCycles": 10, - "meanTimeNs": 294519.3063888889, - "meanTimeMs": 0.2945193063888889 + "warmupCycles": 50, + "meanTimeNs": 287651.0216099106, + "meanTimeMs": 0.2876510216099106 } \ No newline at end of file diff --git a/benchmarks/_results/results.md b/benchmarks/_results/results.md new file mode 100644 index 0000000..320d32b --- /dev/null +++ b/benchmarks/_results/results.md @@ -0,0 +1,7 @@ +| Node | Option | Msecs/op | Ops/sec | V8 | +| ------ | -------------- | -------------- | -------- | --------------------- | +| 20.9.0 | multipasta | 0.287651 msecs | 3476.435 | V8 11.3.244.8-node.16 | +| 20.9.0 | busboy | 0.566429 msecs | 1765.446 | V8 11.3.244.8-node.16 | +| 20.9.0 | fastify-busboy | 0.750653 msecs | 1332.173 | V8 11.3.244.8-node.16 | + +**Specs**: Core™ i9-9880H (2.3 GHz) diff --git a/benchmarks/package.json b/benchmarks/package.json index b377639..21aa0aa 100644 --- a/benchmarks/package.json +++ b/benchmarks/package.json @@ -15,8 +15,8 @@ "benchmark-fastify": "node busboy/executioner.js -c 1", "benchmark-multipasta": "node busboy/executioner.js -c 2", "benchmark-all": "npm run benchmark-busboy -- -p high && npm run benchmark-fastify -- -p high && npm run benchmark-multipasta -- -p high", - "benchmark-all-medium": "npm run benchmark-busboy -- -p medium && npm run benchmark-fastify -- -p medium", - "benchmark-all-low": "npm run benchmark-busboy -- -p low && npm run benchmark-fastify -- -p low", + "benchmark-all-medium": "npm run benchmark-busboy -- -p medium && npm run benchmark-fastify -- -p medium && npm run benchmark-multipasta -- -p medium", + "benchmark-all-low": "npm run benchmark-busboy -- -p low && npm run benchmark-fastify -- -p low && npm run benchmark-multipasta -- -p low", "combine-results": "node common/resultsCombinator.js -r _results -p 6" } } From a12c3ec698e93571b9a612917e3b679eb79df9ff Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 13 Nov 2023 14:28:07 +1300 Subject: [PATCH 3/5] increase chunk size --- benchmarks/_results/Busboy_comparison-busboy-Node_20.json | 4 ++-- .../_results/Busboy_comparison-fastify-busboy-Node_20.json | 4 ++-- .../_results/Busboy_comparison-multipasta-Node_20.json | 4 ++-- benchmarks/busboy/data.js | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/benchmarks/_results/Busboy_comparison-busboy-Node_20.json b/benchmarks/_results/Busboy_comparison-busboy-Node_20.json index b5ff871..aa7afd0 100644 --- a/benchmarks/_results/Busboy_comparison-busboy-Node_20.json +++ b/benchmarks/_results/Busboy_comparison-busboy-Node_20.json @@ -5,6 +5,6 @@ "benchmarkCycles": 500, "benchmarkCycleSamples": 50, "warmupCycles": 50, - "meanTimeNs": 566429.1632040885, - "meanTimeMs": 0.5664291632040884 + "meanTimeNs": 277264.27034383157, + "meanTimeMs": 0.27726427034383155 } \ No newline at end of file diff --git a/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json b/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json index bc41df5..e721fc2 100644 --- a/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json +++ b/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json @@ -5,6 +5,6 @@ "benchmarkCycles": 500, "benchmarkCycleSamples": 50, "warmupCycles": 50, - "meanTimeNs": 750653.2907616243, - "meanTimeMs": 0.7506532907616243 + "meanTimeNs": 189956.0127756485, + "meanTimeMs": 0.1899560127756485 } \ No newline at end of file diff --git a/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json b/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json index 46ec07c..1f837bd 100644 --- a/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json +++ b/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json @@ -5,6 +5,6 @@ "benchmarkCycles": 500, "benchmarkCycleSamples": 50, "warmupCycles": 50, - "meanTimeNs": 287651.0216099106, - "meanTimeMs": 0.2876510216099106 + "meanTimeNs": 246957.7862022996, + "meanTimeMs": 0.2469577862022996 } \ No newline at end of file diff --git a/benchmarks/busboy/data.js b/benchmarks/busboy/data.js index b062ebd..44c4e72 100644 --- a/benchmarks/busboy/data.js +++ b/benchmarks/busboy/data.js @@ -39,10 +39,10 @@ function createMultipartBuffer (boundary) { '--' + boundary + '--' ].join('\r\n') const buf = Buffer.from(payload, 'ascii') - // split into 1400 byte chunks to simulate network packets + // split into 16000 byte chunks to simulate network packets const buffers = [] - for (let i = 0; i < buf.length; i += 1400) { - buffers.push(buf.subarray(i, i + 1400)) + for (let i = 0; i < buf.length; i += 16000) { + buffers.push(buf.subarray(i, i + 16000)) } return buffers } From b2b9de5663b17b9540dca38c08ab1015fd035d50 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 15 Nov 2023 09:41:15 +1300 Subject: [PATCH 4/5] update multipasta --- .../_results/Busboy_comparison-busboy-Node_12.json | 10 ---------- .../_results/Busboy_comparison-busboy-Node_16.json | 10 ---------- .../_results/Busboy_comparison-busboy-Node_20.json | 4 ++-- .../Busboy_comparison-fastify-busboy-Node_16.json | 10 ---------- .../Busboy_comparison-fastify-busboy-Node_20.json | 4 ++-- .../Busboy_comparison-multipasta-Node_20.json | 4 ++-- benchmarks/_results/results.md | 12 ++++++------ package.json | 2 +- 8 files changed, 13 insertions(+), 43 deletions(-) delete mode 100644 benchmarks/_results/Busboy_comparison-busboy-Node_12.json delete mode 100644 benchmarks/_results/Busboy_comparison-busboy-Node_16.json delete mode 100644 benchmarks/_results/Busboy_comparison-fastify-busboy-Node_16.json diff --git a/benchmarks/_results/Busboy_comparison-busboy-Node_12.json b/benchmarks/_results/Busboy_comparison-busboy-Node_12.json deleted file mode 100644 index 69468dd..0000000 --- a/benchmarks/_results/Busboy_comparison-busboy-Node_12.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "runtimeVersion": "12.22.7, V8 7.8.279.23-node.56", - "benchmarkName": "Busboy comparison", - "benchmarkEntryName": "busboy", - "benchmarkCycles": 10, - "benchmarkCycleSamples": 50, - "warmupCycles": 10, - "meanTimeNs": 1945927.3472222222, - "meanTimeMs": 1.9459273472222223 -} \ No newline at end of file diff --git a/benchmarks/_results/Busboy_comparison-busboy-Node_16.json b/benchmarks/_results/Busboy_comparison-busboy-Node_16.json deleted file mode 100644 index b4c492a..0000000 --- a/benchmarks/_results/Busboy_comparison-busboy-Node_16.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "runtimeVersion": "16.13.0, V8 9.4.146.19-node.13", - "benchmarkName": "Busboy comparison", - "benchmarkEntryName": "busboy", - "benchmarkCycles": 2000, - "benchmarkCycleSamples": 50, - "warmupCycles": 1000, - "meanTimeNs": 340114.0411908194, - "meanTimeMs": 0.3401140411908194 -} \ No newline at end of file diff --git a/benchmarks/_results/Busboy_comparison-busboy-Node_20.json b/benchmarks/_results/Busboy_comparison-busboy-Node_20.json index aa7afd0..2b5808f 100644 --- a/benchmarks/_results/Busboy_comparison-busboy-Node_20.json +++ b/benchmarks/_results/Busboy_comparison-busboy-Node_20.json @@ -5,6 +5,6 @@ "benchmarkCycles": 500, "benchmarkCycleSamples": 50, "warmupCycles": 50, - "meanTimeNs": 277264.27034383157, - "meanTimeMs": 0.27726427034383155 + "meanTimeNs": 271603.6766274161, + "meanTimeMs": 0.2716036766274161 } \ No newline at end of file diff --git a/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_16.json b/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_16.json deleted file mode 100644 index 30f5d1e..0000000 --- a/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_16.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "runtimeVersion": "16.13.0, V8 9.4.146.19-node.13", - "benchmarkName": "Busboy comparison", - "benchmarkEntryName": "fastify-busboy", - "benchmarkCycles": 2000, - "benchmarkCycleSamples": 50, - "warmupCycles": 1000, - "meanTimeNs": 270984.48082281026, - "meanTimeMs": 0.27098448082281024 -} \ No newline at end of file diff --git a/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json b/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json index e721fc2..912aaf7 100644 --- a/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json +++ b/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json @@ -5,6 +5,6 @@ "benchmarkCycles": 500, "benchmarkCycleSamples": 50, "warmupCycles": 50, - "meanTimeNs": 189956.0127756485, - "meanTimeMs": 0.1899560127756485 + "meanTimeNs": 192632.5067214754, + "meanTimeMs": 0.1926325067214754 } \ No newline at end of file diff --git a/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json b/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json index 1f837bd..f7efc1a 100644 --- a/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json +++ b/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json @@ -5,6 +5,6 @@ "benchmarkCycles": 500, "benchmarkCycleSamples": 50, "warmupCycles": 50, - "meanTimeNs": 246957.7862022996, - "meanTimeMs": 0.2469577862022996 + "meanTimeNs": 79651.12307008775, + "meanTimeMs": 0.07965112307008775 } \ No newline at end of file diff --git a/benchmarks/_results/results.md b/benchmarks/_results/results.md index 320d32b..31b684a 100644 --- a/benchmarks/_results/results.md +++ b/benchmarks/_results/results.md @@ -1,7 +1,7 @@ -| Node | Option | Msecs/op | Ops/sec | V8 | -| ------ | -------------- | -------------- | -------- | --------------------- | -| 20.9.0 | multipasta | 0.287651 msecs | 3476.435 | V8 11.3.244.8-node.16 | -| 20.9.0 | busboy | 0.566429 msecs | 1765.446 | V8 11.3.244.8-node.16 | -| 20.9.0 | fastify-busboy | 0.750653 msecs | 1332.173 | V8 11.3.244.8-node.16 | +| Node | Option | Msecs/op | Ops/sec | V8 | +| ------ | -------------- | -------------- | --------- | --------------------- | +| 20.9.0 | multipasta | 0.079651 msecs | 12554.751 | V8 11.3.244.8-node.16 | +| 20.9.0 | fastify-busboy | 0.192633 msecs | 5191.232 | V8 11.3.244.8-node.16 | +| 20.9.0 | busboy | 0.271604 msecs | 3681.835 | V8 11.3.244.8-node.16 | -**Specs**: Core™ i9-9880H (2.3 GHz) +**Specs**: Core™ i9-9880H (2.3 GHz) \ No newline at end of file diff --git a/package.json b/package.json index 4d81ce1..f1cdc7e 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "devDependencies": { "@types/node": "^20.1.0", "busboy": "^1.0.0", - "multipasta": "^0.1.11", + "multipasta": "^0.1.12", "photofinish": "^1.8.0", "snazzy": "^9.0.0", "standard": "^17.0.0", From c4f8ab5501311f5c98f071d8fade23bae55ac738 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 15 Nov 2023 09:48:18 +1300 Subject: [PATCH 5/5] add part count validation --- benchmarks/_results/Busboy_comparison-busboy-Node_20.json | 4 ++-- .../_results/Busboy_comparison-fastify-busboy-Node_20.json | 4 ++-- .../_results/Busboy_comparison-multipasta-Node_20.json | 4 ++-- benchmarks/_results/results.md | 6 +++--- benchmarks/busboy/contestants/busboy.js | 5 ++++- benchmarks/busboy/contestants/fastify-busboy.js | 5 ++++- benchmarks/busboy/contestants/multipasta.js | 5 ++++- benchmarks/busboy/data.js | 6 ++++-- benchmarks/busboy/validator.js | 3 ++- package.json | 2 +- 10 files changed, 28 insertions(+), 16 deletions(-) diff --git a/benchmarks/_results/Busboy_comparison-busboy-Node_20.json b/benchmarks/_results/Busboy_comparison-busboy-Node_20.json index 2b5808f..16d8a5b 100644 --- a/benchmarks/_results/Busboy_comparison-busboy-Node_20.json +++ b/benchmarks/_results/Busboy_comparison-busboy-Node_20.json @@ -5,6 +5,6 @@ "benchmarkCycles": 500, "benchmarkCycleSamples": 50, "warmupCycles": 50, - "meanTimeNs": 271603.6766274161, - "meanTimeMs": 0.2716036766274161 + "meanTimeNs": 259789.77117937893, + "meanTimeMs": 0.25978977117937896 } \ No newline at end of file diff --git a/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json b/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json index 912aaf7..fa22c30 100644 --- a/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json +++ b/benchmarks/_results/Busboy_comparison-fastify-busboy-Node_20.json @@ -5,6 +5,6 @@ "benchmarkCycles": 500, "benchmarkCycleSamples": 50, "warmupCycles": 50, - "meanTimeNs": 192632.5067214754, - "meanTimeMs": 0.1926325067214754 + "meanTimeNs": 188173.65372222223, + "meanTimeMs": 0.18817365372222222 } \ No newline at end of file diff --git a/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json b/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json index f7efc1a..80d3d7b 100644 --- a/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json +++ b/benchmarks/_results/Busboy_comparison-multipasta-Node_20.json @@ -5,6 +5,6 @@ "benchmarkCycles": 500, "benchmarkCycleSamples": 50, "warmupCycles": 50, - "meanTimeNs": 79651.12307008775, - "meanTimeMs": 0.07965112307008775 + "meanTimeNs": 67089.49805620349, + "meanTimeMs": 0.0670894980562035 } \ No newline at end of file diff --git a/benchmarks/_results/results.md b/benchmarks/_results/results.md index 31b684a..8a059e4 100644 --- a/benchmarks/_results/results.md +++ b/benchmarks/_results/results.md @@ -1,7 +1,7 @@ | Node | Option | Msecs/op | Ops/sec | V8 | | ------ | -------------- | -------------- | --------- | --------------------- | -| 20.9.0 | multipasta | 0.079651 msecs | 12554.751 | V8 11.3.244.8-node.16 | -| 20.9.0 | fastify-busboy | 0.192633 msecs | 5191.232 | V8 11.3.244.8-node.16 | -| 20.9.0 | busboy | 0.271604 msecs | 3681.835 | V8 11.3.244.8-node.16 | +| 20.9.0 | multipasta | 0.067089 msecs | 14905.463 | V8 11.3.244.8-node.16 | +| 20.9.0 | fastify-busboy | 0.188174 msecs | 5314.240 | V8 11.3.244.8-node.16 | +| 20.9.0 | busboy | 0.259790 msecs | 3849.266 | V8 11.3.244.8-node.16 | **Specs**: Core™ i9-9880H (2.3 GHz) \ No newline at end of file diff --git a/benchmarks/busboy/contestants/busboy.js b/benchmarks/busboy/contestants/busboy.js index a72e04b..130496c 100644 --- a/benchmarks/busboy/contestants/busboy.js +++ b/benchmarks/busboy/contestants/busboy.js @@ -10,22 +10,25 @@ function process () { } }) let processedSize = 0 + let partCount = 0 return new Promise((resolve, reject) => { busboy.on('file', (field, file, filename, encoding, mimetype) => { + partCount++ file.on('data', (data) => { processedSize += data.length }) }) busboy.on('field', (field, value) => { processedSize += value.length + partCount++ }) busboy.on('error', function (err) { reject(err) }) busboy.on('finish', function () { - resolve(processedSize) + resolve([processedSize, partCount]) }) for (const buffer of buffers) { busboy.write(buffer, () => { }) } diff --git a/benchmarks/busboy/contestants/fastify-busboy.js b/benchmarks/busboy/contestants/fastify-busboy.js index 376d164..64be2a8 100644 --- a/benchmarks/busboy/contestants/fastify-busboy.js +++ b/benchmarks/busboy/contestants/fastify-busboy.js @@ -11,22 +11,25 @@ function process () { }) let processedSize = 0 + let partCount = 0 return new Promise((resolve, reject) => { busboy.on('file', (field, file, filename, encoding, mimetype) => { + partCount++ file.on('data', (data) => { processedSize += data.length }) }) busboy.on('field', (field, value) => { processedSize += value.length + partCount++ }) busboy.on('error', function (err) { reject(err) }) busboy.on('finish', function () { - resolve(processedSize) + resolve([processedSize, partCount]) }) for (const buffer of buffers) { busboy.write(buffer, () => { }) } diff --git a/benchmarks/busboy/contestants/multipasta.js b/benchmarks/busboy/contestants/multipasta.js index c56e642..d0e2866 100644 --- a/benchmarks/busboy/contestants/multipasta.js +++ b/benchmarks/busboy/contestants/multipasta.js @@ -6,14 +6,17 @@ const { buffers, boundary } = require('../data') function process () { return new Promise((resolve, reject) => { let processedSize = 0 + let partCount = 0 const parser = MP.make({ headers: { 'content-type': 'multipart/form-data; boundary=' + boundary }, onField (_info, value) { processedSize += value.length + partCount++ }, onFile (_info) { + partCount++ return function (chunk) { if (chunk !== null) { processedSize += chunk.length @@ -24,7 +27,7 @@ function process () { reject(err) }, onDone () { - resolve(processedSize) + resolve([processedSize, partCount]) } }) for (const buffer of buffers) { parser.write(buffer) } diff --git a/benchmarks/busboy/data.js b/benchmarks/busboy/data.js index 44c4e72..3a8ac15 100644 --- a/benchmarks/busboy/data.js +++ b/benchmarks/busboy/data.js @@ -5,6 +5,8 @@ const fileContent = Buffer.from(makeString(1024 * 512), 'utf8') const fileCount = 2 const fieldContent = Buffer.from(makeString(128), 'utf8') const fieldCount = 10 +const chunkSize = 16000 + const buffers = createMultipartBuffer(boundary) function makeString (length) { @@ -41,8 +43,8 @@ function createMultipartBuffer (boundary) { const buf = Buffer.from(payload, 'ascii') // split into 16000 byte chunks to simulate network packets const buffers = [] - for (let i = 0; i < buf.length; i += 16000) { - buffers.push(buf.subarray(i, i + 16000)) + for (let i = 0; i < buf.length; i += chunkSize) { + buffers.push(buf.subarray(i, i + chunkSize)) } return buffers } diff --git a/benchmarks/busboy/validator.js b/benchmarks/busboy/validator.js index c6512dd..19953b4 100644 --- a/benchmarks/busboy/validator.js +++ b/benchmarks/busboy/validator.js @@ -6,8 +6,9 @@ const { fileContent, fileCount, fieldContent, fieldCount } = require('./data') const EXPECTED_RESULT = (fileContent.length * fileCount) + (fieldContent.length * fieldCount) async function validateAccuracy (actualResultPromise) { - const result = await actualResultPromise + const [result, parts] = await actualResultPromise validateEqual(result, EXPECTED_RESULT) + validateEqual(parts, fileCount + fieldCount) } module.exports = { diff --git a/package.json b/package.json index f1cdc7e..8711ce0 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "devDependencies": { "@types/node": "^20.1.0", "busboy": "^1.0.0", - "multipasta": "^0.1.12", + "multipasta": "^0.1.15", "photofinish": "^1.8.0", "snazzy": "^9.0.0", "standard": "^17.0.0",