throttling

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: Apache-2.0 Imports: 6 Imported by: 3

Documentation

Overview

Package throttling implements wrapper around blob.Storage that adds throttling to all calls. Throttling is performed for both operations and byte counts (upload and download separately).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWrapper

func NewWrapper(wrapped blob.Storage, throttler Throttler) blob.Storage

NewWrapper returns a Storage wrapper that adds retry loop around all operations of the underlying storage.

Types

type Limits

type Limits struct {
	ReadsPerSecond         float64 `json:"readsPerSecond,omitempty"`
	WritesPerSecond        float64 `json:"writesPerSecond,omitempty"`
	ListsPerSecond         float64 `json:"listsPerSecond,omitempty"`
	UploadBytesPerSecond   float64 `json:"maxUploadSpeedBytesPerSecond,omitempty"`
	DownloadBytesPerSecond float64 `json:"maxDownloadSpeedBytesPerSecond,omitempty"`
	ConcurrentReads        int     `json:"concurrentReads,omitempty"`
	ConcurrentWrites       int     `json:"concurrentWrites,omitempty"`
}

Limits encapsulates all limits for a Throttler.

type SettableThrottler

type SettableThrottler interface {
	Throttler

	Limits() Limits
	SetLimits(limits Limits) error
	OnUpdate(handler UpdatedHandler)
}

SettableThrottler exposes methods to set throttling limits.

func NewThrottler

func NewThrottler(limits Limits, window time.Duration, initialFillRatio float64) (SettableThrottler, error)

NewThrottler returns a Throttler with provided limits.

type Throttler

type Throttler interface {
	BeforeOperation(ctx context.Context, op string)
	AfterOperation(ctx context.Context, op string)

	// BeforeDownload acquires the specified number of downloaded bytes
	// possibly blocking until enough are available.
	BeforeDownload(ctx context.Context, numBytes int64)

	// BeforeUpload acquires the specified number of upload bytes
	// possibly blocking until enough are available.
	BeforeUpload(ctx context.Context, numBytes int64)

	// ReturnUnusedDownloadBytes returns the specified number of unused download bytes.
	ReturnUnusedDownloadBytes(ctx context.Context, numBytes int64)
}

Throttler implements throttling policy by blocking before certain operations are attempted to ensure we don't exceed the desired rate of operations/bytes uploaded/downloaded.

type UpdatedHandler added in v0.11.0

type UpdatedHandler func(l Limits) error

UpdatedHandler is invoked as part of SetLimits() after limits are updated.

Jump to

Keyboard shortcuts

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