unit

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: AGPL-3.0 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

func (s *Scheduler) DebugUnit(u *Unit, unitSource string)

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

func (s *Scheduler) GetClearanceUpTo() int64

GetClearanceUpTo returns the current clearance limit.

func (*Scheduler) GetCurrentUnitID

func (s *Scheduler) GetCurrentUnitID() int64

GetCurrentUnitID returns the current unit ID.

func (*Scheduler) GetEpoch

func (s *Scheduler) GetEpoch() int32

GetEpoch returns the current epoch ID.

func (*Scheduler) GetFinished

func (s *Scheduler) GetFinished() int64

GetFinished returns the current amount of finished units.

func (*Scheduler) GetFinishedInEpoch

func (s *Scheduler) GetFinishedInEpoch() int64

GetFinishedInEpoch returns the current finished units within the current epoch.

func (*Scheduler) GetHighPrioUnitsInEpoch

func (s *Scheduler) GetHighPrioUnitsInEpoch() int64

GetHighPrioUnitsInEpoch returns the current high priority units within the current epoch.

func (*Scheduler) GetPausedUnitsInEpoch

func (s *Scheduler) GetPausedUnitsInEpoch() int64

GetPausedUnitsInEpoch returns the current paused units within the current epoch.

func (*Scheduler) GetSlotPace

func (s *Scheduler) GetSlotPace() int64

GetSlotPace returns the current slot pace.

func (*Scheduler) NewUnit

func (s *Scheduler) NewUnit() *Unit

NewUnit returns a new unit within the scheduler.

func (*Scheduler) SlotScheduler

func (s *Scheduler) SlotScheduler(ctx context.Context) error

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.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop stops the scheduler and gives clearance to all units.

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

func (u *Unit) IsHighPriority() bool

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.

Jump to

Keyboard shortcuts

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