goAgilePool is a lightweight goroutine pool for Golang, designed for simplicity and high performance
- Customizable goroutine pool size
- Configurable task queue size
- Task timeout control
- Automatic cleanup of idle workers upon timeout
- Efficient worker reuse through FIFO worker queue management
go get github.com/Yiming1997/go-agile-pool
Pool.Submit()
pool := agilepool.NewPool()
// Supports chainable configuration for pool parameters
pool.InitConfig().
WithCleanPeriod(500 * time.Millisecond).
WithTaskQueueSize(10000).
WithWorkerNumCapacity(20000)
// Start the goroutine pool
pool.Init()
wait := sync.WaitGroup{}
for i := 0; i < 20000000; i++ {
wait.Add(1)
go func() {
pool.Submit(func() {
defer wait.Done()
time.Sleep(10 * time.Millisecond)
})
}()
}
wait.Wait()
Pool.SubmitBefore()
pool.SubmitBefore(func() {
defer wait.Done()
time.Sleep(10 * time.Millisecond)
}, 5*time.Second)
benchmark
BenchmarkAgilePool-14 1 5953874200 ns/op 527994424 B/op 21709143 allocs/op