Documentation
¶
Index ¶
- type BackendBandwidth
- type Metrics
- type Scheduler
- func (s *Scheduler) GetMetrics() Metrics
- func (s *Scheduler) RecordSent(backendID string, bytes int)
- func (s *Scheduler) RefundSend(backendID string, bytes int)
- func (s *Scheduler) Register(backendID string) *BackendBandwidth
- func (s *Scheduler) RegisterShared(backendID string) *BackendBandwidth
- func (s *Scheduler) RequestSend(backendID string, bytes int) (bool, time.Duration)
- func (s *Scheduler) Stop()
- func (s *Scheduler) Unregister(backendID string)
- func (s *Scheduler) UnregisterShared(backendID string)
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 ¶
NewScheduler creates a bandwidth scheduler. totalMbps: total bandwidth in megabits per second (0 = unlimited)
func (*Scheduler) GetMetrics ¶
GetMetrics returns current bandwidth metrics.
func (*Scheduler) RecordSent ¶
RecordSent records that data was successfully sent.
func (*Scheduler) RefundSend ¶
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 ¶
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) Unregister ¶
Unregister removes a backend from the scheduler.
func (*Scheduler) UnregisterShared ¶
UnregisterShared decrements the reference count for a shared backend ID. The backend is only removed when the reference count reaches zero.