bandwidth

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackendBandwidth

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

BackendBandwidth tracks per-backend bandwidth state.

type Metrics

type Metrics struct {
	TotalBytesPerSecond   int64   // Configured limit
	CurrentBytesPerSecond float64 // Actual throughput
	ActiveBackendCount    int64   // Backends with pending data
	TotalBackendCount     int64   // All registered backends
	UtilizationPercent    float64 // CurrentBytes / TotalBytes * 100
	PerBackendBytesPerSec int64   // Current fair share
}

Metrics contains current bandwidth utilization statistics.

type Scheduler

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

Scheduler implements Deficit Round Robin for fair bandwidth allocation.

func NewScheduler

func NewScheduler(totalMbps int) *Scheduler

NewScheduler creates a bandwidth scheduler. totalMbps: total bandwidth in megabits per second (0 = unlimited)

func (*Scheduler) GetMetrics

func (s *Scheduler) GetMetrics() Metrics

GetMetrics returns current bandwidth metrics.

func (*Scheduler) RecordSent

func (s *Scheduler) RecordSent(backendID string, bytes int)

RecordSent records that data was successfully sent.

func (*Scheduler) RefundSend

func (s *Scheduler) RefundSend(backendID string, bytes int)

RefundSend returns previously reserved deficit when a send fails (e.g., channel full). This prevents tokens from being permanently lost on dropped messages.

func (*Scheduler) Register

func (s *Scheduler) Register(backendID string) *BackendBandwidth

Register adds a backend to the scheduler.

func (*Scheduler) RegisterShared

func (s *Scheduler) RegisterShared(backendID string) *BackendBandwidth

RegisterShared registers a shared backend ID with reference counting. Multiple callers can register the same ID; the backend is only removed when all callers have called UnregisterShared. This is used for tunnel bandwidth tracking where multiple tunnels may share the same hostname.

func (*Scheduler) RequestSend

func (s *Scheduler) RequestSend(backendID string, bytes int) (bool, time.Duration)

RequestSend checks if a backend can send data. Returns: (allowed bool, waitTime time.Duration) If allowed=false, caller should wait for waitTime before retrying.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop terminates the background goroutine.

func (*Scheduler) Unregister

func (s *Scheduler) Unregister(backendID string)

Unregister removes a backend from the scheduler.

func (*Scheduler) UnregisterShared

func (s *Scheduler) UnregisterShared(backendID string)

UnregisterShared decrements the reference count for a shared backend ID. The backend is only removed when the reference count reaches zero.

Jump to

Keyboard shortcuts

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