eth-tracker/internal/pool/pool.go
Mohammed Sohail fe01fd1f72
perf: increase worker pool queue buffer size 1 -> ~4k
* Previosuly the worker queue pool buffer size was 1 which applies a backpressure on the fast missing blocks producer

* Define our queue size and why we chose this value
2024-06-20 14:19:06 +08:00

30 lines
563 B
Go

package pool
import (
"log/slog"
"runtime/debug"
"github.com/alitto/pond"
)
type PoolOpts struct {
Logg *slog.Logger
WorkerCount int
BlocksBuffer int
}
func NewPool(o PoolOpts) *pond.WorkerPool {
return pond.New(
o.WorkerCount,
o.BlocksBuffer,
pond.Strategy(pond.Balanced()),
pond.PanicHandler(panicHandler(o.Logg)),
)
}
func panicHandler(logg *slog.Logger) func(interface{}) {
return func(panic interface{}) {
logg.Error("block processor goroutine exited from a panic", "error", panic, "stack_trace", string(debug.Stack()))
}
}