control

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package control keeps track of resources and manages queries.

The Controller manages the resources available to each query by managing the memory allocation and concurrency usage of each query. The Controller will compile a program by using the passed in language and it will start the program using the ResourceManager.

It will guarantee that each program that is started has at least one goroutine that it can use with the dispatcher and it will ensure a minimum amount of memory is available before the program runs.

Other goroutines and memory usage is at the will of the specific resource strategy that the Controller is using.

The Controller also provides visibility into the lifetime of the query and its current resource usage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartSpanFromContext

func StartSpanFromContext(ctx context.Context, operationName string, hist prometheus.Observer, gauge prometheus.Gauge) (*span, context.Context)

Types

type Config

type Config struct {
	// ConcurrencyQuota is the number of queries that are allowed to execute concurrently.
	ConcurrencyQuota int
	// MemoryBytesQuotaPerQuery is the maximum number of bytes (in table memory) a query is allowed to use at
	// any given time.
	//
	// The maximum amount of memory the controller is allowed to consume is
	//   ConcurrencyQuota * MemoryBytesQuotaPerQuery
	MemoryBytesQuotaPerQuery int64
	// QueueSize is the number of queries that are allowed to be awaiting execution before new queries are
	// rejected.
	QueueSize int
	Logger    *zap.Logger
	// MetricLabelKeys is a list of labels to add to the metrics produced by the controller.
	// The value for a given key will be read off the context.
	// The context value must be a string or an implementation of the Stringer interface.
	MetricLabelKeys []string

	ExecutorDependencies execute.Dependencies
}

func (*Config) Validate added in v0.27.0

func (c *Config) Validate() error

type Controller

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

Controller provides a central location to manage all incoming queries. The controller is responsible for compiling, queueing, and executing queries.

func New

func New(c Config) (*Controller, error)

func (*Controller) PrometheusCollectors

func (c *Controller) PrometheusCollectors() []prometheus.Collector

PrometheusCollectors satisifies the prom.PrometheusCollector interface.

func (*Controller) Queries

func (c *Controller) Queries() []*Query

Queries reports the active queries.

func (*Controller) Query

func (c *Controller) Query(ctx context.Context, compiler flux.Compiler) (flux.Query, error)

Query submits a query for execution returning immediately. Done must be called on any returned Query objects.

func (*Controller) Shutdown added in v0.7.1

func (c *Controller) Shutdown(ctx context.Context) error

Shutdown will signal to the Controller that it should not accept any new queries and that it should finish executing any existing queries. This will return once the Controller's run loop has been exited and all queries have been finished or until the Context has been canceled.

type Query

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

Query represents a single request.

func (*Query) Cancel

func (q *Query) Cancel()

Cancel will stop the query execution.

func (*Query) Done

func (q *Query) Done()

Done signals to the Controller that this query is no longer being used and resources related to the query may be freed.

func (*Query) Err

func (q *Query) Err() error

Err reports any error the query may have encountered.

func (*Query) ID

func (q *Query) ID() QueryID

ID reports an ephemeral unique ID for the query.

func (*Query) Results added in v0.26.0

func (q *Query) Results() <-chan flux.Result

Results returns a channel that will deliver the query results.

It's possible that the channel is closed before any results arrive. In particular, if a query's context or the query itself is canceled, the query may close the results channel before any results are computed.

The query may also have an error during execution so the Err() function should be used to check if an error happened.

func (*Query) State

func (q *Query) State() State

State reports the current state of the query.

func (*Query) Statistics

func (q *Query) Statistics() flux.Statistics

Statistics reports the statistics for the query.

This method must be called after Done. It will block until the query has been finalized unless a context is given.

type QueryID

type QueryID uint64

type State

type State int

State is the query state.

const (
	// Created indicates the query has been created.
	Created State = iota

	// Compiling indicates that the query is in the process
	// of executing the compiler associated with the query.
	Compiling

	// Queueing indicates the query is waiting inside of the
	// scheduler to be executed.
	// TODO(jsternberg): This stage isn't used currently, but
	// it makes sense to readd this once we have a work queue again.
	Queueing

	// Executing indicates that the query is currently executing.
	Executing

	// Errored indicates that there was an error when attempting
	// to execute a query within any state inside of the controller.
	Errored

	// Finished indicates that the query has been marked as Done
	// and it is awaiting removal from the Controller or has already
	// been removed.
	Finished

	// Canceled indicates that the query was signaled to be
	// canceled. A canceled query must still be released with Done.
	Canceled
)

func (State) String

func (s State) String() string

Directories

Path Synopsis
Package controltest provides a controller for use in tests.
Package controltest provides a controller for use in tests.

Jump to

Keyboard shortcuts

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