measuring

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Internal package used to measuring and benchmarking of the discipline.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDataMixedBetweenPriorities = errors.New("data is mixed between priorities")
	ErrDataPartiallyLost          = errors.New("data is partially lost")
	ErrHandlersQuantityZero       = errors.New("quantity of data handlers is zero")
	ErrMeasureDuplicated          = errors.New("measure is duplicated")
	ErrMeasurementsIsIncomplete   = errors.New("measurements is incomplete")
	ErrUnexpectedMeasureKind      = errors.New("unexpected kind of measure is received")
)

Functions

func CompareItem

func CompareItem(first, second Measure) int

Compare function for sorting measurements by data item.

func CompareTime

func CompareTime(first, second Measure) int

Compare function for sorting measurements by time.

func KeepReceived

func KeepReceived(item Measure) bool

Delete function that keeps only measurements of the Received kind.

Types

type Benchmarker

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

Used to benchmark discipline.

func NewBenchmarker

func NewBenchmarker(handlersQuantity uint, inputCapacity ...uint) (*Benchmarker, error)

Creates Benchmarker instance.

If the capacity of the input (for the discipline) channels is not specified, then the capacity of each channel will be equal to the quantity of data items that will be written to it.

When specifying multiple input channel capacities, the value of the first one will be used.

func (*Benchmarker) AddItems

func (bnch *Benchmarker) AddItems(priority, quantity uint)

Increases quantity of data items that will be written to the input (for the discipline) channel of the specified priority.

func (*Benchmarker) HandlersQuantity

func (bnch *Benchmarker) HandlersQuantity() uint

Returns the quantity of data handlers specified when the instance was created.

func (*Benchmarker) Inputs

func (bnch *Benchmarker) Inputs() map[uint]<-chan uint

Recreates the input (for the discipline) channels where data items will be written.

Must be called before Benchmarker.Play.

func (*Benchmarker) Play

func (bnch *Benchmarker) Play(discipline Discipline[uint])

Writes data items to the input (for the discipline) channels and reads data items from the output channel of the discipline.

Must be called after Benchmarker.Inputs.

type Discipline

type Discipline[Type any] interface {
	Err() <-chan error
	Output() <-chan types.Prioritized[Type]
	Release(priority uint)
}

Interface of priority discipline.

type Kind

type Kind int

Type of one measuring. Specifies the position of the measurement in the processing sequence of the data item received from the discipline.

const (
	KindCompleted Kind = iota + 1
	KindProcessed
	KindReceived
)

type Measure

type Measure struct {
	// Data item received from the discipline
	Item uint

	// Position of the measurement in the processing sequence of the data item
	Kind Kind

	// Priority of data item
	Priority uint

	// Relative time of measurement execution
	Time time.Duration
}

Describes one measuring.

type Measurer

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

Used to measuring discipline.

func NewMeasurer

func NewMeasurer(handlersQuantity uint, inputCapacity ...uint) (*Measurer, error)

Creates Measurer instance.

If the capacity of the input (for the discipline) channels is not specified, then the capacity of each channel will be equal to the quantity of data handlers.

When specifying multiple input channel capacities, the value of the first one will be used.

func (*Measurer) AddDelay

func (msr *Measurer) AddDelay(priority uint, delay time.Duration)

Adds to the actions list a delay in further execution of actions.

func (*Measurer) AddWaitDevastation

func (msr *Measurer) AddWaitDevastation(priority uint)

Adds to the actions list a waiting for the input (for the discipline) channel to be devastated.

func (*Measurer) AddWrite

func (msr *Measurer) AddWrite(priority, quantity uint)

Adds to the actions list a write of the specified quantity of data items to the input (for the discipline) channel of the specified priority.

func (*Measurer) AddWriteWithDelay

func (msr *Measurer) AddWriteWithDelay(priority, quantity uint, delay time.Duration)

Adds to the actions list a write of the specified quantity of data items to the input (for the discipline) channel of the specified priority.

Before writing each data item, the specified delay occurs.

func (*Measurer) HandlersQuantity

func (msr *Measurer) HandlersQuantity() uint

Returns the quantity of data handlers specified when the instance was created.

func (*Measurer) Inputs

func (msr *Measurer) Inputs() map[uint]<-chan uint

Recreates the input (for the discipline) channels where data items will be written.

Must be called before Measurer.Play.

func (*Measurer) Play

func (msr *Measurer) Play(discipline Discipline[uint]) ([]Measure, error)

Writes data items to the input (for the discipline) channels, reads data items from the output channel of the discipline and collects measurements about the time it takes to receive, process and release data items.

Must be called after Measurer.Inputs.

func (*Measurer) SetProcessingDuration

func (msr *Measurer) SetProcessingDuration(priority uint, duration time.Duration)

Sets the processing duration of one data item received from the discipline.

Jump to

Keyboard shortcuts

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