Documentation
¶
Overview ¶
Package unit provides a "work unit" scheduling system for handling data sets that traverse multiple workers / goroutines. The aim is to bind priority to a data set instead of a goroutine and split resources fairly among requests.
Every "work" Unit is assigned an ever increasing ID and can be marked as "paused" or "high priority". The Scheduler always gives a clearance up to a certain ID. All units below this ID may be processed. High priority Units may always be processed.
The Scheduler works with short slots and measures how many Units were finished in a slot. The "slot pace" holds an indication of the current Unit finishing speed per slot. It is only changed slowly (but boosts if too far away) in order to keep stabilize the system. The Scheduler then calculates the next unit ID limit to give clearance to for the next slot:
"finished units" + "slot pace" + "paused units" - "fraction of high priority units"
Index ¶
- type Scheduler
- func (s *Scheduler) DebugUnit(u *Unit, unitSource string)
- func (s *Scheduler) GetClearanceUpTo() int64
- func (s *Scheduler) GetCurrentUnitID() int64
- func (s *Scheduler) GetEpoch() int32
- func (s *Scheduler) GetFinished() int64
- func (s *Scheduler) GetFinishedInEpoch() int64
- func (s *Scheduler) GetHighPrioUnitsInEpoch() int64
- func (s *Scheduler) GetPausedUnitsInEpoch() int64
- func (s *Scheduler) GetSlotPace() int64
- func (s *Scheduler) NewUnit() *Unit
- func (s *Scheduler) SlotScheduler(ctx context.Context) error
- func (s *Scheduler) StartDebugLog()
- func (s *Scheduler) State() *SchedulerState
- func (s *Scheduler) Stop()
- type SchedulerConfig
- type SchedulerState
- type Unit
- type UnitDebugData
- type UnitDebugger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler creates and schedules units. Must be created using NewScheduler().
func NewScheduler ¶
func NewScheduler(config *SchedulerConfig) *Scheduler
NewScheduler returns a new scheduler.
func (*Scheduler) DebugUnit ¶
DebugUnit registers the given unit for debug output with the given source. Additional calls on the same unit update the unit source. StartDebugLog() must be called before calling DebugUnit().
func (*Scheduler) GetClearanceUpTo ¶
GetClearanceUpTo returns the current clearance limit.
func (*Scheduler) GetCurrentUnitID ¶
GetCurrentUnitID returns the current unit ID.
func (*Scheduler) GetFinished ¶
GetFinished returns the current amount of finished units.
func (*Scheduler) GetFinishedInEpoch ¶
GetFinishedInEpoch returns the current finished units within the current epoch.
func (*Scheduler) GetHighPrioUnitsInEpoch ¶
GetHighPrioUnitsInEpoch returns the current high priority units within the current epoch.
func (*Scheduler) GetPausedUnitsInEpoch ¶
GetPausedUnitsInEpoch returns the current paused units within the current epoch.
func (*Scheduler) GetSlotPace ¶
GetSlotPace returns the current slot pace.
func (*Scheduler) SlotScheduler ¶
SlotScheduler manages the slot and schedules units. Must only be started once.
func (*Scheduler) StartDebugLog ¶
func (s *Scheduler) StartDebugLog()
StartDebugLog logs the scheduler state every second.
func (*Scheduler) State ¶
func (s *Scheduler) State() *SchedulerState
State returns the current internal state values of the scheduler.
type SchedulerConfig ¶
type SchedulerConfig struct {
// SlotDuration defines the duration of one slot.
SlotDuration time.Duration
// MinSlotPace defines the minimum slot pace.
// The slot pace will never fall below this value.
MinSlotPace int64
// EpochDuration defines the duration of one epoch.
// Set to 0 to disable epochs.
EpochDuration time.Duration
// AdjustFractionPerStreak defines the fraction of the pace the pace itself changes in either direction to match the current use and load.
AdjustFractionPerStreak int64
// HighPriorityMaxReserveFraction defines the fraction of the pace that may - at maximum - be reserved for high priority units.
HighPriorityMaxReserveFraction int64
}
SchedulerConfig holds scheduler configuration.
type SchedulerState ¶
type SchedulerState struct {
CurrentUnitID int64
SlotPace int64
ClearanceUpTo int64
Finished int64
Epoch int32
FinishedInEpoch int64
PausedUnitsInEpoch int64
HighPrioUnitsInEpoch int64
}
SchedulerState holds a snapshot of the current scheduler state.
type Unit ¶
type Unit struct {
// contains filtered or unexported fields
}
Unit describes a "work unit" and is meant to be embedded into another struct used for passing data moving through multiple processing steps.
func (*Unit) Finish ¶
func (u *Unit) Finish()
Finish signals the unit scheduler that this unit has finished processing. Will no-op if called on a nil Unit.
func (*Unit) IsHighPriority ¶
IsHighPriority returns whether the unit has high priority.
func (*Unit) MakeHighPriority ¶
func (u *Unit) MakeHighPriority()
MakeHighPriority marks the unit as high priority.
func (*Unit) Pause ¶
func (u *Unit) Pause()
Pause signals the unit scheduler that this unit is paused and not being processed at the moment. May only be called if WaitForUnitSlot() was called at least once.
func (*Unit) ReUse ¶
func (u *Unit) ReUse()
ReUse re-initilizes the unit to be able to reuse already allocated structs.
func (*Unit) RemovePriority ¶
func (u *Unit) RemovePriority()
RemovePriority removes the high priority mark.
func (*Unit) WaitForSlot ¶
func (u *Unit) WaitForSlot()
WaitForSlot blocks until the unit may be processed.
type UnitDebugData ¶
type UnitDebugData struct {
// contains filtered or unexported fields
}
UnitDebugData represents a unit that is being debugged.
type UnitDebugger ¶
type UnitDebugger struct {
// contains filtered or unexported fields
}
UnitDebugger is used to debug unit leaks.