estimator

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package estimator provides tools to estimate query timing for a production environment.

Package estimator provides tools to estimate query timing for a production environment.

Index

Constants

View Source
const (
	// ReadyEventType defines ready event type.
	ReadyEventType = "ready"

	// ResultEventType defines result event type.
	ResultEventType = "result"

	// ReadBlocksType defines client event that provides a number of reading blocks.
	ReadBlocksType = "read_blocks"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ReadRatio         float64       `yaml:"readRatio"`
	WriteRatio        float64       `yaml:"writeRatio"`
	ProfilingInterval time.Duration `yaml:"profilingInterval"`
	SampleThreshold   int           `yaml:"sampleThreshold"`
}

Config describes options to estimate query timing.

type Estimator

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

Estimator defines a timing estimator.

func NewEstimator

func NewEstimator(cfg *Config) *Estimator

NewEstimator creates a new Estimator.

func (*Estimator) Config

func (e *Estimator) Config() Config

Config returns Estimator configuration.

func (*Estimator) Reload

func (e *Estimator) Reload(cfg Config)

Reload reloads estimator configuration.

func (*Estimator) Run

func (e *Estimator) Run(ctx context.Context, p *Profiler)

Run starts profiling if it needs to be done.

type Event

type Event struct {
	EventType string
}

Event defines the websocket event structure.

type Monitor

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

Monitor observes processes and system activity.

func NewMonitor

func NewMonitor(pid int, container string, profiler *Profiler) *Monitor

NewMonitor creates a new monitor.

func (*Monitor) InspectIOBlocks

func (m *Monitor) InspectIOBlocks(ctx context.Context) error

InspectIOBlocks counts physically read blocks.

type Profiler

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

Profiler defines a profiling structure.

func NewProfiler

func NewProfiler(conn pgxtype.Querier, opts TraceOptions) *Profiler

NewProfiler creates a new profiler.

func (*Profiler) CountSamples

func (p *Profiler) CountSamples() int

CountSamples returns a number of samples.

func (*Profiler) EstimateTime

func (p *Profiler) EstimateTime(ctx context.Context) (string, error)

EstimateTime estimates time.

func (*Profiler) Finish

func (p *Profiler) Finish() chan struct{}

Finish returns a channel that's receiving data when profiling done.

func (*Profiler) IsEnoughSamples

func (p *Profiler) IsEnoughSamples() bool

IsEnoughSamples checks if enough samples have been collected.

func (*Profiler) RenderStat

func (p *Profiler) RenderStat() string

RenderStat renders the collected profiler stats.

func (*Profiler) Start

func (p *Profiler) Start(ctx context.Context)

Start runs the main profiling loop.

func (*Profiler) Stop

func (p *Profiler) Stop()

Stop signals the end of data collection.

func (*Profiler) TotalTime

func (p *Profiler) TotalTime() float64

TotalTime returns a total time of profiling events.

func (*Profiler) WaitEventsRatio

func (p *Profiler) WaitEventsRatio() map[string]float64

WaitEventsRatio returns a ratio of wait events.

type ReadBlocksEvent

type ReadBlocksEvent struct {
	EventType  string
	ReadBlocks uint64
}

ReadBlocksEvent defines a read blocks event.

type Result

type Result struct {
	IsEnoughStat    bool
	SampleCounter   int
	TotalTime       float64
	EstTime         string
	RenderedStat    string
	WaitEventsRatio map[string]float64
}

Result represents results of estimation session.

type ResultEvent

type ResultEvent struct {
	EventType string
	Payload   Result
}

ResultEvent defines a result event.

type StatDatabase

type StatDatabase struct {
	BlocksRead     int64   `json:"blks_read"`
	BlocksHit      int64   `json:"blks_hit"`
	BlockReadTime  float64 `json:"blk_read_time"`
	BlockWriteTime float64 `json:"blk_write_time"`
}

StatDatabase defines database blocks stats.

type Timing

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

Timing defines a timing estimator.

func NewTiming

func NewTiming(waitEvents map[string]float64, readRatio, writeRatio float64) *Timing

NewTiming creates a new timing estimator.

func (*Timing) CalcMax

func (est *Timing) CalcMax(elapsed float64) float64

CalcMax calculates the maximum query time estimation for the production environment, given the prepared ratios.

func (*Timing) CalcMin

func (est *Timing) CalcMin(elapsed float64) float64

CalcMin calculates the minimum query time estimation for the production environment, given the prepared ratios.

func (*Timing) EstTime

func (est *Timing) EstTime(elapsed float64) string

EstTime prints estimation timings.

func (*Timing) SetRealReadRatio

func (est *Timing) SetRealReadRatio(realReadRatio float64)

SetRealReadRatio sets real read ratio.

type TraceOptions

type TraceOptions struct {
	Pid             int           // PID of profiled backend.
	Interval        time.Duration // Profiling interval.
	SampleThreshold int
	ReadRatio       float64
	WriteRatio      float64
}

TraceOptions defines program's configuration options.

type TraceStat

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

TraceStat describes data retrieved from Postgres' pg_stat_activity view.

Jump to

Keyboard shortcuts

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