View Source ddskerl_ets (ddskerl v0.2.1)
DDSketch implementation in Erlang.
This implements an optimised pre-allocated bounded bucket count, that is, on a degenerate case, memory consumption won't grow but quantiles might lose accuracy as values escape bounds.
In this optimisation, buckets are preallocated using ets
tables.
Values within (0,1)
will be inserted into the underflow bucket;
values above the expected limit will be inserted into the overflow bucket.
Calculating the bucket size
If you have an expected highest value M
and a given error E
,
your ideal bucket size would be given by the formula:
ceil(math:log2(M) * (1.0 / math:log2((1 + E) / (1 - E))))
.
For example, if you measure microseconds and you expect no operation to take more than an hour:
1> F = fun(M, E) -> ceil(math:log2(M) * (1.0 / math:log2((1 + E) / (1 - E)))) end.
2> F(3600000000, 0.01).
1101
Note than for an expected error of 1% and 2184 buckets, we can fit values all the way as big to the biggest 64bits signed integer. If we're measuring picoseconds, this would suffice to measure 107 days.
When to use
This is a good choice when shared ets tables are a more efficient way to ensure dynamicity and potentially code upgrades.
For example:
ddskerl_ets:new(#{ets_table => Table, name => Name, ...}).
...
ddskerl_ets:insert(Table, Name, Value).
...
ddskerl_ets:quantile(Table, Name, Q).
Summary
Functions
Insert a value into the DDSketch.
Insert a value into the DDSketch.
Merge two DDSketch instances.
Merge two DDSketch instances.
Create a new DDSketch instance.
Create a new DDSketch instance.
Calculate the quantile of a DDSketch.
Calculate the quantile of a DDSketch.
Reset the DDSketch values to zero
Reset the DDSketch values to zero
Get the sum of elements in the DDSketch.
Get the sum of elements in the DDSketch.
Get the total number of elements in the DDSketch.
Get the total number of elements in the DDSketch.
Types
-opaque ddsketch()
DDSketch instance.
-opaque object()
DDSketch tuple.
-type opts() :: #{ets_table := ets:tab(), name := term(), error := float(), bound := non_neg_integer()}.
Options for the DDSketch.
ets_table
refers to the table weher the sketch is stored,
name
is the key to use when storing the sketch in the ets table.
Functions
Insert a value into the DDSketch.
Insert a value into the DDSketch.
Merge two DDSketch instances.
Merge two DDSketch instances.
Create a new DDSketch instance.
-spec new(ets:table(), term(), float(), non_neg_integer()) -> boolean().
Create a new DDSketch instance.
Calculate the quantile of a DDSketch.
Calculate the quantile of a DDSketch.
Reset the DDSketch values to zero
Reset the DDSketch values to zero
-spec sum(ddsketch()) -> non_neg_integer().
Get the sum of elements in the DDSketch.
-spec sum(ets:table(), term()) -> non_neg_integer().
Get the sum of elements in the DDSketch.
-spec total(ddsketch()) -> non_neg_integer().
Get the total number of elements in the DDSketch.
-spec total(ets:table(), term()) -> non_neg_integer().
Get the total number of elements in the DDSketch.