chlb

package module
v0.0.0-...-3de4953 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2020 License: BSD-3-Clause Imports: 13 Imported by: 0

README

chlb

Consistent hash ring gRPC load balancer

This is a WIP and is very early in development. The aim is to provide a a way to route gRPC requests to consistent backends based on the fields of the request.

This is done by using a custom gRPC field option to tag which fields should be used in to hash when picking the backend. The load balancer then uses a consistent hash ring in order to route the requests.

Due to the load balancer interface, the balancer does not have access to the request and so cannot cannot route the request. This means that the hashing of the request occurs in an interceptor, and adds the result to a context which is then used for load balancing.

Documentation

Index

Constants

View Source
const Name = "consistent_hash_ring"

Variables

View Source
var UnaryInterceptor = func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
	if pbreq, ok := req.(proto.Message); ok {
		h, ok := Hash(pbreq)
		if ok {
			ctx = withHashVal(ctx, h)
		}
	}
	return invoker(ctx, method, req, reply, cc, opts...)
}

Functions

func Hash

func Hash(pb proto.Message) (int64, bool)

Hash only works at top level, will not search recursively. Need to check what we want to do if there are no hash fields

Types

This section is empty.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL