Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tiancaiamao/gp
A nano goroutine pool implementation in several lines
https://github.com/tiancaiamao/gp
Last synced: 13 days ago
JSON representation
A nano goroutine pool implementation in several lines
- Host: GitHub
- URL: https://github.com/tiancaiamao/gp
- Owner: tiancaiamao
- License: apache-2.0
- Created: 2022-09-29T14:06:46.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-26T08:29:55.000Z (almost 2 years ago)
- Last Synced: 2024-10-31T15:52:52.325Z (20 days ago)
- Language: Go
- Size: 11.7 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# A simple goroutine pool
## Rational
Goroutine is cheap, but not free. Especially when the goroutine trigger `runtime.morestack`, the cost become high.
This package is mainly aimed to handle that. Put back the stack-growed goroutine to a pool, and reuse that goroutine can eliminate the `runtime.morestack` cost.
See a blog post (Chinese) https://www.zenlife.tk/goroutine-pool.md
## Usage
Just replace your `go f()` call with `gp.Go(f)`:
```
import "github.com/tiancaiamao/gp"var gP = gp.New(N, time.Duration)
gp.Go(func() {
// ...
})
```