Package loadbalancer implements load balancer algorithms that are applied by the proxy.
The roundRobin algorithm does proxy requests round robin to backend endpoints. It has a mutex to update the index and will start at a random index
The random algorithm does proxy requests to random backend endpoints.
The consistentHash algorithm choose backend endpoints by hashing client data with hash function fnv.New32. The client data is the client IP, which will be looked up from X-Forwarded-For header with remote IP as the fallback.
r1: * -> <roundRobin, "http://127.0.0.1:9998", "http://127.0.0.1:9997">; r2: * -> <consistentHash, "http://127.0.0.1:9998", "http://127.0.0.1:9997">; r3: * -> <random, "http://127.0.0.1:9998", "http://127.0.0.1:9997">;
Package loadbalancer also implements health checking of pool members for a group of routes, if backend calls are reported to the loadbalancer.
The backend task has initialized correctly and is processing requests.
Refusing connections (dead)
The backend task is unresponsive. This can happen because the task is starting up or shutting down, or because the backend is in an abnormal state (though it would be rare for a backend to stop listening on its port if it is not shutting down).
Lame duck (unhealthy)
The backend task is listening on its port and can serve, but is explicitly asking clients to stop sending requests.
NewAlgorithmProvider creates a routing.PostProcessor used to initialize the algorithm of load balancing routes.
HealthcheckPostProcessor wraps the LB structure implementing the routing.PostProcessor interface for filtering healthy routes.
Do filters the routes with healthy backends.
LB stores state of routes, which were reported dead or unhealthy by other packages, f.e. proxy. Based on reported routes LB starts to do active healthchecks to find if a route becomes haelthy again. Use NewLB() to create an LB
NewLB creates a new LB and starts background jobs for populating backends to check added routes and checking them every healthcheckInterval.
AddHealthcheck can be used to report unhealthy routes, which loadbalancer will use to do active healthchecking and dataclients can ask the loadbalancer to filter unhealhyt or dead routes.
FilterHealthyMemberRoutes can be used by dataclients to filter for routes that have known not healthy backends.