mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +00:00

Fix sync Fix linter Fix tests Clean up Set default references count to 0 Fix sync Use address instead of databaseId Sync protocol Keep references to open databases in OrbitDB Fix append benchmark Initial version of heads exchange Remove Feed Fix KeyValuePersisted iterator Refactor OrbitDBAddress a bit more Add rest of the database types Refactor OrbitDB addresses Initial version for the full circle Initial structure and tests for new OrbitDB Make sure KeyStore is open when a Database is created Re-organize OrbitDB Use new databases and Log More clean up Add 'drop' event to Database Clean up OrbitDB Remove id from OrbitDB Use new KeyStore and Identities Remove storage from OrbitDB Remove migrations from OrbitDB Remove caches from OrbitDB Remove pubsub from OrbitDB
52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
import { Identities } from '../src/index.js'
|
|
import { Log } from '../src/index.js'
|
|
import { MemoryStorage, LevelStorage } from '../src/storage/index.js'
|
|
|
|
// State
|
|
let log
|
|
|
|
// Metrics
|
|
let totalQueries = 0
|
|
let seconds = 0
|
|
let queriesPerSecond = 0
|
|
let lastTenSeconds = 0
|
|
|
|
const queryLoop = async () => {
|
|
await log.append(totalQueries.toString())
|
|
totalQueries++
|
|
lastTenSeconds++
|
|
queriesPerSecond++
|
|
setImmediate(queryLoop)
|
|
}
|
|
|
|
;(async () => {
|
|
console.log('Starting benchmark...')
|
|
|
|
const identities = await Identities()
|
|
const testIdentity = await identities.createIdentity({ id: 'userA' })
|
|
|
|
// MemoryStorage is the default storage for Log but defining them here
|
|
// in case we want to benchmark different storage modules
|
|
const entryStorage = await MemoryStorage()
|
|
const headsStorage = await MemoryStorage()
|
|
// Test LevelStorage
|
|
// const entryStorage = await LevelStorage({ path: './logA/entries' })
|
|
// const headsStorage = await LevelStorage({ path: './logA/heads' })
|
|
|
|
log = await Log(testIdentity, { logId: 'A', entryStorage, headsStorage })
|
|
|
|
// Output metrics at 1 second interval
|
|
setInterval(() => {
|
|
seconds++
|
|
if (seconds % 10 === 0) {
|
|
console.log(`--> Average of ${lastTenSeconds / 10} q/s in the last 10 seconds`)
|
|
if (lastTenSeconds === 0) throw new Error('Problems!')
|
|
lastTenSeconds = 0
|
|
}
|
|
console.log(`${queriesPerSecond} queries per second, ${totalQueries} queries in ${seconds} seconds`)
|
|
queriesPerSecond = 0
|
|
}, 1000)
|
|
|
|
setImmediate(queryLoop)
|
|
})()
|