package adaptive

import "google.golang.org/grpc/balancer/rls/internal/adaptive"

Package adaptive provides functionality for adaptive client-side throttling.

Index

Types

type Throttler

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

Throttler implements a client-side throttling recommendation system. All methods are safe for concurrent use by multiple goroutines.

The throttler has the following knobs for which we will use defaults for now. If there is a need to make them configurable at a later point in time, support for the same will be added.

The adaptive throttler attempts to estimate the probability that a request will be throttled using recent history. Server requests (both throttled and accepted) are registered with the throttler (via the RegisterBackendResponse method), which then recommends client-side throttling (via the ShouldThrottle method) with probability given by: (requests - RatioForAccepts * accepts) / (requests + RequestsPadding)

func New

func New() *Throttler

New initializes a new adaptive throttler with the default values.

func (*Throttler) RegisterBackendResponse

func (t *Throttler) RegisterBackendResponse(throttled bool)

RegisterBackendResponse registers a response received from the backend for a request allowed by ShouldThrottle. This should be called for every response received from the backend (i.e., once for each request for which ShouldThrottle returned false).

func (*Throttler) ShouldThrottle

func (t *Throttler) ShouldThrottle() bool

ShouldThrottle returns a probabilistic estimate of whether the server would throttle the next request. This should be called for every request before allowing it to hit the network. If the returned value is true, the request should be aborted immediately (as if it had been throttled by the server).

Source Files

adaptive.go lookback.go

Version
v1.70.0 (latest)
Published
Jan 23, 2025
Platform
linux/amd64
Imports
3 packages
Last checked
19 hours ago

Tools for package owners.