control

package module
v0.0.0-...-09127fd Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2014 License: Apache-2.0 Imports: 4 Imported by: 0

README

gopid

Proportional Integral Differential control system for golang.

Installation

You can download the code via the usual go utilities:

go get github.com/datacratic/gopid

To build the code and run the test suite along with several static analysis tools, use the provided Makefile:

make test

Note that the usual go utilities will work just fine but we require that all commits pass the full suite of tests and static analysis tools.

License

The source code is available under the Apache License. See the LICENSE file for more details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultGeneratorSamplingPeriod = time.Second

DefaultGeneratorSamplingPeriod defines the default approximate duration over which the QPS is sampled.

View Source
var DefaultGeneratorSleepPrecision = 50 * time.Millisecond

DefaultGeneratorSleepPrecision defines the default duration that will trigger a wait after each request.

View Source
var DefaultGeneratorSmoothingFactor = 0.80

DefaultGeneratorSmoothingFactor contains the default weight of the exponential moving average that estimates the time taken by the handler.

Functions

This section is empty.

Types

type Generator

type Generator struct {
	// Handler contains what gets executed periodically.
	Handler Task
	// QPS contains the number of calls that will be done per second.
	QPS float64
	// SmoothingFactor contains the weight of the exponential moving average that estimates the time taken by the handler.
	// Will use DefaultGeneratorSmoothingFactor if 0.
	SmoothingFactor float64
	// SleepPrecision contains the minimal duration that will trigger a wait after each request.
	// Will use DefaultGeneratorSleepPrecision if 0.
	SleepPrecision time.Duration
	// SamplingPeriod contains the approximate duration over which the QPS is sampled.
	// Will use DefaultGeneratorSamplingPeriod if 0.
	SamplingPeriod time.Duration
}

Generator adapts itself to call an handler a fixed number of times per second. It operates by creating B concurrent batches that will call the handler N times repeatedly. After each call to the handler, it waits W seconds to space requests evently over time. To avoid sleeping for very small amount of time, those waits are grouped based on the supplied precision. Note that the system adjusts B and W based on its estimation of the time R taken by the handler. Therefore, if the variability of R is high, it may make it harder for the system to stabilize to a steady state.

func (*Generator) Start

func (generator *Generator) Start()

Start begins calling the handler at the requested frequency.

type PID

type PID struct {
	// Kp contains the proportional gain.
	Kp float64
	// Ki contains the integral gain.
	Ki float64
	// Kd contains the derivative gain.
	Kd float64
	// Target contains the current setpoint.
	Target float64
	// Output contains the current value of the controller.
	// This value can be set before the first iteration to set initial conditions.
	Output float64
	// contains filtered or unexported fields
}

PID defines a generic PID controller.

func (*PID) Step

func (c *PID) Step(value float64, dt time.Duration) (output float64)

Step performs an iteration of the PID controller.

func (*PID) Update

func (c *PID) Update(value float64) (output float64)

Update performs an iteration of the PID controller with a variable dt based on the system time.

type Task

type Task interface {
	Do()
}

Task defines an interface for executing tasks.

type TaskFunc

type TaskFunc func()

TaskFunc defines an helper type for using function literals as a Task.

func (TaskFunc) Do

func (f TaskFunc) Do()

Do executes the function literal as a Task.

Jump to

Keyboard shortcuts

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