hyperdrive-profiler 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +57 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -20,6 +20,7 @@ const cmd = command('hyperdrive-profiler',
20
20
  flag('--interval|-i [integer]', 'Interval (in seconds) at which to print the performance stats (default 10)'),
21
21
  flag('--ip', 'Print the IP address (obfuscated by default)'),
22
22
  flag('--detail', 'Include detailed stats'),
23
+ flag('--remotes|-r [string]', 'Location of a .txt file containing remote keys. Will print the remote status of each of them. Useful to verify all remotes downloaded the drive.'),
23
24
 
24
25
  async function ({ args, flags }) {
25
26
  const key = IdEnc.decode(args.key)
@@ -36,6 +37,14 @@ const cmd = command('hyperdrive-profiler',
36
37
  console.info(`Using temporary directory ${tmpdir}`)
37
38
  console.info(`Printing progress every ${(statsIntervalMs / 1000).toFixed(0)} seconds`)
38
39
 
40
+ const remotes = []
41
+ if (flags.remotes) {
42
+ console.info(`Reading remote peers from ${flags.remotes}`)
43
+ const content = await fs.promises.readFile(flags.remotes, { encoding: 'utf8' })
44
+ const keys = content.trim().split('\n')
45
+ for (const k of keys) remotes.push(IdEnc.normalize(k))
46
+ console.info(`Printing remote progress for:\n- ${remotes.join('\n- ')}\n`)
47
+ }
39
48
  try {
40
49
  await gcDir(tmpdir)
41
50
  } catch {}
@@ -87,7 +96,7 @@ const cmd = command('hyperdrive-profiler',
87
96
  remoteContiguousLength = Math.max(peer.remoteContiguousLength, remoteContiguousLength)
88
97
  }
89
98
 
90
- for (const peer of drive.blobs?.core.peers) {
99
+ for (const peer of drive.blobs?.core.peers || []) {
91
100
  blobRemoteLength = Math.max(peer.remoteLength, blobRemoteLength)
92
101
  blobRemoteContiguousLength = Math.max(peer.remoteContiguousLength, blobRemoteContiguousLength)
93
102
  }
@@ -102,6 +111,8 @@ const cmd = command('hyperdrive-profiler',
102
111
  const swarmInfo = getSwarmInfo(swarmStats, { printIp, detail })
103
112
  const hypercoreInfo = getHypercoreInfo(hypercoreStats, { detail })
104
113
  console.log(`${timestampsInfo}\n${udxInfo}${swarmInfo}${hypercoreInfo}${contigInfo}`)
114
+
115
+ if (remotes.length > 0) printRemotesInfo(drive, remotes)
105
116
  console.log(`${'-'.repeat(50)}\n`)
106
117
  }
107
118
  const statsInterval = setInterval(printStats, statsIntervalMs)
@@ -123,6 +134,19 @@ const cmd = command('hyperdrive-profiler',
123
134
 
124
135
  await drive.ready()
125
136
 
137
+ console.info(`Drive db public key: ${IdEnc.normalize(drive.key)}`)
138
+ console.info(`Drive db discovery key: ${IdEnc.normalize(drive.discoveryKey)}`)
139
+ if (drive.blobs) {
140
+ await drive.blobs.ready()
141
+ console.info(`Drive blobs public key: ${IdEnc.normalize(drive.blobs.key)}`)
142
+ console.info(`Drive blobs discovery key: ${IdEnc.normalize(drive.blobs.discoveryKey)}`)
143
+ } else {
144
+ drive.on('blobs', async () => {
145
+ await drive.blobs.ready()
146
+ console.info(`Drive blobs public key: ${IdEnc.normalize(drive.blobs.key)}`)
147
+ console.info(`Drive blobs discovery key: ${IdEnc.normalize(drive.blobs.discoveryKey)}`)
148
+ })
149
+ }
126
150
  swarm.join(drive.discoveryKey, { server: false, client: true })
127
151
  if (drive.db.core.length <= 1) await once(drive.db.core, 'append') // DEVNOTE: in theory we could get a not-latest length, but 'good enough'
128
152
  secTillMetadata = (performance.now() - tStart) / 1000
@@ -220,4 +244,36 @@ function getUdxInfo (swarmStats, elapsedSec) {
220
244
  `
221
245
  }
222
246
 
247
+ async function printRemotesInfo (drive, remotes) {
248
+ console.info('Remote download progress overview')
249
+ let nrDoneDbBlindPeers = 0
250
+ let nrDoneBlobsBlindPeers = 0
251
+
252
+ console.info(' - DB core:')
253
+ for (const p of drive.db.core.replicator.peers) {
254
+ const pubKey = IdEnc.normalize(p.remotePublicKey)
255
+ if (remotes.includes(pubKey)) {
256
+ const done = p.remoteLength > 0 && p.remoteContiguousLength === p.remoteLength
257
+ if (remotes && done) nrDoneDbBlindPeers++
258
+ console.info(` - ${IdEnc.normalize(p.remotePublicKey)} ${done ? 'DONE' : 'DOWNLOADING'} ${p.remoteContiguousLength} / ${p.remoteLength}`)
259
+ }
260
+ }
261
+
262
+ console.info(' - Blobs core:')
263
+ for (const p of drive.blobs.core.replicator.peers) {
264
+ const pubKey = IdEnc.normalize(p.remotePublicKey)
265
+ if (remotes.includes(pubKey)) {
266
+ const done = p.remoteLength > 0 && p.remoteContiguousLength === p.remoteLength
267
+ if (remotes && done) nrDoneBlobsBlindPeers++
268
+ console.info(` - ${IdEnc.normalize(p.remotePublicKey)} ${done ? 'DONE' : 'DOWNLOADING'} ${p.remoteContiguousLength} / ${p.remoteLength}`)
269
+ }
270
+ }
271
+
272
+ if (nrDoneDbBlindPeers === remotes.length && nrDoneBlobsBlindPeers === remotes.length) {
273
+ console.info('All remotes fully downloaded this drive')
274
+ } else {
275
+ console.info('Not all remotes have fully downloaded this drive')
276
+ }
277
+ }
278
+
223
279
  cmd.parse()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperdrive-profiler",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Profile hyperdrive download performance",
5
5
  "main": "index.js",
6
6
  "scripts": {