simulator

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Simulator

type Simulator struct {
	Duration time.Duration
	// contains filtered or unexported fields
}

Simulator represents a concurrent pipeline simulator that orchestrates multiple processing stages in a data flow pipeline.

func NewSimulator

func NewSimulator() *Simulator

NewSimulator creates a new simulator for a specific pipeline.

func (*Simulator) AddStage

func (s *Simulator) AddStage(stage *Stage) error

AddStage adds a new stage to the pipeline with validation.

Validation rules:

  • Stage cannot be nil
  • Stage name cannot be empty
  • Stage name must be unique within the pipeline
  • Stage config cannot be nil

func (*Simulator) GetStages

func (s *Simulator) GetStages() []*Stage

GetStages returns a copy of all stages in the pipeline. used by test package

func (*Simulator) Start

func (s *Simulator) Start(printStats bool) error

Start begins the simulation and blocks until completion.

Validation rules:

  • At least 3 stages if you want to collect stats
  • Only one stage will result in creating a generator and nothing else.
  • Only two stages will result in having one generator and one dummy.

type Stage

type Stage struct {
	Name   string
	Config *StageConfig
	// contains filtered or unexported fields
}

Stage represents a processing stage in the pipeline

func NewStage

func NewStage(name string, config *StageConfig) *Stage

NewStage creates a new stage with the provided config or creates a default one.

func (*Stage) GetIsGenerator

func (s *Stage) GetIsGenerator() bool

GetIsGenerator is a getter.

func (*Stage) GetMetrics

func (s *Stage) GetMetrics() *stageMetrics

GetMetrics is a getting. Used by the test package

type StageConfig

type StageConfig struct {

	// Rate at which items are generated (generator only)
	InputRate time.Duration

	// Custom item generator function  (generator only)
	ItemGenerator func() any

	// Number of goroutines per stage
	RoutineNum int

	// Channel buffer size per stage
	BufferSize int

	// Simulated delay per item
	WorkerDelay time.Duration

	// Number of times to retry on error, since your custom function
	// could fail.
	RetryCount int

	// Drop input if channel is full, when not set to drop it will block
	// in case the channels are full.
	DropOnBackpressure bool

	// Custom worker function that processes each item
	WorkerFunc func(item any) (any, error)
	// contains filtered or unexported fields
}

StageConfig holds the configuration for a pipeline stage, it can be shared among all pipelines.

func DefaultConfig

func DefaultConfig() *StageConfig

DefaultConfig returns a new SimulationConfig with sensible defaults Used by test package

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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