Giter VIP home page Giter VIP logo

grpcp's Issues

getConn fast-path

@0x5010 hello!很棒的项目!很久以前我在go夜读1群里看到你分享了这个项目,现在有这个需求就回过头来仔细看了下,然后有些地方我想改一下,然后给你提pr,先问问你的意见
1.一些拼写错误,比如cancel拼成了cannelhttps://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即可

HI,我使用的beego框架,这样的使用方法是否正确?

这是在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需要连接池吗?

grpc需要连接池吗?这个连接池会断了重连吗?跟默认的连接方式相比,有什么优势吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.