Skip to content

Commit

Permalink
Change execution stats intervals (ethereumjs#3106)
Browse files Browse the repository at this point in the history
* Report execution stats in time intervals

* Format constant

* Remove unused property

* Client: further reduce execution/state stats interval from 40 -> 90 secs

---------

Co-authored-by: Holger Drewes <[email protected]>
  • Loading branch information
scorbajio and holgerd77 authored Oct 23, 2023
1 parent ff14395 commit eeb74e4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
30 changes: 20 additions & 10 deletions packages/client/src/execution/vmexecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ export class VMExecution extends Execution {
private MAX_TOLERATED_BLOCK_TIME = 12

/**
* Display state cache stats every num blocks
* Interval for client execution stats output (in ms)
* for debug log level
*
*/
private STATS_NUM_BLOCKS = 5000
private statsCount = 0
private STATS_INTERVAL = 1000 * 90 // 90 seconds

private _statsInterval: NodeJS.Timeout | undefined /* global NodeJS */
private _statsVm: VM | undefined

/**
* Create new VM execution module
Expand Down Expand Up @@ -411,8 +415,8 @@ export class VMExecution extends Execution {
throw Error('Execution stopped')
}

this._statsVm = this.vm
const beforeTS = Date.now()
this.stats(this.vm)
const result = await this.vm.runBlock({
block,
root: parentState,
Expand Down Expand Up @@ -593,6 +597,12 @@ export class VMExecution extends Execution {
* Start execution
*/
async start(): Promise<boolean> {
this._statsInterval = setInterval(
// eslint-disable-next-line @typescript-eslint/await-thenable
await this.stats.bind(this),
this.STATS_INTERVAL
)

const { blockchain } = this.vm
if (this.running || !this.started) {
return false
Expand Down Expand Up @@ -627,6 +637,7 @@ export class VMExecution extends Execution {
* Stop VM execution. Returns a promise that resolves once its stopped.
*/
async stop(): Promise<boolean> {
clearInterval(this._statsInterval)
// Stop with the lock to be concurrency safe and flip started flag so that
// vmPromise can resolve early
await this.runWithLock<void>(async () => {
Expand Down Expand Up @@ -676,10 +687,11 @@ export class VMExecution extends Execution {
})

if (txHashes.length === 0) {
this._statsVm = vm

// we are skipping header validation because the block has been picked from the
// blockchain and header should have already been validated while putBlock
const beforeTS = Date.now()
this.stats(vm)
const res = await vm.runBlock({
block,
root,
Expand Down Expand Up @@ -722,10 +734,9 @@ export class VMExecution extends Execution {
}
}

stats(vm: VM) {
this.statsCount += 1
if (this.statsCount === this.STATS_NUM_BLOCKS) {
const sm = vm.stateManager as any
stats() {
if (this._statsVm !== undefined) {
const sm = this._statsVm.stateManager as any
const disactivatedStats = { size: 0, reads: 0, hits: 0, writes: 0 }
let stats
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
Expand All @@ -748,7 +759,6 @@ export class VMExecution extends Execution {
`Trie cache stats size=${tStats.size} reads=${tStats.cache.reads} hits=${tStats.cache.hits} ` +
`writes=${tStats.cache.writes} readsDB=${tStats.db.reads} hitsDB=${tStats.db.hits} writesDB=${tStats.db.writes}`
)
this.statsCount = 0
}
}
}
2 changes: 1 addition & 1 deletion packages/client/src/service/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class Service {
*
* (for info there will be somewhat reduced output)
*/
private STATS_INTERVAL = 20000
private STATS_INTERVAL = 1000 * 20 // 20 seconds

/**
* Shutdown the client when memory threshold is reached (in percent)
Expand Down

0 comments on commit eeb74e4

Please sign in to comment.