limit

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SmallResourceThreshold is used to represent a resource which can be regarded as a small resource once the size is small than it.
	SmallResourceThreshold int64 = 20
	// Unlimited is used to control the container limit. Here uses a big enough number to represent unlimited.
	Unlimited = float64(100000000)
)
View Source
const (
	// EmptyResourceApproximateSize is the resource approximate size of an empty resource
	// (heartbeat size <= 1MB).
	EmptyResourceApproximateSize = 1
)

Variables

View Source
var ResourceInfluence = map[Type]int64{
	AddPeer:    1000,
	RemovePeer: 1000,
}

ResourceInfluence represents the influence of a operator step, which is used by container limit.

View Source
var SmallResourceInfluence = map[Type]int64{
	AddPeer:    200,
	RemovePeer: 200,
}

SmallResourceInfluence represents the influence of a operator step when the resource size is smaller than smallResourceThreshold, which is used by container limit.

View Source
var TypeNameValue = map[string]Type{
	"add-peer":    AddPeer,
	"remove-peer": RemovePeer,
}

TypeNameValue indicates the name of container limit type and the enum value

Functions

This section is empty.

Types

type ContainerLimit

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

ContainerLimit limits the operators of a container

func NewContainerLimit

func NewContainerLimit(ratePerSec float64, resourceInfluence int64) *ContainerLimit

NewContainerLimit returns a ContainerLimit object

func (*ContainerLimit) Available

func (l *ContainerLimit) Available() int64

Available returns the number of available tokens

func (*ContainerLimit) Rate

func (l *ContainerLimit) Rate() float64

Rate returns the fill rate of the bucket, in tokens per second.

func (*ContainerLimit) Take

func (l *ContainerLimit) Take(count int64) time.Duration

Take takes count tokens from the bucket without blocking.

type Scene

type Scene struct {
	Idle   int
	Low    int
	Normal int
	High   int
}

Scene defines the container limitation on difference scenes Idle/Low/Normal/High indicates the load of the cluster, it is defined in cluster.State. See the details there for how to calculate the load. The values here defines the container-limit for each load. For example: Idle = 60, means that change the container-limit to 60 when the cluster is idle.

func DefaultScene

func DefaultScene(limitType Type) *Scene

DefaultScene returns Scene object with default values

type Type

type Type int

Type indicates the type of container limit

const (
	// AddPeer indicates the type of container limit that limits the adding peer rate
	AddPeer Type = iota
	// RemovePeer indicates the type of container limit that limits the removing peer rate
	RemovePeer
)

func (Type) String

func (t Type) String() string

String returns the representation of the Type

Jump to

Keyboard shortcuts

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