Skip to content

Commit

Permalink
chore: add more perf logs
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Nov 17, 2023
1 parent 3e621f3 commit 9244859
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/protocol-perf/src/perf-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,23 @@ export class Perf implements Startable, PerfInterface {
const writeBlockSize = this.writeBlockSize

const initialStartTime = Date.now()
let lastReportedTime = Date.now()
const connection = await this.components.connectionManager.openConnection(ma, {
...options,
force: options.reuseExistingConnection !== true
})

this.log('opened connection after %d ms', Date.now() - lastReportedTime)
lastReportedTime = Date.now()

const stream = await connection.newStream(this.protocol, options)

this.log('opened stream after %d ms', Date.now() - lastReportedTime)
lastReportedTime = Date.now()

let lastAmountOfBytesSent = 0
let lastReportedTime = Date.now()
let totalBytesSent = 0
let uploadStart = Date.now()

// tell the remote how many bytes we will send. Up cast to 64 bit number
// as if we send as ui32 we limit total transfer size to 4GB
Expand Down Expand Up @@ -160,10 +167,13 @@ export class Perf implements Startable, PerfInterface {

yield * output

this.log('upload complete after %d ms', Date.now() - uploadStart)

// Read the received bytes
let lastAmountOfBytesReceived = 0
lastReportedTime = Date.now()
let totalBytesReceived = 0
let downloadStart = Date.now()

for await (const buf of stream.source) {
if (Date.now() - lastReportedTime > 1000) {
Expand All @@ -184,6 +194,8 @@ export class Perf implements Startable, PerfInterface {
totalBytesReceived += buf.byteLength
}

this.log('download complete after %d ms', Date.now() - downloadStart)

if (totalBytesReceived !== receiveBytes) {
throw new Error(`Expected to receive ${receiveBytes} bytes, but received ${totalBytesReceived}`)
}
Expand Down

0 comments on commit 9244859

Please sign in to comment.