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

cmd: make mempool OOM error handler more adaptive #174

Merged
merged 1 commit into from
May 16, 2024
Merged
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
25 changes: 16 additions & 9 deletions cmd/bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ func main() {
defer cancel()

var (
workers int
rate int
msPerBlock int
threshold time.Duration
dump *internal.Dump
desc = v.GetString("desc")
timeLimit = v.GetDuration("timeLimit")
mode = internal.BenchMode(v.GetString("mode"))
client *internal.RPCClient
workers int
rate int
msPerBlock int
mempoolOOMDelay time.Duration
threshold time.Duration
dump *internal.Dump
desc = v.GetString("desc")
timeLimit = v.GetDuration("timeLimit")
mode = internal.BenchMode(v.GetString("mode"))
client *internal.RPCClient
)

switch mode {
Expand All @@ -61,6 +62,11 @@ func main() {
log.Fatalf("could not receive RPC Node version: %v", err)
}
msPerBlock = version.Protocol.MillisecondsPerBlock
if msPerBlock > 1000 {
mempoolOOMDelay = time.Duration(msPerBlock) * time.Millisecond / 50
} else {
mempoolOOMDelay = time.Duration(msPerBlock) * time.Millisecond / 10
}

reg := regexp.MustCompile(`[^\w.-]+`)
versionStr := strings.Trim(reg.ReplaceAllString(version.UserAgent, "_"), "_")
Expand Down Expand Up @@ -133,6 +139,7 @@ func main() {
internal.WorkerTimeLimit(timeLimit),
internal.WorkerThreshold(threshold),
internal.WorkerBlockchainClient(client),
internal.WorkerMempoolOOMDelay(mempoolOOMDelay),
internal.WorkerRPSReporter(rep.UpdateRPS),
internal.WorkerTPSReporter(rep.UpdateTPS),
internal.WorkerErrReporter(rep.UpdateErr),
Expand Down
35 changes: 22 additions & 13 deletions cmd/internal/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,19 @@ type (
}

doerParams struct {
wrkCount int
cli *RPCClient
mode BenchMode
rate int
threshold time.Duration
timeLimit time.Duration
dump *Dump
cntReporter func(cnt int32)
errReporter func(cnt int32)
rpsReporter func(rps float64)
tpsReporter func(deltaTime uint64, txCount int, tps float64)
stop context.CancelFunc
wrkCount int
cli *RPCClient
mode BenchMode
rate int
threshold time.Duration
timeLimit time.Duration
mempoolOOMDelay time.Duration
dump *Dump
cntReporter func(cnt int32)
errReporter func(cnt int32)
rpsReporter func(rps float64)
tpsReporter func(deltaTime uint64, txCount int, tps float64)
stop context.CancelFunc
}

// WorkerOption is an option type to configure workers.
Expand Down Expand Up @@ -75,6 +76,14 @@ func WorkerBlockchainClient(cli *RPCClient) WorkerOption {
}
}

// WorkerMempoolOOMDelay sets the time interval to pause sender's work after
// mempool OOM error occurred on tx submission.
func WorkerMempoolOOMDelay(delay time.Duration) WorkerOption {
return func(p *doerParams) {
p.mempoolOOMDelay = delay
}
}

// WorkerTimeLimit sets time limit to send requests.
func WorkerTimeLimit(limit time.Duration) WorkerOption {
return func(p *doerParams) {
Expand Down Expand Up @@ -244,7 +253,7 @@ loop:
log.Printf("failed to re-enqueue transaction: %s\n", err)
d.countErr.Add(1)
}
time.Sleep(100 * time.Millisecond)
time.Sleep(d.mempoolOOMDelay)
} else {
d.countErr.Add(1)
}
Expand Down
Loading