scaling

package
v0.0.0-...-b22cb63 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 11 Imported by: 28

Documentation

Index

Constants

View Source
const (
	// DefaultMinReplicas is the minimal amount of replicas for a service.
	DefaultMinReplicas = 1

	// DefaultMaxReplicas is the amount of replicas a service will auto-scale up to.
	DefaultMaxReplicas = 5

	// DefaultScalingFactor is the defining proportion for the scaling increments.
	DefaultScalingFactor = 10

	DefaultTypeScale = "rps"

	// MinScaleLabel label indicating min scale for a function
	MinScaleLabel = "com.openfaas.scale.min"

	// MaxScaleLabel label indicating max scale for a function
	MaxScaleLabel = "com.openfaas.scale.max"

	// ScalingFactorLabel label indicates the scaling factor for a function
	ScalingFactorLabel = "com.openfaas.scale.factor"
)

Variables

This section is empty.

Functions

func MakeHorizontalScalingHandler

func MakeHorizontalScalingHandler(next http.HandlerFunc) http.HandlerFunc

Types

type CachedFunctionQuery

type CachedFunctionQuery struct {
	// contains filtered or unexported fields
}

func (*CachedFunctionQuery) Get

func (*CachedFunctionQuery) GetAnnotations

func (c *CachedFunctionQuery) GetAnnotations(name string, namespace string) (annotations map[string]string, err error)

type Call

type Call struct {
	// contains filtered or unexported fields
}

type FunctionCache

type FunctionCache struct {
	Cache  map[string]*FunctionMeta
	Expiry time.Duration
	Sync   sync.RWMutex
}

FunctionCache provides a cache of Function replica counts

func (*FunctionCache) Get

func (fc *FunctionCache) Get(functionName, namespace string) (ServiceQueryResponse, bool)

Get replica count for functionName

func (*FunctionCache) Set

func (fc *FunctionCache) Set(functionName, namespace string, queryRes ServiceQueryResponse)

Set replica count for functionName

type FunctionCacher

type FunctionCacher interface {
	Set(functionName, namespace string, serviceQueryResponse ServiceQueryResponse)
	Get(functionName, namespace string) (ServiceQueryResponse, bool)
}

FunctionCacher queries functions and caches the results

func NewFunctionCache

func NewFunctionCache(cacheExpiry time.Duration) FunctionCacher

NewFunctionCache creates a function cache to query function metadata

type FunctionMeta

type FunctionMeta struct {
	LastRefresh          time.Time
	ServiceQueryResponse ServiceQueryResponse
}

FunctionMeta holds the last refresh and any other meta-data needed for caching.

func (*FunctionMeta) Expired

func (fm *FunctionMeta) Expired(expiry time.Duration) bool

Expired find out whether the cache item has expired with the given expiry duration from when it was stored.

type FunctionQuery

type FunctionQuery interface {
	Get(name string, namespace string) (ServiceQueryResponse, error)
	GetAnnotations(name string, namespace string) (annotations map[string]string, err error)
}

func NewCachedFunctionQuery

func NewCachedFunctionQuery(cache FunctionCacher, serviceQuery ServiceQuery) FunctionQuery

type FunctionScaleResult

type FunctionScaleResult struct {
	Available bool
	Error     error
	Found     bool
	Duration  time.Duration
}

FunctionScaleResult holds the result of scaling from zero

type FunctionScaler

type FunctionScaler struct {
	Cache        FunctionCacher
	Config       ScalingConfig
	SingleFlight *singleflight.Group
}

FunctionScaler scales from zero

func NewFunctionScaler

func NewFunctionScaler(config ScalingConfig, functionCacher FunctionCacher) FunctionScaler

NewFunctionScaler create a new scaler with the specified ScalingConfig

func (*FunctionScaler) Scale

func (f *FunctionScaler) Scale(functionName, namespace string) FunctionScaleResult

Scale scales a function from zero replicas to 1 or the value set in the minimum replicas metadata

type ScalingConfig

type ScalingConfig struct {
	// MaxPollCount attempts to query a function before giving up
	MaxPollCount uint

	// FunctionPollInterval delay or interval between polling a function's
	// readiness status
	FunctionPollInterval time.Duration

	// CacheExpiry life-time for a cache entry before considering invalid
	CacheExpiry time.Duration

	// ServiceQuery queries available/ready replicas for function
	ServiceQuery ServiceQuery

	// SetScaleRetries is the number of times to try scaling a function before
	// giving up due to errors
	SetScaleRetries uint
}

ScalingConfig for scaling behaviours

type ServiceQuery

type ServiceQuery interface {
	GetReplicas(service, namespace string) (response ServiceQueryResponse, err error)
	SetReplicas(service, namespace string, count uint64) error
}

ServiceQuery provides interface for replica querying/setting

type ServiceQueryResponse

type ServiceQueryResponse struct {
	Replicas          uint64
	MaxReplicas       uint64
	MinReplicas       uint64
	ScalingFactor     uint64
	AvailableReplicas uint64
	Annotations       *map[string]string
}

ServiceQueryResponse response from querying a function status

type SingleFlight

type SingleFlight struct {
	// contains filtered or unexported fields
}

func NewSingleFlight

func NewSingleFlight() *SingleFlight

func (*SingleFlight) Do

func (s *SingleFlight) Do(key string, f func() (interface{}, error)) (interface{}, error)

type SingleFlightResult

type SingleFlightResult struct {
	Result interface{}
	Error  error
}

Jump to

Keyboard shortcuts

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