概要
ノンブロッキングで同時実行数を制限する goroutine プール
その他のプロジェクト計測したスター増加
- 24時間
- +1
- 7日間
- +1
- 15日間
- +1
- 1か月
- 0
期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。
README.md
オリジナルworkerpool
Concurrency limiting goroutine pool. Limits the concurrency of task execution, not the number of tasks queued. Never blocks submitting tasks, no matter how many tasks are queued.
If you need a worker pool that blocks when all workers are busy, see workers.
This implementation builds on ideas from the following:
- http://marcio.io/2015/07/handling-1-million-requests-per-minute-with-golang
- http://nesv.github.io/golang/2014/02/25/worker-queues-in-go.html
Installation
Add the module to your project:
go get github.com/gammazero/workerpool
Example
package main
import (
"fmt"
"github.com/gammazero/workerpool"
)
func main() {
wp := workerpool.New(2)
requests := []string{"alpha", "beta", "gamma", "delta", "epsilon"}
for _, r := range requests {
err := wp.Do(func() {
fmt.Println("Handling request:", r)
})
if err != nil {
fmt.Println("Cannot handle request:", err)
}
}
wp.StopWait()
}
Example wrapper function to show start and finish time of submitted function.
Usage Note
There is no upper limit on the number of tasks queued, other than the limits of system resources. If the number of inbound tasks is too many to even queue for pending processing, then the solution is outside the scope of workerpool. It should be solved by distributing workload over multiple systems, and/or storing input for pending processing in intermediate storage such as a file system, distributed message queue, etc.
関連プロジェクトを探す
読み込み中…