rto

package
v1.1.3-beta.15 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

rto implements adaptive timeout algorithm used in TCP retransmission timeout.

Index

Constants

View Source
const (
	DEFAULT_BACKOFF      int64         = 2
	CONSERVATIVE_BACKOFF int64         = 1
	DEFAULT_K_MARGIN     int64         = 1
	DEFAULT_INTERVAL     time.Duration = 5 * time.Second
	DEFAULT_SLO          float64       = 0.1
	ALPHA_SCALING        int64         = 8
	LOG2_ALPHA           int64         = 3
	BETA_SCALING         int64         = 4
	LOG2_BETA            int64         = 2
	SLO_SAFETY_MARGIN    float64       = 0.5 // safety margin of 0.5 or division by 2
	MIN_FAILED_SAMPLES   float64       = 2
)

Variables

View Source
var AdaptoRTOProviders map[string]*AdaptoRTOProvider
View Source
var RequestRateLimitExceeded error = requestRateLimitExceeded{}

Functions

func GetTimeout

func GetTimeout(ctx context.Context, config Config) (timeout time.Duration, rttCh chan<- RttSignal, err error)

GetTimeout retrieves timeout value using provider with given id in config. if no provider with matching id is found, creates a new provider

Types

type AdaptoRTOProvider

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

func NewAdaptoRTOProvider added in v1.0.7

func NewAdaptoRTOProvider(config Config) *AdaptoRTOProvider

func (*AdaptoRTOProvider) ChokeTimeout added in v1.1.0

func (arp *AdaptoRTOProvider) ChokeTimeout()

ChokeTimeout handles timeout update when transitioning to overload should lock rto updates

func (*AdaptoRTOProvider) ComputeNewRTO added in v1.0.7

func (arp *AdaptoRTOProvider) ComputeNewRTO(rtt time.Duration)

ComputeNewRTO computes new rto based on new rtt MUST be called in thread safe manner as it does not lock mu

func (*AdaptoRTOProvider) CurrentReq added in v1.1.1

func (arp *AdaptoRTOProvider) CurrentReq() int64

CurrentReq extraporates current number of requests for the past interval using sliding window this should be used when overload is declared ref: https://blog.cloudflare.com/counting-things-a-lot-of-different-things/ should lock rto updates

func (*AdaptoRTOProvider) NewTimeout

func (arp *AdaptoRTOProvider) NewTimeout(ctx context.Context) (timeout time.Duration, rttCh chan<- RttSignal, err error)

NewTimeout returns the current timeout value TODO: implement pseudo client queue / rate limiting

func (*AdaptoRTOProvider) OverloadReq added in v1.1.3

func (arp *AdaptoRTOProvider) OverloadReq(overloadedTimeout time.Duration) int64

OverloadReq computes the estimate of instantaneous number of request per interval that triggered overload. the reference time for the sliding window is adjusted by the timeout duration that triggered overload.

func (*AdaptoRTOProvider) StartWithSLO added in v1.0.7

func (arp *AdaptoRTOProvider) StartWithSLO()

StartWithSLO starts the provider by spawning a goroutine that waits for new rtt or timeout event and updates the timeout value accordingly. timeout calculations are also adjusted to meet the SLO

type Config

type Config struct {
	Id             string
	Max            time.Duration // max timeout value allowed
	Min            time.Duration // min timeout value allowed
	SLOFailureRate float64       // target failure rate SLO
	Interval       time.Duration // interval for failure rate calculations
	KMargin        int64         // starting kMargin for with SLO and static kMargin for without SLO

	Logger logger.Logger // optional logger
}

func (*Config) Validate added in v1.0.7

func (c *Config) Validate() *ConfigValidationError

type ConfigValidationError added in v1.1.3

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

func (ConfigValidationError) Error added in v1.1.3

func (c ConfigValidationError) Error() string

type RTOProviderState added in v1.1.0

type RTOProviderState = int64

State enum for main state machine

const (
	NORMAL RTOProviderState = iota
	OVERLOAD
)

type RttSignal

type RttSignal = time.Duration

RttSignal is alias for time.Duration that is used for typing the channel used to report rtt.

Jump to

Keyboard shortcuts

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