Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertToDec(val float64) sdk.Dec
- func GetLatencyFactor(cu uint64) float64
- type AvailabilityScoreStore
- type Config
- type LatencyScoreStore
- type Option
- type ScoreStore
- func (ss *ScoreStore) GetConfig() Config
- func (ss *ScoreStore) GetDenom() float64
- func (ss *ScoreStore) GetLastUpdateTime() time.Time
- func (ss *ScoreStore) GetName() string
- func (ss *ScoreStore) GetNum() float64
- func (ss *ScoreStore) Resolve() (float64, error)
- func (ss *ScoreStore) String() string
- func (ss *ScoreStore) Update(sample float64, sampleTime time.Time) error
- func (ss *ScoreStore) UpdateConfig(opts ...Option) error
- func (ss *ScoreStore) Validate() error
- type ScoreStorer
- type SyncScoreStore
Constants ¶
const ( DefaultHalfLifeTime = time.Hour MaxHalfTime = 3 * time.Hour DefaultWeight float64 = 1 ProbeUpdateWeight float64 = 0.25 RelayUpdateWeight float64 = 1 // TODO: find actual numbers from info of latencies of high/mid/low CU from "stats.lavanet.xyz". // Do a distribution and find average factor to multiply the failure cost by. DefaultCuLatencyFactor = LowCuLatencyFactor HighCuLatencyFactor = 0.01 // for cu > HighCuThreshold MidCuLatencyFactor = 0.1 // for MidCuThreshold < cu < HighCuThreshold LowCuLatencyFactor = float64(1) // for cu < MidCuThreshold HighCuThreshold = uint64(100) MidCuThreshold = uint64(50) )
const ( DecPrecision int64 = 8 InitialDataStaleness = 24 * time.Hour )
const ( DefaultLatencyNum float64 = 0.01 DefaultSyncNum float64 = 0.1 DefaultAvailabilityNum float64 = 1 LatencyScoreType = "latency" SyncScoreType = "sync" AvailabilityScoreType = "availability" TotalScoreType = "total" // Worst score results for each QoS excellence metric for truncation WorstLatencyScore float64 = 30 // seconds WorstSyncScore float64 = 20 * 60 // seconds WorstAvailabilityScore float64 = 0.00001 // very small value to avoid score = 0 )
Variables ¶
var TimeConflictingScoresError = sdkerrors.New("TimeConflictingScoreStoreError", 5183, "ScoreStore has a more recent sample than the one provided")
Functions ¶
func ConvertToDec ¶
func GetLatencyFactor ¶
GetLatencyFactor returns the appropriate latency factor by the CU amount
Types ¶
type AvailabilityScoreStore ¶
type AvailabilityScoreStore struct {
*ScoreStore
}
func (*AvailabilityScoreStore) Resolve ¶
func (as *AvailabilityScoreStore) Resolve() (float64, error)
type Config ¶
type LatencyScoreStore ¶
type LatencyScoreStore struct {
*ScoreStore
}
type Option ¶
type Option func(*Config)
Option is used as a generic and elegant way to configure a new ScoreStore
func WithDecayHalfLife ¶
func WithLatencyCuFactor ¶
func WithWeight ¶
type ScoreStore ¶
type ScoreStore struct {
Name string
Num float64 // using float64 and not math/big for performance
Denom float64
Time time.Time
Config Config
// contains filtered or unexported fields
}
ScoreStore is a decaying weighted average object that is used to collect providers performance metrics samples (see QoS excellence comment below). These are used to calculate the providers QoS excellence score, used by the provider optimizer when choosing providers to be paired with a consumer.
ScoreStore holds a score's numerator and denominator, last update timestamp, and a configuration object. When a ScoreStore updates it uses a decay exponent to lower the weight of old average samples and a weight parameter to determine the influence of the new sample.
Resolving the ScoreStore's num and denom means to divide the num by the denom to get the score. Keeping the score as a fracture helps calculating and updating weighted average calculations on the go.
func (*ScoreStore) GetConfig ¶
func (ss *ScoreStore) GetConfig() Config
func (*ScoreStore) GetDenom ¶
func (ss *ScoreStore) GetDenom() float64
func (*ScoreStore) GetLastUpdateTime ¶
func (ss *ScoreStore) GetLastUpdateTime() time.Time
func (*ScoreStore) GetName ¶
func (ss *ScoreStore) GetName() string
func (*ScoreStore) GetNum ¶
func (ss *ScoreStore) GetNum() float64
func (*ScoreStore) Resolve ¶
func (ss *ScoreStore) Resolve() (float64, error)
Resolve resolves the ScoreStore's frac by dividing the numerator by the denominator
func (*ScoreStore) String ¶
func (ss *ScoreStore) String() string
String prints a ScoreStore's fields
func (*ScoreStore) Update ¶
func (ss *ScoreStore) Update(sample float64, sampleTime time.Time) error
update updates the ScoreStore's numerator and denominator with a new sample. The ScoreStore's score is calculated as a weighted average with a decay factor. The new sample is added by the following formula:
num = num * decay_factor + sample * weight denom = denom * decay_factor + weight decay_factor = exp(-time_since_last_update / half_life_time)
func (*ScoreStore) UpdateConfig ¶
func (ss *ScoreStore) UpdateConfig(opts ...Option) error
UpdateConfig updates the configuration of a ScoreStore
func (*ScoreStore) Validate ¶
func (ss *ScoreStore) Validate() error
Validate validates the ScoreStore's fields hold valid values
type ScoreStorer ¶
type ScoreStorer interface {
Update(sample float64, sampleTime time.Time) error
Resolve() (float64, error)
Validate() error
String() string
UpdateConfig(opts ...Option) error
GetName() string
GetNum() float64
GetDenom() float64
GetLastUpdateTime() time.Time
GetConfig() Config
}
ScoreStorer defines the interface for all score stores
func NewCustomScoreStore ¶
func NewCustomScoreStore(scoreType string, num, denom float64, t time.Time, opts ...Option) (ScoreStorer, error)
NewCustomScoreStore creates a new custom ScoreStorer based on the score type
func NewScoreStore ¶
func NewScoreStore(scoreType string) ScoreStorer
NewScoreStore creates a new default ScoreStorer based on the score type
type SyncScoreStore ¶
type SyncScoreStore struct {
*ScoreStore
}