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 append stats in Core #558

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ module.exports = class Core {
this.sessions = sessions
this.globalCache = globalCache

this.stats = {
blocksAppended: 0,
bytesAppended: 0
}

this._manifestFlushed = !!header.manifest
this._maxOplogSize = 65536
this._autoFlush = 1
Expand Down Expand Up @@ -684,6 +689,7 @@ module.exports = class Core {
}
}

const initByteLength = this.tree.byteLength
const byteLength = await this._appendBlocks(values)

await this.oplog.append([entry], false)
Expand All @@ -700,6 +706,11 @@ module.exports = class Core {

if (this._shouldFlush()) await this._flushOplog()

this.stats.blocksAppended += values.length

const bytesInBatch = byteLength - initByteLength // Safe because we're in a mutex
this.stats.bytesAppended += bytesInBatch

return { length: batch.length, byteLength }
} finally {
this._mutex.unlock()
Expand Down
10 changes: 10 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,13 @@ test('valid manifest passed to a session is stored', async function (t) {

t.alike(b.manifest, core.manifest)
})

test('basic - core stats', async function (t) {
const core = await create()

await core.append('ok')
await core.append(['batch', 'here'])

t.is(core.core.stats.bytesAppended, 11, 'bytesAppended')
t.is(core.core.stats.blocksAppended, 3, 'blocksAppended')
})
Loading