-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathindex.js
74 lines (58 loc) · 1.69 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* eslint-disable no-console */
import assert from 'assert'
import range from 'lodash.range'
import { makeBlocks } from '../test/utils/make-blocks.js'
import { genBitswapNetwork } from '../test/utils/mocks.js'
const nodes = [2, 5, 10, 20]
const blockFactors = [1, 10, 100]
;(async function () {
console.log('-- start')
await Promise.all(
nodes.map(async nodeCount => {
await Promise.all(
blockFactors.map(async blockFactor => {
const nodeArr = await genBitswapNetwork(nodeCount)
await round(nodeArr, blockFactor, nodeCount)
await shutdown(nodeArr)
})
)
})
)
console.log('-- finished')
})()
async function shutdown (nodeArr) {
await Promise.all(
nodeArr.map(async node => {
await node.bitswap.stop()
await node.libp2p.stop()
})
)
}
async function round (nodeArr, blockFactor, n) {
const blocks = await makeBlocks(n * blockFactor)
const cids = blocks.map((b) => b.cid)
console.info('put blockFactor amount of blocks per node')
await Promise.all(
nodeArr.map(async (node, i) => {
await node.bitswap.start()
await Promise.all(
range(blockFactor).map(async j => {
const index = i * blockFactor + j
await node.bitswap.put(blocks[index])
})
)
})
)
console.info('fetch all blocks on every node')
const d = Date.now()
await Promise.all(
nodeArr.map(async node => {
let count = 0
for await (const _ of node.bitswap.getMany(cids)) { // eslint-disable-line no-unused-vars
count++
}
assert(count === blocks.length)
})
)
console.log(' %s nodes - %s blocks/node - %sms', n, blockFactor, Date.now() - d)
}