https://github.com/ejunjsh/workerpool
https://github.com/ejunjsh/workerpool
Last synced: 27 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ejunjsh/workerpool
- Owner: ejunjsh
- Created: 2017-08-05T13:40:08.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-05T14:03:23.000Z (over 8 years ago)
- Last Synced: 2024-12-29T08:41:51.859Z (about 1 year ago)
- Language: Go
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# workerpool
## install
````go
go get github.com/ejunjsh/workerpool
````
## usage
````go
import "github.com/ejunjsh/workerpool"
func main(){
wg := new(sync.WaitGroup)
//十个goroutine,队列容量100
wp:=workerpool.NewWorkerPool(10,100)
wp.Start()
//提交1000000任务
for i := 0; i < 1000000; i++ {
wg.Add(1)
wp.Execute(func() {
for j := 0; j < 100000; j++ {
}
wg.Done()
})
}
wg.Wait()
wp.Stop()
}
````
## benchmark
````bash
$ go test -bench .
BenchmarkWorkerPool-8 1 8170956922 ns/op
BenchmarkNopool-8 1 8400776011 ns/op
BenchmarkGopool-8 1 8129090755 ns/op
````