Skip to content
Open
Changes from all 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
15 changes: 8 additions & 7 deletions benchmarks/src/metrics.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'node:fs'
import { Transform } from 'node:stream'
import { Readable } from 'node:stream'
import { monitorEventLoopDelay } from 'node:perf_hooks'

/**
Expand Down Expand Up @@ -66,12 +66,13 @@ export const countS3Ops = (plugin, counters) => {
client.getObject = async (...args) => {
counters.gets++
const stream = await get(...args)
// count through a Transform rather than a 'data' listener: a listener would
// put the stream into flowing mode and race the caller's `for await`
const counting = new Transform({
transform (chunk, _enc, cb) { counters.getBytes += chunk.length; cb(null, chunk) }
})
return stream.pipe(counting)
const counted = async function * () {
for await (const chunk of stream) {
counters.getBytes += chunk.length
yield chunk
}
}
return Readable.from(counted())
}
/** @param {any[]} args */
client.removeObject = (...args) => {
Expand Down