Documentation
¶
Overview ¶
Package load include helpers for building grpclb compatible servers.
Example ¶
package main import ( "log" "net" "time" lbpb "github.com/bsm/grpclb/grpclb_backend_v1" "github.com/bsm/grpclb/load" "golang.org/x/net/context" "google.golang.org/grpc" pb "google.golang.org/grpc/examples/helloworld/helloworld" ) // GreeterServer is used to implement helloworld.GreeterServer. type GreeterServer struct { reporter *load.RateReporter } // SayHello implements helloworld.GreeterServer // It increments rate to report load metrics to the load balancer. func (s *GreeterServer) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { s.reporter.Increment(1) return &pb.HelloReply{Message: "Hello " + in.Name}, nil } func main() { lis, err := net.Listen("tcp", ":50051") if err != nil { log.Fatalf("failed to listen: %v", err) } s := grpc.NewServer() r := load.NewRateReporter(time.Minute) pb.RegisterGreeterServer(s, &GreeterServer{reporter: r}) lbpb.RegisterLoadReportServer(s, r) s.Serve(lis) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RateReporter ¶
type RateReporter struct {
// contains filtered or unexported fields
}
RateReporter maintains score as an exponentially weighted rate
func NewRateReporter ¶
func NewRateReporter(d time.Duration) *RateReporter
NewRateReporter builds a rate reporter over a period of time.
func (*RateReporter) Increment ¶
func (r *RateReporter) Increment(n int64)
Increment increases the rate by n. Typical use case is e.g. the rate of requests, where Increment(1) is called on every request.
func (*RateReporter) Load ¶
func (r *RateReporter) Load(_ context.Context, _ *pb.LoadRequest) (*pb.LoadResponse, error)
Load implements github.com/bsm/grpclb/grpclb_backend_v1.LoadReportServer
func (*RateReporter) Score ¶
func (r *RateReporter) Score() int64
Score returns the current load score
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
Reporter is a simple and proportional github.com/bsm/grpclb/grpclb_backend_v1.LoadReportServer
func (*Reporter) Increment ¶
Increment allows to adjust load by a certain increment. Typical use case is e.g. the number of server connections, where Increment(1) is called on evert new connect and Increment(-1) on every disconnect.
func (*Reporter) Load ¶
func (r *Reporter) Load(_ context.Context, _ *pb.LoadRequest) (*pb.LoadResponse, error)
Load implements github.com/bsm/grpclb/grpclb_backend_v1.LoadReportServer