public abstract class Buckets extends Object implements LogMessageSource<Split>
Modifier and Type | Field and Description |
---|---|
protected int |
bucketNb
Number of real buckets (=buckets.length-2).
|
protected Bucket[] |
buckets
Array of buckets, sorted by ranges.
|
protected long |
max
Upper bound of all real buckets.
|
protected long |
min
Lower bound of all real buckets.
|
Constructor and Description |
---|
Buckets(long min,
long max,
int bucketNb)
Constructor, initializes buckets.
|
Modifier and Type | Method and Description |
---|---|
void |
addValue(long value)
Searches the appropriate bucket and add the value in it.
|
void |
addValues(Collection<Long> values)
For each value, search the appropriate bucket and add the value in it.
|
void |
clear()
Clears all buckets.
|
protected double |
estimateQuantile(Bucket bucket,
double expectedCount,
double lastCount)
Interpolate quantile located in given Bucket using linear regression.
|
protected Bucket |
getBucketForValue(long value)
Get the bucket containing the given value.
|
int |
getBucketNb() |
List<Bucket> |
getBuckets()
Returns the bucket list.
|
String |
getLogMessage(Split lastSplit)
Transforms buckets and quantiles into a loggable message.
|
LogTemplate<Split> |
getLogTemplate() |
long |
getMax() |
double |
getMedian()
Computes median.
|
long |
getMin() |
double |
getQuantile(double ratio)
Computes quantile.
|
Double[] |
getQuantiles(double... ratios)
Computes many quantiles.
|
Double[] |
getQuartiles()
Computes first (=0.25), second (=median=0.5) and third (=0.75) quartiles.
|
void |
log(Split lastSplit)
Logs eventually buckets config and quantiles.
|
BucketsSample |
sample()
Sample buckets and quantiles state.
|
void |
setLogTemplate(LogTemplate<Split> logTemplate) |
String |
toString()
String containing: min/max/number configuration and 50%, 75% and 90% quantiles if available.
|
protected final Bucket[] buckets
protected final int bucketNb
protected final long min
protected final long max
public Buckets(long min, long max, int bucketNb)
min
- Min of all valuesmax
- Max of all valuesbucketNb
- Number of bucketsprotected double estimateQuantile(Bucket bucket, double expectedCount, double lastCount)
Bucket.min
and Bucket.max
Bucket.count
bucket
- Current bucket containing the quantileexpectedCount
- Searched valuelastCount
- Value of the bucket lower boundprotected Bucket getBucketForValue(long value)
value
- Valuepublic void addValue(long value)
public void addValues(Collection<Long> values)
public double getQuantile(double ratio)
ratio
- Nth quantile, 0.5 is median. Expects values between 0 and 1.public double getMedian()
public Double[] getQuartiles()
public Double[] getQuantiles(double... ratios)
ratios
- Nth quantiles, 0.5 is median. Expects values between 0 and 1.null
, if computation failedpublic LogTemplate<Split> getLogTemplate()
public void setLogTemplate(LogTemplate<Split> logTemplate)
public BucketsSample sample()
public String toString()
public void clear()
public List<Bucket> getBuckets()
public String getLogMessage(Split lastSplit)
getLogMessage
in interface LogMessageSource<Split>
lastSplit
- Contextpublic int getBucketNb()
public long getMin()
public long getMax()
Copyright © 2019. All rights reserved.