From 8c7069a3a6b7a39835b21e2fb6632ccf09fb4047 Mon Sep 17 00:00:00 2001 From: haad Date: Fri, 1 Sep 2023 09:35:18 +0300 Subject: [PATCH] Fix nodejs benchmarks --- benchmarks/log-iterator.js | 2 +- benchmarks/orbitdb-events.js | 83 +++++++++++++++++++++++++++++++++ benchmarks/orbitdb-keyvalue.js | 8 +--- benchmarks/orbitdb-replicate.js | 14 ++---- 4 files changed, 91 insertions(+), 16 deletions(-) create mode 100644 benchmarks/orbitdb-events.js diff --git a/benchmarks/log-iterator.js b/benchmarks/log-iterator.js index 4da047b..de3a0e1 100644 --- a/benchmarks/log-iterator.js +++ b/benchmarks/log-iterator.js @@ -33,7 +33,7 @@ import rmrf from 'rimraf' const startTime1 = new Date().getTime() for (let i = 0; i < entryCount; i++) { - await log.append(i.toString(), { pointerCount: 0 }) + await log.append(i.toString(), { referencesCount: 0 }) } const endTime1 = new Date().getTime() const duration1 = endTime1 - startTime1 diff --git a/benchmarks/orbitdb-events.js b/benchmarks/orbitdb-events.js new file mode 100644 index 0000000..2506b2c --- /dev/null +++ b/benchmarks/orbitdb-events.js @@ -0,0 +1,83 @@ +import { createOrbitDB } from '../src/index.js' +import rmrf from 'rimraf' +import * as IPFS from 'ipfs-core' + +import { EventEmitter } from 'events' +EventEmitter.defaultMaxListeners = 10000 + +const ipfsConfig = { + preload: { + enabled: false + }, + config: { + Addresses: { + API: '/ip4/127.0.0.1/tcp/0', + Swarm: ['/ip4/0.0.0.0/tcp/0'], + Gateway: '/ip4/0.0.0.0/tcp/0' + }, + Bootstrap: [], + Discovery: { + MDNS: { + Enabled: false, + Interval: 0 + }, + webRTCStar: { + Enabled: false + } + } + } +} + +;(async () => { + console.log('Starting benchmark...') + + const entryCount = 1000 + + await rmrf('./ipfs') + await rmrf('./orbitdb') + + const ipfs = await IPFS.create({ ...ipfsConfig, repo: './ipfs' }) + const orbitdb = await createOrbitDB({ ipfs }) + + console.log(`Create ${entryCount} events`) + + const db1 = await orbitdb.open('benchmark-events') + + const startTime1 = new Date().getTime() + + for (let i = 0; i < entryCount; i++) { + await db1.add(i.toString()) + } + + const endTime1 = new Date().getTime() + const duration1 = endTime1 - startTime1 + const operationsPerSecond1 = Math.floor(entryCount / (duration1 / 1000)) + const millisecondsPerOp1 = duration1 / entryCount + console.log(`Creating ${entryCount} events took ${duration1} ms, ${operationsPerSecond1} ops/s, ${millisecondsPerOp1} ms/op`) + + console.log(`Iterate ${entryCount} events`) + const startTime2 = new Date().getTime() + + const all = [] + for await (const { key, value } of db1.iterator()) { + all.unshift({ key, value }) + } + + const endTime2 = new Date().getTime() + const duration2 = endTime2 - startTime2 + const operationsPerSecond2 = Math.floor(entryCount / (duration2 / 1000)) + const millisecondsPerOp2 = duration2 / entryCount + + console.log(`Iterating ${all.length} events took ${duration2} ms, ${operationsPerSecond2} ops/s, ${millisecondsPerOp2} ms/op`) + + await db1.drop() + await db1.close() + + await orbitdb.stop() + await ipfs.stop() + + await rmrf('./ipfs') + await rmrf('./orbitdb') + + process.exit(0) +})() diff --git a/benchmarks/orbitdb-keyvalue.js b/benchmarks/orbitdb-keyvalue.js index 4b5bf55..c485856 100644 --- a/benchmarks/orbitdb-keyvalue.js +++ b/benchmarks/orbitdb-keyvalue.js @@ -1,18 +1,14 @@ -import { OrbitDB } from '../src/index.js' +import { createOrbitDB } from '../src/index.js' import rmrf from 'rimraf' import * as IPFS from 'ipfs-core' import { EventEmitter } from 'events' - EventEmitter.defaultMaxListeners = 10000 const ipfsConfig = { preload: { enabled: false }, - EXPERIMENTAL: { - pubsub: true - }, config: { Addresses: { API: '/ip4/127.0.0.1/tcp/0', @@ -41,7 +37,7 @@ const ipfsConfig = { await rmrf('./orbitdb') const ipfs = await IPFS.create({ ...ipfsConfig, repo: './ipfs' }) - const orbitdb = await OrbitDB({ ipfs }) + const orbitdb = await createOrbitDB({ ipfs }) console.log(`Set ${entryCount} keys/values`) diff --git a/benchmarks/orbitdb-replicate.js b/benchmarks/orbitdb-replicate.js index 53dffa3..6a7b3ca 100644 --- a/benchmarks/orbitdb-replicate.js +++ b/benchmarks/orbitdb-replicate.js @@ -1,20 +1,16 @@ -import { OrbitDB } from '../src/index.js' +import { createOrbitDB } from '../src/index.js' import rmrf from 'rimraf' import * as IPFS from 'ipfs-core' import connectPeers from '../test/utils/connect-nodes.js' import waitFor from '../test/utils/wait-for.js' import { EventEmitter } from 'events' - EventEmitter.defaultMaxListeners = 10000 const ipfsConfig = { preload: { enabled: false }, - EXPERIMENTAL: { - pubsub: true - }, config: { Addresses: { API: '/ip4/127.0.0.1/tcp/0', @@ -46,8 +42,8 @@ const ipfsConfig = { const ipfs1 = await IPFS.create({ ...ipfsConfig, repo: './ipfs1' }) const ipfs2 = await IPFS.create({ ...ipfsConfig, repo: './ipfs2' }) - const orbitdb1 = await OrbitDB({ ipfs: ipfs1, directory: './orbitdb1' }) - const orbitdb2 = await OrbitDB({ ipfs: ipfs2, directory: './orbitdb2' }) + const orbitdb1 = await createOrbitDB({ ipfs: ipfs1, directory: './orbitdb1' }) + const orbitdb2 = await createOrbitDB({ ipfs: ipfs2, directory: './orbitdb2' }) await connectPeers(ipfs1, ipfs2) @@ -77,7 +73,7 @@ const ipfsConfig = { await waitFor(() => connected, () => true) - console.log(`Iterate ${entryCount} events`) + console.log(`Iterate ${entryCount} events to replicate them`) const startTime2 = new Date().getTime() const all = [] @@ -90,7 +86,7 @@ const ipfsConfig = { const operationsPerSecond2 = Math.floor(entryCount / (duration2 / 1000)) const millisecondsPerOp2 = duration2 / entryCount - console.log(`Iterating ${all.length} events took ${duration2} ms, ${operationsPerSecond2} ops/s, ${millisecondsPerOp2} ms/op`) + console.log(`Replicating ${all.length} events took ${duration2} ms, ${operationsPerSecond2} ops/s, ${millisecondsPerOp2} ms/op`) await db1.drop() await db1.close()