Skip to content

Commit 3953aef

Browse files
committed
Move storage for basho_bench_config to application, as opposed to janky custom orddict
1 parent bb6d3c9 commit 3953aef

1 file changed

Lines changed: 13 additions & 130 deletions

File tree

src/basho_bench_config.erl

Lines changed: 13 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@
4040

4141
-include("basho_bench.hrl").
4242

43-
-record(basho_bench_config_state, {config_keys}).
43+
-record(basho_bench_config_state, {}).
4444

4545
-type state() :: #basho_bench_config_state{}.
4646
%% ===================================================================
4747
%% Public API
4848
%% ===================================================================
4949

50+
%% Todo: ensure_started before calling on any gen_server APIs.
5051
ensure_started() ->
5152
start_link().
5253

@@ -65,15 +66,15 @@ get(Key) ->
6566
case gen_server:call({global, ?MODULE}, {get, Key}) of
6667
{ok, Value} ->
6768
Value;
68-
error ->
69+
undefined ->
6970
erlang:error("Missing configuration key", [Key])
7071
end.
7172

7273
get(Key, Default) ->
7374
case gen_server:call({global, ?MODULE}, {get, Key}) of
7475
{ok, Value} ->
7576
Value;
76-
error ->
77+
undefined ->
7778
Default
7879
end.
7980

@@ -116,7 +117,7 @@ normalize_ip_entry(IP, Normalized, DefaultPort) ->
116117

117118
-spec init(term()) -> {ok, state()}.
118119
init(_Args) ->
119-
State = #basho_bench_config_state{config_keys = base_config()},
120+
State = #basho_bench_config_state{},
120121
{ok, State}.
121122

122123
-spec code_change(term(), state(), term()) -> {ok, state()}.
@@ -129,141 +130,23 @@ terminate(_Reason, _State) ->
129130

130131
handle_call({load_files, FileNames}, _From, State) ->
131132
TermsList = get_keys_from_files(FileNames),
132-
ConfigKeys2 = load_termlist(TermsList, State#basho_bench_config_state.config_keys),
133-
State2 = State#basho_bench_config_state{config_keys = ConfigKeys2},
134-
{reply, ok, State2};
135-
handle_call({set, app_run_mode, Value}, _From, State) ->
136-
application:set_env(basho_bench_app, app_run_mode, Value),
137133
{reply, ok, State};
138-
handle_call({get, app_run_mode}, _From, State) ->
139-
case application:get_env(basho_bench_app, app_run_mode) of
140-
{ok, Value} ->
141-
{reply, {ok, Value}, State};
142-
undefined ->
143-
{reply, error, State}
144-
end;
134+
145135
handle_call({set, Key, Value}, _From, State) ->
146-
NewKVs = orddict:store(Key, Value, State#basho_bench_config_state.config_keys),
147-
State2 = State#basho_bench_config_state{config_keys = NewKVs},
148-
{reply, ok, State2};
136+
application:set_env(basho_bench, Key, Value),
137+
{reply, ok, State};
149138
handle_call({get, Key}, _From, State) ->
150-
Value = orddict:find(Key, State#basho_bench_config_state.config_keys),
139+
Value = application:get_env(basho_bench, Key),
151140
{reply, Value, State}.
141+
152142
get_keys_from_files(Files) ->
153-
[ case file:consult(File) of
143+
KVs = [ case file:consult(File) of
154144
{ok, Terms} ->
155145
Terms;
156146
{error, Reason} ->
157147
?FAIL_MSG("Failed to parse config file ~s: ~p\n", [File, Reason]),
158148
throw(invalid_config),
159149
notokay
160-
end || File <- Files ].
161-
162-
163-
load_termlist(TermList, ExistingConfig) ->
164-
NewKVs = lists:flatten(TermList),
165-
FoldFun = fun({Key, Value}, Accum) ->
166-
orddict:store(Key, Value, Accum)
167-
end,
168-
lists:foldl(FoldFun, ExistingConfig, NewKVs).
169-
170-
base_config() ->
171-
orddict:from_list([
172-
%% Run mode: How should basho_bench started as a separate node, or part of an
173-
%% other node. The default is standalone, other option is included.
174-
175-
%%
176-
%% Mode of load generation:
177-
%% max - Generate as many requests as possible per worker
178-
%% {rate, Rate} - Exp. distributed Mean reqs/sec
179-
%%
180-
{mode, {rate, 5}},
181-
182-
%%
183-
%% Default log level
184-
%%
185-
{log_level, debug},
186-
187-
%%
188-
%% Base test output directory
189-
%%
190-
{test_dir, "tests"},
150+
end || File <- Files ],
151+
[application:set_env(basho_bench, Key, Value) || {Key, Value} <- KVs].
191152

192-
%%
193-
%% Test duration (minutes)
194-
%%
195-
{duration, 5},
196-
197-
%%
198-
%% Number of concurrent workers
199-
%%
200-
{concurrent, 3},
201-
202-
%%
203-
%% Driver module for the current test
204-
%%
205-
{driver, basho_bench_driver_http_raw},
206-
207-
%%
208-
%% Operations (and associated mix). Note that
209-
%% the driver may not implement every operation.
210-
%%
211-
{operations, [{get, 4},
212-
{put, 4},
213-
{delete, 1}]},
214-
215-
%%
216-
%% Interval on which to report latencies and status (seconds)
217-
%%
218-
{report_interval, 10},
219-
220-
%%
221-
%% Key generators
222-
%%
223-
%% {uniform_int, N} - Choose a uniformly distributed integer between 0 and N
224-
%%
225-
{key_generator, {uniform_int, 100000}},
226-
227-
%%
228-
%% Value generators
229-
%%
230-
%% {fixed_bin, N} - Fixed size binary blob of N bytes
231-
%%
232-
{value_generator, {fixed_bin, 100}}
233-
]).
234-
-ifdef(TEST).
235-
load_files_test() ->
236-
%% Extracted from bitcask, and null test.
237-
KVs = [[{mode,max},
238-
{duration,1},
239-
{report_interval,1},
240-
{concurrent,8},
241-
{driver,basho_bench_driver_null},
242-
{key_generator,{partitioned_sequential_int,5000000}},
243-
{disable_sequential_int_progress_report,true},
244-
{value_generator,{fixed_bin,10248}},
245-
{operations,[{do_something,7},{an_error,1},{another_error,2}]}],
246-
[{mode,max},
247-
{duration,10},
248-
{concurrent,1},
249-
{driver,basho_bench_driver_bitcask},
250-
{key_generator,{int_to_bin_bigendian,{uniform_int,5000000}}},
251-
{value_generator,{fixed_bin,10000}},
252-
{operations,[{get,1},{put,1}]},
253-
{code_paths,["../../public/bitcask"]},
254-
{bitcask_dir,"/tmp/bitcask.bench"},
255-
{bitcask_flags,[o_sync]}]],
256-
KVOrdDict = [{bitcask_dir,"/tmp/bitcask.bench"},
257-
{bitcask_flags,[o_sync]},
258-
{code_paths,["../../public/bitcask"]},
259-
{concurrent,1},
260-
{disable_sequential_int_progress_report,true},
261-
{driver,basho_bench_driver_bitcask},
262-
{duration,10},
263-
{key_generator,{int_to_bin_bigendian,{uniform_int,5000000}}},
264-
{mode,max},
265-
{operations,[{get,1},{put,1}]},
266-
{report_interval,1},
267-
{value_generator,{fixed_bin,10000}}],
268-
?assertEqual(KVOrdDict, load_termlist(KVs, [])).
269-
-endif.

0 commit comments

Comments
 (0)