hotspot

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConcurrencyMaxCount = 4000
	ParamsCapacityBase  = 4000
	ParamsMaxCapacity   = 20000
)

Variables

This section is empty.

Functions

func ClearRules

func ClearRules() error

ClearRules clears all parameter flow rules.

func IsValidRule

func IsValidRule(rule *Rule) error

func LoadRules

func LoadRules(rules []*Rule) (bool, error)

LoadRules replaces old rules with the given hotspot parameter flow control rules. Return value:

bool: indicates whether the internal map has been changed; error: indicates whether occurs the error.

func RemoveTrafficShapingGenerator

func RemoveTrafficShapingGenerator(cb ControlBehavior) error

func SetTrafficShapingGenerator

func SetTrafficShapingGenerator(cb ControlBehavior, generator TrafficControllerGenFunc) error

SetTrafficShapingGenerator sets the traffic controller generator for the given control behavior. Note that modifying the generator of default control behaviors is not allowed.

Types

type ConcurrencyStatSlot

type ConcurrencyStatSlot struct {
}

ConcurrencyStatSlot is to record the Concurrency statistic for all arguments

func (*ConcurrencyStatSlot) OnCompleted

func (c *ConcurrencyStatSlot) OnCompleted(ctx *base.EntryContext)

func (*ConcurrencyStatSlot) OnEntryBlocked

func (c *ConcurrencyStatSlot) OnEntryBlocked(ctx *base.EntryContext, blockError *base.BlockError)

func (*ConcurrencyStatSlot) OnEntryPassed

func (c *ConcurrencyStatSlot) OnEntryPassed(ctx *base.EntryContext)

type ControlBehavior

type ControlBehavior int8

ControlBehavior indicates the traffic shaping behaviour.

const (
	Reject ControlBehavior = iota
	Throttling
)

func (ControlBehavior) String

func (t ControlBehavior) String() string

type MetricType

type MetricType int8

MetricType represents the target metric type.

const (
	// Concurrency represents concurrency count.
	Concurrency MetricType = iota
	// QPS represents request count per second.
	QPS
)

func (MetricType) String

func (t MetricType) String() string

type ParamKind

type ParamKind int

ParamKind represents the Param kind.

const (
	KindInt ParamKind = iota
	KindString
	KindBool
	KindFloat64
	KindSum
)

func (ParamKind) String

func (t ParamKind) String() string

type ParamsMetric

type ParamsMetric struct {
	// RuleTimeCounter records the last added token timestamp.
	RuleTimeCounter cache.ConcurrentCounterCache
	// RuleTokenCounter records the number of tokens.
	RuleTokenCounter cache.ConcurrentCounterCache
	// ConcurrencyCounter records the real-time concurrency.
	ConcurrencyCounter cache.ConcurrentCounterCache
}

ParamsMetric carries real-time counters for frequent ("hot spot") parameters.

For each cache map, the key is the parameter value, while the value is the counter.

type Rule

type Rule struct {
	// ID is the unique id
	ID string `json:"id,omitempty"`
	// Resource is the resource name
	Resource        string          `json:"resource"`
	MetricType      MetricType      `json:"metricType"`
	ControlBehavior ControlBehavior `json:"controlBehavior"`
	// ParamIndex is the index in context arguments slice.
	ParamIndex int     `json:"paramIndex"`
	Threshold  float64 `json:"threshold"`
	// MaxQueueingTimeMs only take effect in both Throttling ControlBehavior and QPS MetricType
	MaxQueueingTimeMs int64 `json:"maxQueueingTimeMs"`
	// BurstCount is the silent count
	// Only take effect in both Reject ControlBehavior and QPS MetricType
	BurstCount int64 `json:"burstCount"`
	// DurationInSec is the time interval in statistic
	// Only take effect in QPS MetricType
	DurationInSec int64 `json:"durationInSec"`
	// ParamsMaxCapacity is the max capacity of cache statistic
	ParamsMaxCapacity int64 `json:"paramsMaxCapacity"`
	// SpecificItems indicates the special threshold for specific value
	SpecificItems []SpecificValue `json:"specificItems"`
}

Rule represents the hotspot(frequent) parameter flow control rule

func GetRules

func GetRules(res string) []*Rule

GetRules returns existing rules of the given resource.

func (*Rule) Equals

func (r *Rule) Equals(newRule *Rule) bool

Equals checks whether current rule is consistent with the given rule.

func (*Rule) IsStatReusable

func (r *Rule) IsStatReusable(newRule *Rule) bool

IsStatReusable checks whether current rule is "statistically" equal to the given rule.

func (*Rule) ResourceName

func (r *Rule) ResourceName() string

func (*Rule) String

func (r *Rule) String() string

type Slot

type Slot struct {
}

func (*Slot) Check

func (s *Slot) Check(ctx *base.EntryContext) *base.TokenResult

type SpecificValue

type SpecificValue struct {
	ValKind   ParamKind `json:"valKind"`
	ValStr    string    `json:"valStr"`
	Threshold int64     `json:"threshold"`
}

SpecificValue indicates the specific param, contain the supported param kind and concrete value.

func (*SpecificValue) String

func (s *SpecificValue) String() string

type TrafficControllerGenFunc

type TrafficControllerGenFunc func(r *Rule, reuseMetric *ParamsMetric) TrafficShapingController

TrafficControllerGenFunc represents the TrafficShapingController generator function of a specific control behavior.

type TrafficShapingController

type TrafficShapingController interface {
	PerformChecking(arg interface{}, acquireCount int64) *base.TokenResult

	BoundParamIndex() int

	BoundMetric() *ParamsMetric

	BoundRule() *Rule
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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