Permalink
Browse files

Merge branch slf-value_generator_blob_file -> master

  • Loading branch information...
2 parents 55c94db + 7dd24d9 commit ec9042b7234e15c7707f6f8e770305bad2cf40f9 Scott Lystig Fritchie committed Jan 26, 2013
Showing with 27 additions and 13 deletions.
  1. +2 −0 include/basho_bench.hrl
  2. +25 −13 src/basho_bench_valgen.erl
View
@@ -11,3 +11,5 @@
-define(FMT(Str, Args), lists:flatten(io_lib:format(Str, Args))).
+-define(VAL_GEN_BLOB_CFG, value_generator_blob_file).
+-define(VAL_GEN_SRC_SIZE, value_generator_source_size).
View
@@ -30,19 +30,19 @@
%% API
%% ====================================================================
-new({fixed_bin, Size}, _Id) ->
- Source = init_source(),
+new({fixed_bin, Size}, Id) ->
+ Source = init_source(Id),
fun() -> data_block(Source, Size) end;
new({fixed_bin, Size, Val}, _Id) ->
Data = list_to_binary(lists:duplicate(Size, Val)),
fun() -> Data end;
new({fixed_char, Size}, _Id) ->
fun() -> list_to_binary(lists:map(fun (_) -> random:uniform(95)+31 end, lists:seq(1,Size))) end;
-new({exponential_bin, MinSize, Mean}, _Id) ->
- Source = init_source(),
- fun() -> data_block(Source, MinSize + trunc(basho_bench_stats:exponential(1 / Mean))) end;
-new({uniform_bin, MinSize, MaxSize}, _Id) ->
- Source = init_source(),
+new({exponential_bin, MinSize, Mean}, Id) ->
+ Source = init_source(Id),
+ fun() -> data_block(Source, MinSize + trunc(basho_stats_rv:exponential(1 / Mean))) end;
+new({uniform_bin, MinSize, MaxSize}, Id) ->
+ Source = init_source(Id),
Diff = MaxSize - MinSize,
fun() -> data_block(Source, MinSize + random:uniform(Diff)) end;
new({function, Module, Function, Args}, Id) ->
@@ -66,18 +66,30 @@ dimension(_Other, _) ->
%% Internal Functions
%% ====================================================================
-init_source() ->
- SourceSz = basho_bench_config:get(value_generator_source_size, 1048576),
- {SourceSz, crypto:rand_bytes(SourceSz)}.
+init_source(Id) ->
+ init_source(Id, basho_bench_config:get(?VAL_GEN_BLOB_CFG, undefined)).
-data_block({SourceSz, Source}, BlockSize) ->
+init_source(Id, undefined) ->
+ if Id == 1 -> ?DEBUG("random source\n", []);
+ true -> ok
+ end,
+ SourceSz = basho_bench_config:get(?VAL_GEN_SRC_SIZE, 1048576),
+ {?VAL_GEN_SRC_SIZE, SourceSz, crypto:rand_bytes(SourceSz)};
+init_source(Id, Path) ->
+ {Path, {ok, Bin}} = {Path, file:read_file(Path)},
+ if Id == 1 -> ?DEBUG("path source ~p ~p\n", [size(Bin), Path]);
+ true -> ok
+ end,
+ {?VAL_GEN_BLOB_CFG, size(Bin), Bin}.
+
+data_block({SourceCfg, SourceSz, Source}, BlockSize) ->
case SourceSz - BlockSize > 0 of
true ->
Offset = random:uniform(SourceSz - BlockSize),
<<_:Offset/bytes, Slice:BlockSize/bytes, _Rest/binary>> = Source,
Slice;
false ->
- ?WARN("value_generator_source_size is too small; it needs a value > ~p.\n",
- [BlockSize]),
+ ?WARN("~p is too small ~p < ~p\n",
+ [SourceCfg, SourceSz, BlockSize]),
Source
end.

0 comments on commit ec9042b

Please sign in to comment.