hyperdrive-profiler 2.0.4 → 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.
- package/index.js +78 -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,10 +86,33 @@ 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
|
+
let remoteLength = 0
|
|
90
|
+
let remoteContiguousLength = 0
|
|
91
|
+
let blobRemoteLength = 0
|
|
92
|
+
let blobRemoteContiguousLength = 0
|
|
93
|
+
|
|
94
|
+
for (const peer of drive.core.peers) {
|
|
95
|
+
remoteLength = Math.max(peer.remoteLength, remoteLength)
|
|
96
|
+
remoteContiguousLength = Math.max(peer.remoteContiguousLength, remoteContiguousLength)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
for (const peer of drive.blobs?.core.peers || []) {
|
|
100
|
+
blobRemoteLength = Math.max(peer.remoteLength, blobRemoteLength)
|
|
101
|
+
blobRemoteContiguousLength = Math.max(peer.remoteContiguousLength, blobRemoteContiguousLength)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let contigInfo = 'Availability:\n'
|
|
105
|
+
contigInfo += ' - Metadata remote length: ' + remoteLength + '\n'
|
|
106
|
+
contigInfo += ' - Metadata remote contiguous length: ' + remoteContiguousLength + '\n'
|
|
107
|
+
contigInfo += ' - Blob remote length: ' + blobRemoteLength + '\n'
|
|
108
|
+
contigInfo += ' - Blob remote contiguous length: ' + blobRemoteContiguousLength + '\n'
|
|
109
|
+
|
|
80
110
|
const udxInfo = getUdxInfo(swarmStats, elapsedSec)
|
|
81
111
|
const swarmInfo = getSwarmInfo(swarmStats, { printIp, detail })
|
|
82
112
|
const hypercoreInfo = getHypercoreInfo(hypercoreStats, { detail })
|
|
83
|
-
console.log(`${timestampsInfo}\n${udxInfo}${swarmInfo}${hypercoreInfo}`)
|
|
113
|
+
console.log(`${timestampsInfo}\n${udxInfo}${swarmInfo}${hypercoreInfo}${contigInfo}`)
|
|
114
|
+
|
|
115
|
+
if (remotes.length > 0) printRemotesInfo(drive, remotes)
|
|
84
116
|
console.log(`${'-'.repeat(50)}\n`)
|
|
85
117
|
}
|
|
86
118
|
const statsInterval = setInterval(printStats, statsIntervalMs)
|
|
@@ -102,6 +134,19 @@ const cmd = command('hyperdrive-profiler',
|
|
|
102
134
|
|
|
103
135
|
await drive.ready()
|
|
104
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
|
+
}
|
|
105
150
|
swarm.join(drive.discoveryKey, { server: false, client: true })
|
|
106
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'
|
|
107
152
|
secTillMetadata = (performance.now() - tStart) / 1000
|
|
@@ -199,4 +244,36 @@ function getUdxInfo (swarmStats, elapsedSec) {
|
|
|
199
244
|
`
|
|
200
245
|
}
|
|
201
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
|
+
|
|
202
279
|
cmd.parse()
|