Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LoadBalancer ¶
type LoadBalancer interface { Handler(w http.ResponseWriter, r *http.Request) AsyncHealthChecks() }
LoadBalancer common inteface
type Node ¶
type Node struct { Address string `mapstructure:"address"` Port string `mapstructure:"port"` HealthURL string `mapstructure:"health"` ActiveConnections int // contains filtered or unexported fields }
Node ...
func (*Node) CheckHealth ¶
CheckHealth manually performs a health check at the node's health url. It returns true if healthy, false if unhealthy. Note: This does not set the node's `healthy:bool` field, as that's the purview of the orchestrating load-balancer.
func (*Node) Handler ¶
Handler forwards request to node. Based on https://stackoverflow.com/a/34725635
func (*Node) SetHealthy ¶
func (n *Node) SetHealthy()
SetHealthy sets the node to "healthy", meaning it is perceived to be able to successfully process requests.
func (*Node) SetUnhealthy ¶
func (n *Node) SetUnhealthy()
SetUnhealthy sets the node to "unhealthy", meaning it is not perceived to be able to successfully process requests.
type RoundRobin ¶
type RoundRobin struct { Nodes []*Node // contains filtered or unexported fields }
RoundRobin struct contains: - A slice of node pointers - The current "active" node index - The maximum number of Healthy nodes
func NewRoundRobin ¶
func NewRoundRobin(nodes []*Node) *RoundRobin
NewRoundRobin creates a new RoundRobin load balancer.
func (*RoundRobin) AsyncHealthChecks ¶
func (rr *RoundRobin) AsyncHealthChecks()
AsyncHealthChecks performs health checks in the background at an interval set by asyncHealthChecksTimeSeconds.
func (*RoundRobin) Handler ¶
func (rr *RoundRobin) Handler(w http.ResponseWriter, r *http.Request)
Handler selects a node via round robin and passes the request to the selected node.
type TwoChoice ¶
TwoChoice struct contains: - A slice of node pointers - A set of indexes to healthy nodes (as a map) - A set of indexes to unhealthy ndoes (as a map)
func NewTwoChoice ¶
NewTwoChoice creates a new TwoChoice load balancer
func (*TwoChoice) AsyncHealthChecks ¶
func (tc *TwoChoice) AsyncHealthChecks()
AsyncHealthChecks performs health checks in the background at an interval set by asyncHealthChecksTimeSeconds.
func (*TwoChoice) Handler ¶
func (tc *TwoChoice) Handler(w http.ResponseWriter, r *http.Request)
Handler selects a node via random two choice and passes the request to the selected node. See https://www.nginx.com/blog/nginx-power-of-two-choices-load-balancing-algorithm/