Skip to content

hakobe/grpc-go-client-side-load-balancing-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gRPC client side load balancing example using Go

This is a gRPC client-side load balancing example on top of grpc-go.

The only load balancer bundled to grpc-go is grpc.RoundRobin. grpc RoundRoubin requires a grpc.Resolver which is intended to implement a DNS resolver or an other resourse resolution mechanism like Consul.

In this example I implemented a grpc.Resolver which only returns fixed servers initially passed. It is good for trying gRPC load balancing instantly.

Prequirements

  • protoc
  • protoc-gen-go
    • $ go get -u github.com/golang/protobuf/protoc-gen-go

Build

$ make

Run

# Run 4 servers
$ ./server/server -hostport 0.0.0.0:5000 &
$ ./server/server -hostport 0.0.0.0:5001 &
$ ./server/server -hostport 0.0.0.0:5002 &
$ ./server/server -hostport 0.0.0.0:5003 &

$ sleep 3 # Wait for server to start up

# Do gRPC method calls 10000 times
$ time ./client/client -n 10000 \
    -server localhost:5000 \
    -server localhost:5001 \
    -server localhost:5002 \
    -server localhost:5003 \
 
# or 
$ ./run.sh

LICENSE

MIT @hakobe

About

This is a gRPC client-side load balancing example on top of grpc-go.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published