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.
go get -u github.com/GitHub121380/pool
import "github.com/GitHub121380/pool"
package main
import (
"log"
"time"
"github.com/GitHub121380/pool"
"google.golang.org/grpc"
)
func main() {
options := &pool.Options{
InitTargets: []string{"127.0.0.1:8080"},
InitCap: 5,
MaxCap: 30,
TimeoutType: pool.IdleTimeoutType,
//TimeoutType: pool.FixedTimeoutType,
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())
}
- https://github.com/fatih/pool
- https://github.com/silenceper/pool
- https://github.com/daizuozhuo/rpc-example
- https://github.com/flyaways/pool
Contributors