Coder Social home page Coder Social logo

grpcbalance's Introduction

gRPC-go load balancing

The gRPC-go Require

  • Go 1.15+
  • gRPC 1.36.0

Version

Each version corresponds to the corresponding version of GRPC-go.

For example, tag: v1.36.0 -> grpc-go v1.36.0

Cautions

v1.45.0 & v1.46.0-dev running panic like this:

panic: runtime error: comparing uncomparable type MyAttribute

goroutine 1 [running]:
google.golang.org/grpc/attributes.(*Attributes).Equal(0xc00015e4b0, 0xc00013c140)
        /project/vendor/google.golang.org/grpc/attributes/attributes.go:95 +0x194
google.golang.org/grpc/resolver.addressMapEntryList.find({0xc00013c1b8, 0x1, 0x8000102}, {{0xc00015e4c8, 0x13}, {0xc00015e4c8, 0xd}, 0xc00013c140, 0x0, 0x0, ...})
        /project/vendor/google.golang.org/grpc/resolver/map.go:49 +0xb9
google.golang.org/grpc/resolver.(*AddressMap).Get(0xc00013c188, {{0xc00015e4c8, 0x13}, {0xc00015e4c8, 0xd}, 0xc00013c140, 0x0, 0x0, {0x0, 0x0}})
        /project/vendor/google.golang.org/grpc/resolver/map.go:59 +0x94
mesh-sidecar/grpclient_balancer/balancer.(*baseBalancer).UpdateClientConnState(0xc00013b500, {{{0xc000414380, 0x3, 0x3}, 0x0, 0x0}, {0x0, 0x0}})

Your attribute needs implement Equal function. https://github.com/grpc/grpc-go/blob/v1.46.0-dev/attributes/attributes.go#L91

type MyAttribute struct {
    attr string
}

func (ma MyAttribute) Equal(o interface{}) bool {
    return true
}

How it works

The gRPC client-side load balancing to work need to main components, the naming resolver and the load balancing policy

load balancing work image

The infra image source itnext.io

gRPC naming resolver & load balancing working principle

On gRPC Load Balancing

Running the Example Application

The gRPC client and server applications used in the example are based on the proto/echo & load_balancing examples found on the gRPC-go examples with the following modifications:

  • The server running with port args
  • The client used customized balance

Support Balance Strategy

Customize Advanced Balancing Strategy

  1. Modify naming resolver with your requirements, first set attributes.Attributes for per endpoint address, second when one endpoint attributes.Attributes changed then update subConn state.

  2. Implement yourself balancer & picker function, then based on attributes.Attributes picker subConn in Pick(balancer.PickInfo) (balancer.PickResult, error)

License

Apache 2.0 license.

grpcbalance's People

Contributors

xkeyideal avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

imneov

grpcbalance's Issues

同学,您这个项目引入了55个开源组件,存在3个漏洞,辛苦升级一下

检测到 xkeyideal/grpcbalance 一共引入了55个开源组件,存在3个漏洞

漏洞标题:Go SSH拒绝服务漏洞
缺陷组件:golang.org/x/[email protected]
漏洞编号:CVE-2020-9283
漏洞描述:Go SSH是一个使用go语言开发的极度简洁的ssh工具,用于远程管理linux、unix等机器。
Go SSH存在拒绝服务漏洞,该漏洞源于网络系统或产品未对输入的数据进行正确的验证,攻击者可利用该漏洞导致拒绝服务条件,拒绝向合法用户提供服务。
国家漏洞库信息:https://www.cnvd.org.cn/flaw/show/CNVD-2020-14300
影响范围:(∞, 0.0.0-20200220183623-bac4c82f6975)
最小修复版本:0.0.0-20200220183623-bac4c82f6975
缺陷组件引入路径:main@->golang.org/x/[email protected]

另外还有3个漏洞,详细报告:https://mofeisec.com/jr?p=a8d165

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.