Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultGeneratorSamplingPeriod = time.Second
DefaultGeneratorSamplingPeriod defines the default approximate duration over which the QPS is sampled.
var DefaultGeneratorSleepPrecision = 50 * time.Millisecond
DefaultGeneratorSleepPrecision defines the default duration that will trigger a wait after each request.
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.
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.