0x5010 / grpcp Goto Github PK
View Code? Open in Web Editor NEWgrpcp is a Grpc Persistent Connection Pool.
License: MIT License
grpcp is a Grpc Persistent Connection Pool.
License: MIT License
@0x5010 hello!很棒的项目!很久以前我在go夜读1群里看到你分享了这个项目,现在有这个需求就回过头来仔细看了下,然后有些地方我想改一下,然后给你提pr,先问问你的意见
1.一些拼写错误,比如cancel
拼成了cannel
,https://github.com/0x5010/grpcp/blob/master/grpcp.go#L52
2.加个context option
,这样我外部的ctx cancel之后,pool也可以cancel掉
3.option
的写法,你的option写法其实有点问题,虽然你tracker conn
里的字段是unexport
的,但是我依然可以通过option
再次修改字段值(虽然没人会这么做...),具体的你可以参考下grpc options的写法
https://github.com/grpc/grpc-go/blob/master/server.go#L111
4.读的fast-path,
https://github.com/0x5010/grpcp/blob/master/grpcp.go#L120
func (ct *ConnectionTracker) getConn(addr string, force bool) (*grpc.ClientConn, error) {
ct.Lock()
tc, ok := ct.connections[addr]
if !ok {
tc = &trackedConn{
addr: addr,
tracker: ct,
}
ct.connections[addr] = tc
}
ct.Unlock()
我认为绝大多数的场景,服务热起来后,这里最后都会变成只读,这里作为总入口用Lock
损失太多了,而用读锁就非常轻量,写场景做double-check即可
这是在controller中的一个post方法,每个用户注册都会执行一遍该方法,在高并发的情况下这样使用可以的是吗?
func (this *RegisterController) Post() {
conn, _ := grpcp.GetConn(addr) // get conn with grpcp default pool
// defer conn.Close() // no close, close will disconnect
client := pb.NewGreeterClient(conn)
r, _ := client.SayHello(context.Background(), &pb.HelloRequest{Name: name})
}
grpc需要连接池吗?这个连接池会断了重连吗?跟默认的连接方式相比,有什么优势吗?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.