endpoints

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: MIT Imports: 6 Imported by: 0

README

internal/endpoints

Package endpoints is an internal package that tries to abstract the concept of a set of endpoints each with their own connection pool.

It currently only does "least active requests" load balancing. It would be nice to extend this and add support for marking endpoints as down temporarily if there are issues.

Right now only the thriftset package uses this code, but it would be interesting to implement a "least active requests" http load balancer using this code.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoEndpoints is returned when no endpoints are configured or available.
	ErrNoEndpoints = errors.New("endpoints: no endpoints configured or available")

	// ErrGetOnClosedEndpoint is returned by endpoint.GetConn if the endpoint
	// has been closed because it was removed from the watch.
	// This error is retryable.
	ErrGetOnClosedEndpoint = errors.New("endpoint closed")
)

Functions

This section is empty.

Types

type Conn

type Conn struct {
	Endpoint string

	// Conn is the item created by a Set.OpenSocket(host) call.
	Conn io.Closer

	// Data can be uses to store other info on the connection.
	// Used by the thriftset to store protocol and transport factories.
	Data interface{}
	// contains filtered or unexported fields
}

A Conn represents a connection to an endpoint.

func (*Conn) Close

func (c *Conn) Close() error

Close on this connection calls close on the underlying connection/closer.

func (*Conn) Release

func (c *Conn) Release() error

Release puts the connection back in the pool and allows others to use it.

type Pooler

type Pooler interface {
	// OpenConn creates the network connection to the host.
	// This could be tcp, udp, higher level thrift, etc.
	OpenConn(host string) (io.Closer, error)

	IdleTimeout() time.Duration
	MaxActivePerHost() int
	MaxIdlePerHost() int
}

Pooler can be throught of as a parent wrapper to a bunch of endpoints. It defines how connections are opened. And the general behavior of the pool.

type Set

type Set struct {
	Pooler Pooler
	// contains filtered or unexported fields
}

Set contains a list of endpoints and defines some operation on top of it.

func NewSet

func NewSet(pooler Pooler) *Set

NewSet creates a new endpoint set.

func (*Set) Close

func (s *Set) Close() error

Close will close all the hosts and thus all the connections for all the endpoints.

func (*Set) GetConn

func (s *Set) GetConn() (*Conn, error)

GetConn returns a connection from the endpoint with the current least amount of active connections.

func (*Set) SetEndpoints

func (s *Set) SetEndpoints(hosts []string) (added, removed int)

SetEndpoints will do a smart update of the endpoint lists. New hosts will be added, old ones will be removed.

Jump to

Keyboard shortcuts

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