Skip to content

Commit

Permalink
cmd: make mempool OOM error handler more adaptive
Browse files Browse the repository at this point in the history
Once mempool OOm error happens, worker should wait for a while until
block processing finishes. Make this awaiting interval depend on
MSPerBlock protocol setting so that it's possible to perform precise
calculations for low MSPerBlock setting.

Signed-off-by: Anna Shaleva <[email protected]>
  • Loading branch information
AnnaShaleva committed May 16, 2024
1 parent b0d351e commit df6d6f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func main() {
internal.WorkerTimeLimit(timeLimit),
internal.WorkerThreshold(threshold),
internal.WorkerBlockchainClient(client),
internal.WorkerMSPerBlock(int64(msPerBlock)),
internal.WorkerRPSReporter(rep.UpdateRPS),
internal.WorkerTPSReporter(rep.UpdateTPS),
internal.WorkerErrReporter(rep.UpdateErr),
Expand Down
12 changes: 11 additions & 1 deletion cmd/internal/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type (
rate int
threshold time.Duration
timeLimit time.Duration
msPerBlock int64
dump *Dump
cntReporter func(cnt int32)
errReporter func(cnt int32)
Expand Down Expand Up @@ -75,6 +76,13 @@ func WorkerBlockchainClient(cli *RPCClient) WorkerOption {
}
}

// WorkerMSPerBlock sets milliseconds per block protocol setting.
func WorkerMSPerBlock(msPerBlock int64) WorkerOption {
return func(p *doerParams) {
p.msPerBlock = msPerBlock
}
}

// WorkerTimeLimit sets time limit to send requests.
func WorkerTimeLimit(limit time.Duration) WorkerOption {
return func(p *doerParams) {
Expand Down Expand Up @@ -213,6 +221,8 @@ func (d *doer) worker(ctx context.Context, idx *atomic.Int64, start time.Time) {
var (
done = ctx.Done()
timer = time.NewTimer(d.timeLimit)
// mempoolOOMDelay is the time interval to pause sender's work after mempool OOM error occurred on tx submission.
mempoolOOMDelay = time.Duration(d.msPerBlock / 50 * int64(time.Millisecond))
)

defer func() {
Expand Down Expand Up @@ -244,7 +254,7 @@ loop:
log.Printf("failed to re-enqueue transaction: %s\n", err)
d.countErr.Add(1)
}
time.Sleep(100 * time.Millisecond)
time.Sleep(mempoolOOMDelay)
} else {
d.countErr.Add(1)
}
Expand Down

0 comments on commit df6d6f7

Please sign in to comment.