https://github.com/flyaways/pool
General Purpose Connection Pool for GRPC,RPC,TCP Sevice Cluster
https://github.com/flyaways/pool
connection-pool golang grpc pool rpc tcp
Last synced: 2 months ago
JSON representation
General Purpose Connection Pool for GRPC,RPC,TCP Sevice Cluster
- Host: GitHub
- URL: https://github.com/flyaways/pool
- Owner: flyaways
- License: mit
- Created: 2018-05-20T14:06:30.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-08-08T11:54:00.000Z (over 1 year ago)
- Last Synced: 2024-11-17T12:48:38.344Z (over 1 year ago)
- Topics: connection-pool, golang, grpc, pool, rpc, tcp
- Language: Go
- Homepage: https://flyaways.github.io/pool/
- Size: 144 KB
- Stars: 135
- Watchers: 4
- Forks: 35
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Pool
[](https://godoc.org/github.com/flyaways/pool)
[](https://goreportcard.com/report/github.com/flyaways/pool)
[](https://sourcegraph.com/github.com/flyaways/pool?badge)
[](https://www.codetriage.com/flyaways/pool)
[](https://github.com/flyaways/pool/blob/master/LICENSE)

[](https://github.com/flyaways/pool/releases)
[](https://github.com/996icu/996.ICU/blob/master/LICENSE)
Pool is Used to manage and reuse client connections to service cluster.
Pool provides several key features:
* **General Purpose** - Pool for GRPC,RPC,TCP.support RPC timeout.
* **Support Cluster** - Connet to Cluster.
* **Danamic Update** - Danamic update targets.
Pool runs on Linux, Mac OS X, and Windows.
**Note**: Random to pick a target to get one connection for loadbalance.
## Install
```sh
go get -u gopkg.in/flyaways/pool.v1
```
## Usage
```go
import "gopkg.in/flyaways/pool.v1"
```
## Example
```go
package main
import (
"log"
"time"
"gopkg.in/flyaways/pool.v1"
"google.golang.org/grpc"
)
func main() {
options := &pool.Options{
InitTargets: []string{"127.0.0.1:8080"},
InitCap: 5,
MaxCap: 30,
DialTimeout: time.Second * 5,
IdleTimeout: time.Second * 60,
ReadTimeout: time.Second * 5,
WriteTimeout: time.Second * 5,
}
p, err := pool.NewGRPCPool(options, grpc.WithInsecure())//for grpc
//p, err := pool.NewRPCPool(options) //for rpc
//p, err := pool.NewTCPPool(options) //for tcp
if err != nil {
log.Printf("%#v\n", err)
return
}
if p == nil {
log.Printf("p= %#v\n", p)
return
}
defer p.Close()
//todo
//danamic update targets
//options.Input()<-&[]string{}
conn, err := p.Get()
if err != nil {
log.Printf("%#v\n", err)
return
}
defer p.Put(conn)
//todo
//conn.DoSomething()
log.Printf("len=%d\n", p.IdleCount())
}
```
## Reference
* [https://github.com/fatih/pool](https://github.com/fatih/pool)
* [https://github.com/silenceper/pool]( https://github.com/silenceper/pool)
* [https://github.com/daizuozhuo/rpc-example]( https://github.com/daizuozhuo/rpc-example)
## Contribution Welcomed !
Contributors
* [flyaways](https://github.com/flyaways)
## License
* The MIT License (MIT) - see LICENSE for more details
[](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fflyaways%2Fpool?ref=badge_large)