hyperdrive-profiler 2.1.0 → 2.2.1
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.
- package/index.js +60 -1
- 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 {}
|
|
@@ -77,6 +86,9 @@ const cmd = command('hyperdrive-profiler',
|
|
|
77
86
|
timestampsInfo += `\n - Blobs core: ${blobsContig} / ${blobsLength} (contiguous length / length)`
|
|
78
87
|
if (secTillFullyDownload) timestampsInfo += `\n - Fully downloaded in ${secTillFullyDownload.toFixed(2)} seconds`
|
|
79
88
|
|
|
89
|
+
timestampsInfo += `\n - Nr peers db core: ${drive.db.core.peers.length} `
|
|
90
|
+
if (drive.blobs) timestampsInfo += `\n - Nr peers blobs core: ${drive.blobs.core.peers.length} `
|
|
91
|
+
|
|
80
92
|
let remoteLength = 0
|
|
81
93
|
let remoteContiguousLength = 0
|
|
82
94
|
let blobRemoteLength = 0
|
|
@@ -87,7 +99,7 @@ const cmd = command('hyperdrive-profiler',
|
|
|
87
99
|
remoteContiguousLength = Math.max(peer.remoteContiguousLength, remoteContiguousLength)
|
|
88
100
|
}
|
|
89
101
|
|
|
90
|
-
for (const peer of drive.blobs?.core.peers) {
|
|
102
|
+
for (const peer of drive.blobs?.core.peers || []) {
|
|
91
103
|
blobRemoteLength = Math.max(peer.remoteLength, blobRemoteLength)
|
|
92
104
|
blobRemoteContiguousLength = Math.max(peer.remoteContiguousLength, blobRemoteContiguousLength)
|
|
93
105
|
}
|
|
@@ -102,6 +114,8 @@ const cmd = command('hyperdrive-profiler',
|
|
|
102
114
|
const swarmInfo = getSwarmInfo(swarmStats, { printIp, detail })
|
|
103
115
|
const hypercoreInfo = getHypercoreInfo(hypercoreStats, { detail })
|
|
104
116
|
console.log(`${timestampsInfo}\n${udxInfo}${swarmInfo}${hypercoreInfo}${contigInfo}`)
|
|
117
|
+
|
|
118
|
+
if (remotes.length > 0) printRemotesInfo(drive, remotes)
|
|
105
119
|
console.log(`${'-'.repeat(50)}\n`)
|
|
106
120
|
}
|
|
107
121
|
const statsInterval = setInterval(printStats, statsIntervalMs)
|
|
@@ -123,6 +137,19 @@ const cmd = command('hyperdrive-profiler',
|
|
|
123
137
|
|
|
124
138
|
await drive.ready()
|
|
125
139
|
|
|
140
|
+
console.info(`Drive db public key: ${IdEnc.normalize(drive.key)}`)
|
|
141
|
+
console.info(`Drive db discovery key: ${IdEnc.normalize(drive.discoveryKey)}`)
|
|
142
|
+
if (drive.blobs) {
|
|
143
|
+
await drive.blobs.ready()
|
|
144
|
+
console.info(`Drive blobs public key: ${IdEnc.normalize(drive.blobs.key)}`)
|
|
145
|
+
console.info(`Drive blobs discovery key: ${IdEnc.normalize(drive.blobs.discoveryKey)}`)
|
|
146
|
+
} else {
|
|
147
|
+
drive.on('blobs', async () => {
|
|
148
|
+
await drive.blobs.ready()
|
|
149
|
+
console.info(`Drive blobs public key: ${IdEnc.normalize(drive.blobs.key)}`)
|
|
150
|
+
console.info(`Drive blobs discovery key: ${IdEnc.normalize(drive.blobs.discoveryKey)}`)
|
|
151
|
+
})
|
|
152
|
+
}
|
|
126
153
|
swarm.join(drive.discoveryKey, { server: false, client: true })
|
|
127
154
|
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
155
|
secTillMetadata = (performance.now() - tStart) / 1000
|
|
@@ -220,4 +247,36 @@ function getUdxInfo (swarmStats, elapsedSec) {
|
|
|
220
247
|
`
|
|
221
248
|
}
|
|
222
249
|
|
|
250
|
+
async function printRemotesInfo (drive, remotes) {
|
|
251
|
+
console.info('Remote download progress overview')
|
|
252
|
+
let nrDoneDbBlindPeers = 0
|
|
253
|
+
let nrDoneBlobsBlindPeers = 0
|
|
254
|
+
|
|
255
|
+
console.info(' - DB core:')
|
|
256
|
+
for (const p of drive.db.core.replicator.peers) {
|
|
257
|
+
const pubKey = IdEnc.normalize(p.remotePublicKey)
|
|
258
|
+
if (remotes.includes(pubKey)) {
|
|
259
|
+
const done = p.remoteLength > 0 && p.remoteContiguousLength === p.remoteLength
|
|
260
|
+
if (remotes && done) nrDoneDbBlindPeers++
|
|
261
|
+
console.info(` - ${IdEnc.normalize(p.remotePublicKey)} ${done ? 'DONE' : 'DOWNLOADING'} ${p.remoteContiguousLength} / ${p.remoteLength}`)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
console.info(' - Blobs core:')
|
|
266
|
+
for (const p of drive.blobs.core.replicator.peers) {
|
|
267
|
+
const pubKey = IdEnc.normalize(p.remotePublicKey)
|
|
268
|
+
if (remotes.includes(pubKey)) {
|
|
269
|
+
const done = p.remoteLength > 0 && p.remoteContiguousLength === p.remoteLength
|
|
270
|
+
if (remotes && done) nrDoneBlobsBlindPeers++
|
|
271
|
+
console.info(` - ${IdEnc.normalize(p.remotePublicKey)} ${done ? 'DONE' : 'DOWNLOADING'} ${p.remoteContiguousLength} / ${p.remoteLength}`)
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (nrDoneDbBlindPeers === remotes.length && nrDoneBlobsBlindPeers === remotes.length) {
|
|
276
|
+
console.info('All remotes fully downloaded this drive')
|
|
277
|
+
} else {
|
|
278
|
+
console.info('Not all remotes have fully downloaded this drive')
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
223
282
|
cmd.parse()
|