Skip to content

Commit adea7bb

Browse files
committed
chore: add trace logs to mss and remove commented perf code
1 parent 6625a27 commit adea7bb

File tree

3 files changed

+17
-62
lines changed

3 files changed

+17
-62
lines changed

packages/multistream-select/src/handle.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export async function handle <Stream extends Duplex<any, any, any>> (stream: Str
7171
}
7272

7373
if (protocols.includes(protocol)) {
74-
await multistream.write(lp, uint8ArrayFromString(`${protocol}\n`), options)
7574
options.log.trace('respond with "%s" for "%s"', protocol, protocol)
75+
await multistream.write(lp, uint8ArrayFromString(`${protocol}\n`), options)
7676

7777
return { stream: lp.unwrap(), protocol }
7878
}
@@ -89,7 +89,7 @@ export async function handle <Stream extends Duplex<any, any, any>> (stream: Str
8989
continue
9090
}
9191

92-
await multistream.write(lp, uint8ArrayFromString('na\n'), options)
9392
options.log('respond with "na" for "%s"', protocol)
93+
await multistream.write(lp, uint8ArrayFromString('na\n'), options)
9494
}
9595
}

packages/multistream-select/src/select.ts

+3
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ export async function select <Stream extends Duplex<any, any, any>> (stream: Str
6666
const p2 = uint8ArrayFromString(`${protocol}\n`)
6767
await multistream.writeAll(lp, [p1, p2], options)
6868

69+
options?.log.trace('select: reading multistream-select header')
6970
let response = await multistream.readString(lp, options)
7071
options?.log.trace('select: read "%s"', response)
7172

7273
// Read the protocol response if we got the protocolId in return
7374
if (response === PROTOCOL_ID) {
75+
options?.log.trace('select: reading protocol response')
7476
response = await multistream.readString(lp, options)
7577
options?.log.trace('select: read "%s"', response)
7678
}
@@ -84,6 +86,7 @@ export async function select <Stream extends Duplex<any, any, any>> (stream: Str
8486
for (const protocol of protocols) {
8587
options?.log.trace('select: write "%s"', protocol)
8688
await multistream.write(lp, uint8ArrayFromString(`${protocol}\n`), options)
89+
options?.log.trace('select: reading protocol response')
8790
const response = await multistream.readString(lp, options)
8891
options?.log.trace('select: read "%s" for "%s"', response, protocol)
8992

packages/protocol-perf/src/perf-service.ts

+12-60
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,23 @@ export class Perf implements Startable, PerfInterface {
9797
const writeBlockSize = this.writeBlockSize
9898

9999
const initialStartTime = Date.now()
100+
let lastReportedTime = Date.now()
100101
const connection = await this.components.connectionManager.openConnection(ma, {
101102
...options,
102103
force: options.reuseExistingConnection !== true
103104
})
104105

106+
this.log('opened connection after %d ms', Date.now() - lastReportedTime)
107+
lastReportedTime = Date.now()
108+
105109
const stream = await connection.newStream(this.protocol, options)
106110

111+
this.log('opened stream after %d ms', Date.now() - lastReportedTime)
112+
lastReportedTime = Date.now()
113+
107114
let lastAmountOfBytesSent = 0
108-
let lastReportedTime = Date.now()
109115
let totalBytesSent = 0
116+
const uploadStart = Date.now()
110117

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

161168
yield * output
162169

163-
/*
164-
const b = byteStream(stream)
165-
await b.write(uint8Buf.subarray(0, 8), options)
166-
167-
while (sendBytes > 0) {
168-
let toSend: number = writeBlockSize
169-
170-
if (toSend > sendBytes) {
171-
toSend = sendBytes
172-
}
173-
174-
const chunk = uint8Buf.subarray(0, toSend)
175-
176-
await b.write(chunk, options)
177-
178-
sendBytes -= toSend
179-
180-
if (Date.now() - lastReportedTime > 1000) {
181-
yield {
182-
type: 'intermediary',
183-
timeSeconds: (Date.now() - lastReportedTime) / 1000,
184-
uploadBytes: lastAmountOfBytesSent,
185-
downloadBytes: 0
186-
}
187-
188-
// record last reported time after `console.log` because it can
189-
// affect benchmark timings
190-
lastReportedTime = Date.now()
191-
lastAmountOfBytesSent = 0
192-
}
193-
194-
lastAmountOfBytesSent += toSend
195-
totalBytesSent += toSend
196-
}
197-
198-
// sent all the bytes, close the write end of the stream
199-
await b.unwrap().closeWrite()
170+
this.log('upload complete after %d ms', Date.now() - uploadStart)
200171

201-
*/
202172
// Read the received bytes
203173
let lastAmountOfBytesReceived = 0
204174
lastReportedTime = Date.now()
205175
let totalBytesReceived = 0
206-
/*
207-
while (totalBytesReceived < receiveBytes) {
208-
const buf = await b.read(1024, options)
209-
210-
if (Date.now() - lastReportedTime > 1000) {
211-
yield {
212-
type: 'intermediary',
213-
timeSeconds: (Date.now() - lastReportedTime) / 1000,
214-
uploadBytes: 0,
215-
downloadBytes: lastAmountOfBytesReceived
216-
}
176+
const downloadStart = Date.now()
217177

218-
// record last reported time after `console.log` because it can
219-
// affect benchmark timings
220-
lastReportedTime = Date.now()
221-
lastAmountOfBytesReceived = 0
222-
}
223-
224-
lastAmountOfBytesReceived += buf.byteLength
225-
totalBytesReceived += buf.byteLength
226-
}
227-
*/
228178
for await (const buf of stream.source) {
229179
if (Date.now() - lastReportedTime > 1000) {
230180
yield {
@@ -244,6 +194,8 @@ export class Perf implements Startable, PerfInterface {
244194
totalBytesReceived += buf.byteLength
245195
}
246196

197+
this.log('download complete after %d ms', Date.now() - downloadStart)
198+
247199
if (totalBytesReceived !== receiveBytes) {
248200
throw new Error(`Expected to receive ${receiveBytes} bytes, but received ${totalBytesReceived}`)
249201
}

0 commit comments

Comments
 (0)