assigner

package
v0.23.5 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_internal_nanny_assigner_assigner_proto protoreflect.FileDescriptor

Functions

func AssignedResources

func AssignedResources(a *Assignment) []string

AssignedResources returns all the resources assigned to the entire key space in a given assignment.

func HasReplica

func HasReplica(s *Slice, resource string) bool

func Replicas

func Replicas(s *Slice) []string

Types

type AlgoConstraints

type AlgoConstraints struct {

	// Upper bound on the load allowed on any resource.
	MaxLoadLimitResource float64 `` /* 127-byte string literal not displayed */
	// Lower bound on the load allowed on any resource.
	MinLoadLimitResource float64 `` /* 127-byte string literal not displayed */
	// Any slice with replica load above this threshold should be split to enable
	// the algo to move slices around, in order to provide load balancing
	// guarantees.
	SplitThreshold float64 `protobuf:"fixed64,3,opt,name=split_threshold,json=splitThreshold,proto3" json:"split_threshold,omitempty"`
	// Any slice with replica load above this threshold should be replicated to
	// enable the algo to move slices around, in order to provide load balancing
	// guarantees.
	//
	// In practice, this threshold should be set to a value equal to or higher
	// than the splitThreshold, because it is preferred for a slice to be split
	// first.
	//
	// Also, a good algorithm should replicate a slice iff the slice has a single
	// key; otherwise splitting is always preferred because it incurs less churn.
	ReplicateThreshold float64 `protobuf:"fixed64,4,opt,name=replicate_threshold,json=replicateThreshold,proto3" json:"replicate_threshold,omitempty"`
	// Any slice with replica load below this threshold should be dereplicated if
	// the number of replicas is greater than 1.
	//
	// Dereplication creates more opportunities for merging slices, hence
	// controlling the assignment size.
	DereplicateThreshold float64 `protobuf:"fixed64,5,opt,name=dereplicate_threshold,json=dereplicateThreshold,proto3" json:"dereplicate_threshold,omitempty"`
	// Maximum number of slices a resource should be assigned in a given
	// assignment. Note that this is just a hint, because in reality the algorithm
	// might not be able to provide a hard guarantee.
	//
	// The role of this constraint is to ensure that the number of slices in an
	// assignment is bounded.
	MaxNumSlicesResourceHint int64 `` /* 140-byte string literal not displayed */
	// contains filtered or unexported fields
}

AlgoConstraints contains various constraints needed by the routing algos to generate assignments.

func (*AlgoConstraints) Descriptor deprecated

func (*AlgoConstraints) Descriptor() ([]byte, []int)

Deprecated: Use AlgoConstraints.ProtoReflect.Descriptor instead.

func (*AlgoConstraints) GetDereplicateThreshold

func (x *AlgoConstraints) GetDereplicateThreshold() float64

func (*AlgoConstraints) GetMaxLoadLimitResource

func (x *AlgoConstraints) GetMaxLoadLimitResource() float64

func (*AlgoConstraints) GetMaxNumSlicesResourceHint

func (x *AlgoConstraints) GetMaxNumSlicesResourceHint() int64

func (*AlgoConstraints) GetMinLoadLimitResource

func (x *AlgoConstraints) GetMinLoadLimitResource() float64

func (*AlgoConstraints) GetReplicateThreshold

func (x *AlgoConstraints) GetReplicateThreshold() float64

func (*AlgoConstraints) GetSplitThreshold

func (x *AlgoConstraints) GetSplitThreshold() float64

func (*AlgoConstraints) ProtoMessage

func (*AlgoConstraints) ProtoMessage()

func (*AlgoConstraints) ProtoReflect

func (x *AlgoConstraints) ProtoReflect() protoreflect.Message

func (*AlgoConstraints) Reset

func (x *AlgoConstraints) Reset()

func (*AlgoConstraints) String

func (x *AlgoConstraints) String() string

type Algorithm

type Algorithm func(currAssignment *Assignment) (*Assignment, error)

Algorithm takes the current assignment, and returns a new assignment. The returned assignment should have a larger version than the current assignment.

type Assigner

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

Assigner generates routing information for a set of managed Kubernetes ReplicaSets.

In the current implementation, the assigner generates new routing information when (1) new components become managed by the ReplicaSet, or (2) the load changes for a given Pod, or (3) the ReplicaSet acquires new Pods.

func NewAssigner

func NewAssigner(
	ctx context.Context,
	store store.Store,
	logger *slog.Logger,
	algo Algorithm,
	updateRoutingInterval time.Duration,
	getHealthyPods func(ctx context.Context, cfg *config.GKEConfig, replicaSet string) ([]*nanny.Pod, error)) *Assigner

func (*Assigner) GetComponentsToStart

func (a *Assigner) GetComponentsToStart(req *nanny.GetComponentsRequest) (*nanny.GetComponentsReply, error)

GetComponentsToStart returns the set of components the given replica set should start. This call will block if there have been no component changes since the last call to GetComponentsToStart().

func (*Assigner) GetReplicaSets added in v0.22.1

GetReplicaSets returns the state of all Kubernetes ReplicaSets for an application version or a collection of applications and their versions.

func (*Assigner) GetRoutingInfo

func (a *Assigner) GetRoutingInfo(req *nanny.GetRoutingRequest) (*nanny.GetRoutingReply, error)

GetRoutingInfo returns the routing information for a given component. This call will block if there have been no routing changes since the last call to GetRoutingInfo().

func (*Assigner) RegisterComponent added in v0.22.1

func (a *Assigner) RegisterComponent(ctx context.Context, req *nanny.ActivateComponentRequest) error

RegisterComponent registers a given activated component.

func (*Assigner) RegisterListener

func (a *Assigner) RegisterListener(ctx context.Context, req *nanny.ExportListenerRequest) error

RegisterListener registers a given instantiated listener.

func (*Assigner) StopAppVersion added in v0.22.1

func (a *Assigner) StopAppVersion(ctx context.Context, app, appVersion string) error

StopAppVersion stops all work for the given app version and cleans up its state.

If the method returns an error, it should be invoked again as the operation likely hasn't been fully applied.

TODO(mwhittaker): The store deletions below race any operations that write to the store. We should make sure that every operation that could potentially write to the store first checks to see if the version has been stopped. This is complicated by the fact that the store writes are spread between the assigner, manager, the gke deployer, and the gke-local deployer.

type Assignment

type Assignment struct {
	Version            uint64           `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"`
	Slices             []*Slice         `protobuf:"bytes,2,rep,name=slices,proto3" json:"slices,omitempty"`
	CandidateResources map[string]bool  `` /* 204-byte string literal not displayed */
	Constraints        *AlgoConstraints `protobuf:"bytes,4,opt,name=constraints,proto3" json:"constraints,omitempty"`
	Stats              *Statistics      `protobuf:"bytes,5,opt,name=stats,proto3" json:"stats,omitempty"`
	// contains filtered or unexported fields
}

Assignment is a wrapper class that creates and decodes assignment protos.

func EqualDistributionAlgorithm

func EqualDistributionAlgorithm(currAssignment *Assignment) (*Assignment, error)

EqualDistributionAlgorithm is an implementation of a sharding algorithm that distributes the entire key space approximately equally across all healthy resources.

The algorithm is as follows: - split the entire key space in a number of slices that is more likely to spread uniformly the key space among all healthy resources

- distribute the slices round robin across all healthy resources

func FromProto

func FromProto(assignmentP *protos.Assignment) (*Assignment, error)

FromProto returns an assignment from an assignment proto.

func LoadBasedAlgorithm

func LoadBasedAlgorithm(currAssignment *Assignment) (*Assignment, error)

LoadBasedAlgorithm is an implementation of a sharding algorithm that attempts to minimize the maximum load on any given resource.

func (*Assignment) Descriptor deprecated

func (*Assignment) Descriptor() ([]byte, []int)

Deprecated: Use Assignment.ProtoReflect.Descriptor instead.

func (*Assignment) GetCandidateResources

func (x *Assignment) GetCandidateResources() map[string]bool

func (*Assignment) GetConstraints

func (x *Assignment) GetConstraints() *AlgoConstraints

func (*Assignment) GetSlices

func (x *Assignment) GetSlices() []*Slice

func (*Assignment) GetStats

func (x *Assignment) GetStats() *Statistics

func (*Assignment) GetVersion

func (x *Assignment) GetVersion() uint64

func (*Assignment) ProtoMessage

func (*Assignment) ProtoMessage()

func (*Assignment) ProtoReflect

func (x *Assignment) ProtoReflect() protoreflect.Message

func (*Assignment) Reset

func (x *Assignment) Reset()

func (*Assignment) String

func (x *Assignment) String() string

type LoadTracker

type LoadTracker struct {

	// Slice load on a given resource.
	PerResourceLoad float64 `protobuf:"fixed64,1,opt,name=per_resource_load,json=perResourceLoad,proto3" json:"per_resource_load,omitempty"`
	// Resources to which the slice is assigned.
	Resources map[string]bool `` /* 160-byte string literal not displayed */
	// Distribution of the load along split points.
	Distribution map[uint64]float64 `` /* 168-byte string literal not displayed */
	// contains filtered or unexported fields
}

loadTracker tracks load information for a given slice across all the assigned resources.

Note that for a replicated slice (len(resources) > 1):

  • perResourceload contains the total load as reported by the latest resource that has the slice assigned
  • distribution contains the load distribution along split points for the given replica

Most of the slices will have a single replica; ideally, only hot keys should be replicated. Given that our load metric is req/s it is fair to assume that the load is evenly distributed across the replicas of a slice, hence the load, and the load distribution for a given replica should be representative for all replicas. Otherwise, it is challenging for the weavelets to report exactly the same split points for all replicas, and challenging for the assigner to compute split points that make sense across all replicas.

TODO(rgrandl): mwhittaker@ has an interesting idea. Instead of taking the latest load report, we take the load report with the largest number of requests received. That way if a resource was down for some reason or lagging behind in an assignment and reports an almost empty load report, we won't use it.

TODO(rgrandl): revisit these decisions if we ever decide to support a different load metric.

func (*LoadTracker) Descriptor deprecated

func (*LoadTracker) Descriptor() ([]byte, []int)

Deprecated: Use LoadTracker.ProtoReflect.Descriptor instead.

func (*LoadTracker) GetDistribution

func (x *LoadTracker) GetDistribution() map[uint64]float64

func (*LoadTracker) GetPerResourceLoad

func (x *LoadTracker) GetPerResourceLoad() float64

func (*LoadTracker) GetResources

func (x *LoadTracker) GetResources() map[string]bool

func (*LoadTracker) ProtoMessage

func (*LoadTracker) ProtoMessage()

func (*LoadTracker) ProtoReflect

func (x *LoadTracker) ProtoReflect() protoreflect.Message

func (*LoadTracker) Reset

func (x *LoadTracker) Reset()

func (*LoadTracker) String

func (x *LoadTracker) String() string

type ReplicaSetState added in v0.2.0

type ReplicaSetState struct {
	ReplicaSet *nanny.ReplicaSet `protobuf:"bytes,1,opt,name=replica_set,json=replicaSet,proto3" json:"replica_set,omitempty"`
	// Routing assignments for all components that use routing/sharding, keyed
	// by component name.
	RoutingAssignments map[string]*Assignment `` /* 203-byte string literal not displayed */
	// contains filtered or unexported fields
}

ReplicaSetState stores information about a Kubernetes ReplicaSet, i.e., a set of pods that host the same set of components.

func (*ReplicaSetState) Descriptor deprecated added in v0.2.0

func (*ReplicaSetState) Descriptor() ([]byte, []int)

Deprecated: Use ReplicaSetState.ProtoReflect.Descriptor instead.

func (*ReplicaSetState) GetReplicaSet added in v0.22.1

func (x *ReplicaSetState) GetReplicaSet() *nanny.ReplicaSet

func (*ReplicaSetState) GetRoutingAssignments added in v0.22.1

func (x *ReplicaSetState) GetRoutingAssignments() map[string]*Assignment

func (*ReplicaSetState) ProtoMessage added in v0.2.0

func (*ReplicaSetState) ProtoMessage()

func (*ReplicaSetState) ProtoReflect added in v0.2.0

func (x *ReplicaSetState) ProtoReflect() protoreflect.Message

func (*ReplicaSetState) Reset added in v0.2.0

func (x *ReplicaSetState) Reset()

func (*ReplicaSetState) String added in v0.2.0

func (x *ReplicaSetState) String() string

type Slice

type Slice struct {
	StartInclusive *SliceKey    `protobuf:"bytes,1,opt,name=start_inclusive,json=startInclusive,proto3" json:"start_inclusive,omitempty"`
	EndExclusive   *SliceKey    `protobuf:"bytes,2,opt,name=end_exclusive,json=endExclusive,proto3" json:"end_exclusive,omitempty"`
	LoadInfo       *LoadTracker `protobuf:"bytes,3,opt,name=load_info,json=loadInfo,proto3" json:"load_info,omitempty"`
	// contains filtered or unexported fields
}

Slice contains the allocation of a routing key range to a set of resources.

The range covers [startInclusive, endExclusive).

func (*Slice) Descriptor deprecated

func (*Slice) Descriptor() ([]byte, []int)

Deprecated: Use Slice.ProtoReflect.Descriptor instead.

func (*Slice) GetEndExclusive

func (x *Slice) GetEndExclusive() *SliceKey

func (*Slice) GetLoadInfo

func (x *Slice) GetLoadInfo() *LoadTracker

func (*Slice) GetStartInclusive

func (x *Slice) GetStartInclusive() *SliceKey

func (*Slice) ProtoMessage

func (*Slice) ProtoMessage()

func (*Slice) ProtoReflect

func (x *Slice) ProtoReflect() protoreflect.Message

func (*Slice) Reset

func (x *Slice) Reset()

func (*Slice) String

func (x *Slice) String() string

type SliceKey

type SliceKey struct {
	Val uint64 `protobuf:"varint,1,opt,name=val,proto3" json:"val,omitempty"`
	// contains filtered or unexported fields
}

SliceKey is an abstraction for routing keys used in slices.

func (*SliceKey) Descriptor deprecated

func (*SliceKey) Descriptor() ([]byte, []int)

Deprecated: Use SliceKey.ProtoReflect.Descriptor instead.

func (*SliceKey) GetVal

func (x *SliceKey) GetVal() uint64

func (*SliceKey) ProtoMessage

func (*SliceKey) ProtoMessage()

func (*SliceKey) ProtoReflect

func (x *SliceKey) ProtoReflect() protoreflect.Message

func (*SliceKey) Reset

func (x *SliceKey) Reset()

func (*SliceKey) String

func (x *SliceKey) String() string

type Statistics

type Statistics struct {
	SplitOps              int64 `protobuf:"varint,1,opt,name=splitOps,proto3" json:"splitOps,omitempty"`
	MergeOps              int64 `protobuf:"varint,2,opt,name=mergeOps,proto3" json:"mergeOps,omitempty"`
	ReplicateOps          int64 `protobuf:"varint,3,opt,name=replicateOps,proto3" json:"replicateOps,omitempty"`
	DereplicateOps        int64 `protobuf:"varint,4,opt,name=dereplicateOps,proto3" json:"dereplicateOps,omitempty"`
	MoveDueToBalanceOps   int64 `protobuf:"varint,5,opt,name=moveDueToBalanceOps,proto3" json:"moveDueToBalanceOps,omitempty"`
	MoveDueToUnhealthyOps int64 `protobuf:"varint,6,opt,name=moveDueToUnhealthyOps,proto3" json:"moveDueToUnhealthyOps,omitempty"`
	// contains filtered or unexported fields
}

Statistics contains various statistics for a given assignment.

func (*Statistics) Descriptor deprecated

func (*Statistics) Descriptor() ([]byte, []int)

Deprecated: Use Statistics.ProtoReflect.Descriptor instead.

func (*Statistics) GetDereplicateOps

func (x *Statistics) GetDereplicateOps() int64

func (*Statistics) GetMergeOps

func (x *Statistics) GetMergeOps() int64

func (*Statistics) GetMoveDueToBalanceOps

func (x *Statistics) GetMoveDueToBalanceOps() int64

func (*Statistics) GetMoveDueToUnhealthyOps

func (x *Statistics) GetMoveDueToUnhealthyOps() int64

func (*Statistics) GetReplicateOps

func (x *Statistics) GetReplicateOps() int64

func (*Statistics) GetSplitOps

func (x *Statistics) GetSplitOps() int64

func (*Statistics) ProtoMessage

func (*Statistics) ProtoMessage()

func (*Statistics) ProtoReflect

func (x *Statistics) ProtoReflect() protoreflect.Message

func (*Statistics) Reset

func (x *Statistics) Reset()

func (*Statistics) String

func (x *Statistics) String() string

Jump to

Keyboard shortcuts

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