backpressure

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package backpressure provides flow control mechanisms for data forwarding.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdaptiveConfig

type AdaptiveConfig struct {
	HighWatermark int
	LowWatermark  int
	YieldMin      time.Duration
	YieldMax      time.Duration
}

AdaptiveConfig holds configuration for AdaptiveController.

type AdaptiveController

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

AdaptiveController provides adaptive backpressure with exponential backoff. Thread-safe for concurrent use.

func NewAdaptiveController

func NewAdaptiveController(cfg AdaptiveConfig) *AdaptiveController

NewAdaptiveController creates a new adaptive backpressure controller.

func (*AdaptiveController) CheckAndYield

func (c *AdaptiveController) CheckAndYield() bool

CheckAndYield checks if paused and yields CPU time with exponential backoff. Returns true if yielding was performed.

func (*AdaptiveController) IsPaused

func (c *AdaptiveController) IsPaused() bool

IsPaused returns whether the flow is paused.

func (*AdaptiveController) Pause

func (c *AdaptiveController) Pause()

Pause stops data flow.

func (*AdaptiveController) Reset

func (c *AdaptiveController) Reset()

Reset resets the backoff to minimum.

func (*AdaptiveController) Resume

func (c *AdaptiveController) Resume()

Resume allows data flow to continue.

func (*AdaptiveController) SetWatermarks

func (c *AdaptiveController) SetWatermarks(low, high int)

SetWatermarks configures the high and low watermark levels.

func (*AdaptiveController) Stats

func (c *AdaptiveController) Stats() (pauseCount int64, totalPause time.Duration)

Stats returns backpressure statistics.

func (*AdaptiveController) UpdateLevel

func (c *AdaptiveController) UpdateLevel(level int)

UpdateLevel updates the current buffer level and manages watermarks.

type Controller

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

Controller manages backpressure for a data flow.

func NewController

func NewController() *Controller

NewController creates a new backpressure controller.

func (*Controller) CheckAndYield

func (c *Controller) CheckAndYield() bool

CheckAndYield checks if paused and yields CPU time if so. Returns true if yielding was performed.

func (*Controller) IsPaused

func (c *Controller) IsPaused() bool

IsPaused returns whether the flow is paused.

func (*Controller) Pause

func (c *Controller) Pause()

Pause stops data flow.

func (*Controller) Resume

func (c *Controller) Resume()

Resume allows data flow to continue.

func (*Controller) SetWatermarks

func (c *Controller) SetWatermarks(low, high int)

SetWatermarks configures the high and low watermark levels.

func (*Controller) UpdateLevel

func (c *Controller) UpdateLevel(level int)

UpdateLevel updates the current buffer level and manages watermarks.

type Pair

type Pair struct {
	A *Controller
	B *Controller
}

Pair manages backpressure for bidirectional data flow.

func NewPair

func NewPair() *Pair

NewPair creates a backpressure pair for bidirectional flow.

func (*Pair) PauseA

func (p *Pair) PauseA()

PauseA pauses direction A.

func (*Pair) PauseB

func (p *Pair) PauseB()

PauseB pauses direction B.

func (*Pair) ResumeA

func (p *Pair) ResumeA()

ResumeA resumes direction A.

func (*Pair) ResumeB

func (p *Pair) ResumeB()

ResumeB resumes direction B.

func (*Pair) SignalErrorA

func (p *Pair) SignalErrorA()

SignalErrorA signals an error in direction A, resuming B.

func (*Pair) SignalErrorB

func (p *Pair) SignalErrorB()

SignalErrorB signals an error in direction B, resuming A.

Jump to

Keyboard shortcuts

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