Class DubboMergingDigest
- All Implemented Interfaces:
Serializable
This can be very fast because the cost of sorting and merging is amortized over several insertion. If we keep N centroids total and have the input array is k long, then the amortized cost is something like
N/k + log k
These costs even out when N/k = log k. Balancing costs is often a good place to start in optimizing an algorithm. For different values of compression factor, the following table shows estimated asymptotic values of N and suggested values of k:
| Compression | N | k |
| 50 | 78 | 25 |
| 100 | 157 | 42 |
| 200 | 314 | 73 |
The virtues of this kind of t-digest implementation include:
- No allocation is required after initialization
- The data structure automatically compresses existing centroids when possible
- No Java object overhead is incurred for centroids since data is kept in primitive arrays
The current implementation takes the liberty of using ping-pong buffers for implementing the merge resulting in a substantial memory penalty, but the complexity of an in place merge was not considered as worthwhile since even with the overhead, the memory cost is less than 40 bytes per centroid which is much less than half what the AVLTreeDigest uses and no dynamic allocation is required at all.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionbooleanbooleanstatic boolean -
Constructor Summary
ConstructorsConstructorDescriptionDubboMergingDigest(double compression) Allocates a buffer merging t-digest.DubboMergingDigest(double compression, int bufferSize) If you know the size of the temporary buffer for incoming points, you can use this entry point.DubboMergingDigest(double compression, int bufferSize, int size) Fully specified constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(double x, int w) voidvoidasBytes(ByteBuffer buf) voidasSmallBytes(ByteBuffer buf) intbyteSize()doublecdf(double x) intCollection<com.tdunning.math.stats.Centroid> voidcompress()Merges any pending inputs and compresses the data down to the public setting.doubledoublegetMax()doublegetMin()com.tdunning.math.stats.ScaleFunctiondoublequantile(double q) com.tdunning.math.stats.TDigestTurns on internal data recording.voidsetScaleFunction(com.tdunning.math.stats.ScaleFunction scaleFunction) longsize()inttoString()Methods inherited from class org.apache.dubbo.metrics.aggregate.DubboAbstractTDigest
add, add, isRecordingMethods inherited from class com.tdunning.math.stats.TDigest
createAvlTreeDigest, createDigest, createMergingDigest
-
Field Details
-
useAlternatingSort
public boolean useAlternatingSort -
useTwoLevelCompression
public boolean useTwoLevelCompression -
useWeightLimit
public static boolean useWeightLimit
-
-
Constructor Details
-
DubboMergingDigest
public DubboMergingDigest(double compression) Allocates a buffer merging t-digest. This is the normally used constructor that allocates default sized internal arrays. Other versions are available, but should only be used for special cases.- Parameters:
compression- The compression factor
-
DubboMergingDigest
public DubboMergingDigest(double compression, int bufferSize) If you know the size of the temporary buffer for incoming points, you can use this entry point.- Parameters:
compression- Compression factor for t-digest. Same as 1/\delta in the paper.bufferSize- How many samples to retain before merging.
-
DubboMergingDigest
public DubboMergingDigest(double compression, int bufferSize, int size) Fully specified constructor. Normally only used for deserializing a buffer t-digest.- Parameters:
compression- Compression factorbufferSize- Number of temporary centroidssize- Size of main buffer
-
-
Method Details
-
getMin
public double getMin()- Overrides:
getMinin classcom.tdunning.math.stats.TDigest
-
getMax
public double getMax()- Overrides:
getMaxin classcom.tdunning.math.stats.TDigest
-
recordAllData
public com.tdunning.math.stats.TDigest recordAllData()Turns on internal data recording.- Overrides:
recordAllDatain classDubboAbstractTDigest
-
add
public void add(double x, int w) - Specified by:
addin classcom.tdunning.math.stats.TDigest
-
add
- Specified by:
addin classcom.tdunning.math.stats.TDigest
-
compress
public void compress()Merges any pending inputs and compresses the data down to the public setting. Note that this typically loses a bit of precision and thus isn't a thing to be doing all the time. It is best done only when we want to show results to the outside world.- Specified by:
compressin classcom.tdunning.math.stats.TDigest
-
size
public long size()- Specified by:
sizein classcom.tdunning.math.stats.TDigest
-
cdf
public double cdf(double x) - Specified by:
cdfin classcom.tdunning.math.stats.TDigest
-
quantile
public double quantile(double q) - Specified by:
quantilein classcom.tdunning.math.stats.TDigest
-
centroidCount
public int centroidCount()- Specified by:
centroidCountin classcom.tdunning.math.stats.TDigest
-
centroids
- Specified by:
centroidsin classcom.tdunning.math.stats.TDigest
-
compression
public double compression()- Specified by:
compressionin classcom.tdunning.math.stats.TDigest
-
byteSize
public int byteSize()- Specified by:
byteSizein classcom.tdunning.math.stats.TDigest
-
smallByteSize
public int smallByteSize()- Specified by:
smallByteSizein classcom.tdunning.math.stats.TDigest
-
getScaleFunction
public com.tdunning.math.stats.ScaleFunction getScaleFunction() -
setScaleFunction
public void setScaleFunction(com.tdunning.math.stats.ScaleFunction scaleFunction) - Overrides:
setScaleFunctionin classcom.tdunning.math.stats.TDigest
-
asBytes
- Specified by:
asBytesin classcom.tdunning.math.stats.TDigest
-
asSmallBytes
- Specified by:
asSmallBytesin classcom.tdunning.math.stats.TDigest
-
toString
-