mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-06 14:16:37 +00:00
Improve log append benchmark
This commit is contained in:
parent
b9422463d0
commit
eb229103bd
@ -1,6 +1,6 @@
|
|||||||
import { Identities } from '../src/index.js'
|
import { Identities, Log } from '../src/index.js'
|
||||||
import { Log } from '../src/index.js'
|
import { MemoryStorage } from '../src/storage/index.js'
|
||||||
import { MemoryStorage, LevelStorage } from '../src/storage/index.js'
|
// import { MemoryStorage, LevelStorage, LRUStorage } from '../src/storage/index.js'
|
||||||
|
|
||||||
// State
|
// State
|
||||||
let log
|
let log
|
||||||
@ -11,6 +11,9 @@ let seconds = 0
|
|||||||
let queriesPerSecond = 0
|
let queriesPerSecond = 0
|
||||||
let lastTenSeconds = 0
|
let lastTenSeconds = 0
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
const benchmarkDuration = 20 // seconds
|
||||||
|
|
||||||
const queryLoop = async () => {
|
const queryLoop = async () => {
|
||||||
await log.append(totalQueries.toString())
|
await log.append(totalQueries.toString())
|
||||||
totalQueries++
|
totalQueries++
|
||||||
@ -22,6 +25,8 @@ const queryLoop = async () => {
|
|||||||
;(async () => {
|
;(async () => {
|
||||||
console.log('Starting benchmark...')
|
console.log('Starting benchmark...')
|
||||||
|
|
||||||
|
console.log('Benchmark duration is ' + benchmarkDuration + ' seconds')
|
||||||
|
|
||||||
const identities = await Identities()
|
const identities = await Identities()
|
||||||
const testIdentity = await identities.createIdentity({ id: 'userA' })
|
const testIdentity = await identities.createIdentity({ id: 'userA' })
|
||||||
|
|
||||||
@ -29,6 +34,9 @@ const queryLoop = async () => {
|
|||||||
// in case we want to benchmark different storage modules
|
// in case we want to benchmark different storage modules
|
||||||
const entryStorage = await MemoryStorage()
|
const entryStorage = await MemoryStorage()
|
||||||
const headsStorage = await MemoryStorage()
|
const headsStorage = await MemoryStorage()
|
||||||
|
// Test LRUStorage
|
||||||
|
// const entryStorage = await LRUStorage()
|
||||||
|
// const headsStorage = await LRUStorage()
|
||||||
// Test LevelStorage
|
// Test LevelStorage
|
||||||
// const entryStorage = await LevelStorage({ path: './logA/entries' })
|
// const entryStorage = await LevelStorage({ path: './logA/entries' })
|
||||||
// const headsStorage = await LevelStorage({ path: './logA/heads' })
|
// const headsStorage = await LevelStorage({ path: './logA/heads' })
|
||||||
@ -36,13 +44,17 @@ const queryLoop = async () => {
|
|||||||
log = await Log(testIdentity, { logId: 'A', entryStorage, headsStorage })
|
log = await Log(testIdentity, { logId: 'A', entryStorage, headsStorage })
|
||||||
|
|
||||||
// Output metrics at 1 second interval
|
// Output metrics at 1 second interval
|
||||||
setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
seconds++
|
seconds++
|
||||||
if (seconds % 10 === 0) {
|
if (seconds % 10 === 0) {
|
||||||
console.log(`--> Average of ${lastTenSeconds / 10} q/s in the last 10 seconds`)
|
console.log(`--> Average of ${lastTenSeconds / 10} q/s in the last 10 seconds`)
|
||||||
if (lastTenSeconds === 0) throw new Error('Problems!')
|
if (lastTenSeconds === 0) throw new Error('Problems!')
|
||||||
lastTenSeconds = 0
|
lastTenSeconds = 0
|
||||||
}
|
}
|
||||||
|
if (seconds >= benchmarkDuration) {
|
||||||
|
clearInterval(interval)
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
console.log(`${queriesPerSecond} queries per second, ${totalQueries} queries in ${seconds} seconds`)
|
console.log(`${queriesPerSecond} queries per second, ${totalQueries} queries in ${seconds} seconds`)
|
||||||
queriesPerSecond = 0
|
queriesPerSecond = 0
|
||||||
}, 1000)
|
}, 1000)
|
Loading…
x
Reference in New Issue
Block a user