Documentation ¶
Index ¶
- Constants
- func ClearRules() error
- func IsValidRule(rule *Rule) error
- func LoadRules(rules []*Rule) (bool, error)
- func RemoveTrafficShapingGenerator(cb ControlBehavior) error
- func SetTrafficShapingGenerator(cb ControlBehavior, generator TrafficControllerGenFunc) error
- type ConcurrencyStatSlot
- type ControlBehavior
- type MetricType
- type ParamKind
- type ParamsMetric
- type Rule
- type Slot
- type SpecificValue
- type TrafficControllerGenFunc
- type TrafficShapingController
Constants ¶
const ( ConcurrencyMaxCount = 4000 ParamsCapacityBase = 4000 ParamsMaxCapacity = 20000 )
Variables ¶
This section is empty.
Functions ¶
func IsValidRule ¶
func LoadRules ¶
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 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 (*Rule) IsStatReusable ¶
IsStatReusable checks whether current rule is "statistically" equal to the given rule.
func (*Rule) ResourceName ¶
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 }