public class MovingAverageTask extends Object implements Runnable
Modifier and Type | Field and Description |
---|---|
protected double |
average
The moving average.
|
static double |
DEFAULT_WEIGHT
The recommended default weight.
|
protected static org.apache.log4j.Logger |
log |
protected String |
name
The label used in log messages.
|
protected long |
nsamples
#of samples taken so far.
|
protected Callable<? extends Number> |
sampleTask
Used to sample whatever is being measured.
|
protected double |
w
The weight used to compute the moving average.
|
Constructor and Description |
---|
MovingAverageTask(String name,
Callable<? extends Number> sampleTask) |
MovingAverageTask(String name,
Callable<? extends Number> sampleTask,
double w)
Core impl.
|
Modifier and Type | Method and Description |
---|---|
double |
getMovingAverage()
The current value of the moving average.
|
protected static double |
getMovingAverage(double avg,
double q,
double w)
Compute a moving average:
(1 - w) * avg + w * q |
long |
getSampleCount()
#of samples taken so far.
|
double |
getWeight()
The weight used to compute the moving average.
|
void |
run()
Note: don't throw anything from here or it will cause the task to no
longer be run!
|
protected static final org.apache.log4j.Logger log
protected final String name
protected final Callable<? extends Number> sampleTask
protected final double w
protected long nsamples
protected double average
public static final double DEFAULT_WEIGHT
public MovingAverageTask(String name, Callable<? extends Number> sampleTask)
name
- The label for log messages.sampleTask
- Task that returns a sampled value.public MovingAverageTask(String name, Callable<? extends Number> sampleTask, double w)
name
- The label for log messages.queue
- Task that returns a sampled value.w
- The weight to be used by
getMovingAverage(double, double, double)
public double getMovingAverage()
public double getWeight()
public long getSampleCount()
protected static final double getMovingAverage(double avg, double q, double w)
(1 - w) * avg + w * q
avg
- The previous average and initially zero (0.0).q
- The current value (e.g., the instantaneous measurement of the
#of active tasks plus the length of the queue).w
- The weight for the moving average in (0:1). Values around .2
seem appropriate.Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.