Giter Site home page Giter Site logo

grpc-client-pool's Introduction

grpc-client-pool

grpc-client-pool's scenes are mainly about grpc-sidecar and grpc-proxy !

desc

Each grpc request contains PATH in http2 header, the path is fullMethod.

what is fullMethod ?

/api.v1.election.CandidateSvc/Register

what is serviceName ?

/api.v1.election.CandidateSvc

what is methodName ?

/Register

process

  1. init grpc client pool
  2. get grpc-client by grpc fullMethod/serviceName
  3. use gprc invoke request/response.

grpc-client-pool's People

Contributors

rfyiamcool avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

grpc-client-pool's Issues

你好,请问个grpc负载均衡的问题

看了你这边的连接池给了我很大的帮助,但有一个问题我不是很明白
如下:是通过域名解析实现的一个简单的负载均衡,但我不是很明白grpc内部是怎么对多个连接进行管理的

func main() {
var svc = flag.String("service", "hello_service", "service name")
var reg = flag.String("reg", "http://192.168.127.135:2379", "register etcd address")
flag.Parse()
r := grpclb.NewResolver(*reg, *svc)
resolver.Register(r)

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
DefaultServiceConfig := `{"loadBalancingPolicy":"round_robin"}`
// authority是自己随便起的,不是必须的,但是r.Scheme()+"://authority/"+*svc这种格式是必须的
conn, err := grpc.DialContext(ctx, r.Scheme()+"://authority/"+*svc, grpc.WithInsecure(), grpc.WithDefaultServiceConfig(DefaultServiceConfig), grpc.WithBlock())
if err != nil {
    panic(err)
}

ticker := time.NewTicker(1000 * time.Millisecond)
client := pb.NewGreeterClient(conn)
for t := range ticker.C {
    resp, err := client.SayHello(context.Background(), &pb.HelloRequest{Name: "world " + strconv.Itoa(t.Second())})
    if err == nil {
        logrus.Infof("%v: Reply is %s\n", t, resp.Message)
    }
}

}`

connect to backend server err would cause many goroutines been stuck at client.go#L104

we integrate client.go into our api-gateway.
when our backend gRPC server become unavailable,
our api-gateway process's cpu&memory&goroutines all goes up.

the problem is that client.go uses grpc.Dial() with grpc.WithBlock(),
so when server goes down, every call to grpcpool.getConn() will take 3-second to finish,
causing more and more goroutines got stuck at client.go#L104

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.