Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ethe/goroutinepool
Goroutine pool
https://github.com/ethe/goroutinepool
Last synced: about 2 months ago
JSON representation
Goroutine pool
- Host: GitHub
- URL: https://github.com/ethe/goroutinepool
- Owner: ethe
- License: other
- Created: 2018-07-07T05:52:23.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-11-09T08:06:47.000Z (about 4 years ago)
- Last Synced: 2024-10-12T13:31:49.217Z (3 months ago)
- Language: Go
- Size: 5.86 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
**Deprecated: On Go 1.11.2 goroutine pool has already slower than native `go` keyword.**
# Goroutine Pool
The pool implementation of Go goroutine, it is useful to avoid heavy pressure of `runtime.morestack ` when using goroutine.
It could recycle rather than free goroutines after executed. If the recycled goroutines not be stack reduced yet, then there is no need to request more stack.## Benchmark
```
goos: darwin
goarch: amd64
pkg: eleme/nex/utils/gp
BenchmarkGoPool-4 2000000 753 ns/op 32 B/op 1 allocs/op
BenchmarkGo-4 5000000 318 ns/op 0 B/op 0 allocs/op
BenchmarkMorestackPool-4 1000000 2551 ns/op 64 B/op 3 allocs/op
BenchmarkMoreStack-4 300000 3758 ns/op 16 B/op 1 allocs/op
```## Usage
```go
package mainimport (
"time""github.com/ethe/GoroutinePool"
)func main() {
pool := gp.New(20 * time.Second) // set idle timeout
pool.Go(func() {}) // same as `go func(){}()`
}```
## Lock-free Queue
It also contains a lock-free queue (linked list) minimal implementation.```go
package mainimport (
"fmt""github.com/ethe/GoroutinePool"
)func main() {
queue := NewQueue()
queue.Put(1)
fmt.Println(queue.Get())
}
```