Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bench test for large core with two non-sparse readers #405

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
},
"devDependencies": {
"brittle": "^3.0.0",
"byte-size": "^8.1.1",
"hyperswarm": "^4.3.6",
"random-access-memory": "^6.1.0",
"random-access-memory-overlay": "^3.0.0",
Expand Down
70 changes: 70 additions & 0 deletions test/bench/large.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const test = require('brittle')
const Hypercore = require('../../index.js')
const RAM = require('random-access-memory')
const { replicate, createTmpDir } = require('../helpers')
const speedometer = require('speedometer')
const byteSize = require('byte-size')

test('large core with two non-sparse readers', { timeout: 999999999 }, async function (t) {
const dir = createTmpDir(t)

const writer = new Hypercore(dir)
await writer.ready()

const clone1 = new Hypercore(RAM, writer.key)
const clone2 = new Hypercore(RAM, writer.key)

for (let i = writer.length; i < 1000000; i++) {
await writer.append(Math.random().toString(16).substr(2))

if (i % 100000 === 0) t.comment('Append ' + i)
}

t.comment('Writer complete')

intervalSpeed(t, writer, 'Writer')
intervalSpeed(t, clone1, 'Clone1')
intervalSpeed(t, clone2, 'Clone2')

replicate(writer, clone1, t)
replicate(writer, clone2, t)

const dl1 = clone1.download()
const dl2 = clone2.download()

await dl1.done()
await dl2.done()

t.comment('Done')

await writer.close()
await clone1.close()
await clone2.close()
})

function intervalSpeed (t, core, name) {
const info = {
blocks: { down: speedometer(), up: speedometer() },
network: { down: speedometer(), up: speedometer() }
}

core.on('download', onspeed.bind(null, 'down', info))
core.on('upload', onspeed.bind(null, 'up', info))

const id = setInterval(() => {
t.comment(
name,
'↓ ' + Math.ceil(info.blocks.down()),
'↑ ' + Math.ceil(info.blocks.up()) + ' blks/s',
'↓ ' + byteSize(info.network.down()),
'↑ ' + byteSize(info.network.up())
)
}, 1000)

t.teardown(() => clearInterval(id))
}

function onspeed (eventName, info, index, byteLength, from) {
info.blocks[eventName](1)
info.network[eventName](byteLength)
}