Skip to content

Commit 3471aaf

Browse files
committed
Add a fixed size binary set generator
For testing CRDT sets we often want to generate a set of elements of elements of a certain size. In the past we used int generators, but sets of 32bit elements aren't realistic enough. We want to know how many elements of size X before performance degrades. To that end this commit adds a generator `{fixed_bin_set, ElemSize, Cardinality}` where `ElemSize` is the size of a random binary element and `Cardinality` is the size of the set. It makes use of the existing binary block generation code in valgen. It would be nice if we could generate variable size element sets in future. Maybe just multiple sets from which we pick at random?
1 parent 286f701 commit 3471aaf

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/basho_bench_valgen.erl

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,20 @@ new({fixed_bin, Size, Val}, _Id)
3838
when is_integer(Size), Size >= 0, is_integer(Val), Val >= 0, Val =< 255 ->
3939
Data = list_to_binary(lists:duplicate(Size, Val)),
4040
fun() -> Data end;
41+
%% Create a set of binaries with elements of Size and a cardinality of Card
42+
new({fixed_bin_set, Size, Card}, Id) when is_integer(Size), Size >= 0 ->
43+
%% This might be a bit hacky
44+
basho_bench_config:set(?VAL_GEN_SRC_SIZE, Size*Card),
45+
Source = init_source(Id),
46+
fun() -> data_block(fun aligned_offset/2, Source, Size) end;
4147
new({fixed_char, Size}, _Id)
4248
when is_integer(Size), Size >= 0 ->
4349
fun() -> list_to_binary(lists:map(fun (_) -> random:uniform(95)+31 end, lists:seq(1,Size))) end;
4450
new({exponential_bin, MinSize, Mean}, Id)
4551
when is_integer(MinSize), MinSize >= 0, is_number(Mean), Mean > 0 ->
4652
Source = init_source(Id),
4753
fun() -> data_block(Source, MinSize + trunc(basho_bench_stats:exponential(1 / Mean))) end;
48-
new({uniform_bin, MinSize, MaxSize}, Id)
54+
new({uniform_bin, MinSize, MaxSize}, Id)
4955
when is_integer(MinSize), is_integer(MaxSize), MinSize < MaxSize ->
5056
Source = init_source(Id),
5157
Diff = MaxSize - MinSize,
@@ -107,14 +113,23 @@ init_source(Id, Path) ->
107113
end,
108114
{?VAL_GEN_BLOB_CFG, size(Bin), Bin}.
109115

110-
data_block({SourceCfg, SourceSz, Source}, BlockSize) ->
116+
data_block(Source, BlockSize) ->
117+
data_block(fun random_offset/2, Source, BlockSize).
118+
119+
data_block(OffsetFun, {SourceCfg, SourceSz, Source}, BlockSize) ->
111120
case SourceSz - BlockSize > 0 of
112121
true ->
113-
Offset = random:uniform(SourceSz - BlockSize),
122+
Offset = OffsetFun(SourceSz, BlockSize),
114123
<<_:Offset/bytes, Slice:BlockSize/bytes, _Rest/binary>> = Source,
115124
Slice;
116125
false ->
117126
?WARN("~p is too small ~p < ~p\n",
118127
[SourceCfg, SourceSz, BlockSize]),
119128
Source
120129
end.
130+
131+
random_offset(SourceSz, BlockSize) ->
132+
random:uniform(SourceSz - BlockSize).
133+
134+
aligned_offset(SourceSz, BlockSize) ->
135+
(random:uniform(SourceSz - BlockSize) div BlockSize) * BlockSize.

0 commit comments

Comments
 (0)