Skip to content

Commit

Permalink
Massive days work doing basic integration
Browse files Browse the repository at this point in the history
  • Loading branch information
dizzyd committed Dec 22, 2009
1 parent ccf28f8 commit 165b800
Show file tree
Hide file tree
Showing 13 changed files with 307 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .hgignore
@@ -1 +1,4 @@
.beam
tests/.*$
riak_bench$
erl_crash.dump$
2 changes: 1 addition & 1 deletion Makefile
@@ -1,3 +1,3 @@

all:
./rebar compile test
./rebar compile test escriptize
14 changes: 11 additions & 3 deletions ebin/riak_bench.app
Expand Up @@ -2,20 +2,28 @@
[{description, "Riak Benchmarking Suite"},
{vsn, "0.1"},
{modules, [
riak_bench,
riak_bench_app,
riak_bench_config,
riak_bench_driver_http_raw,
riak_bench_log,
riak_bench_keygen,
riak_bench_stats,
riak_bench_sup,
riak_bench_worker,
riak_bench_valgen,
riak_bench_utils
riak_bench_valgen
]},
{registered, [ riak_bench_sup ]},
{applications, [kernel,
stdlib,
sasl]},
{mod, {riak_bench_app, []}},
{env, [
%%
%% Base test output directory
%%
{test_dir, "tests"},

%%
%% Test duration (minutes)
%%
Expand All @@ -29,7 +37,7 @@
%%
%% Driver module for the current test
%%
{driver, riak_bench_driver_simple},
{driver, riak_bench_driver_http_raw},

%% Operations (and associated mix). Note that
%% the driver may not implement every operation.
Expand Down
13 changes: 13 additions & 0 deletions include/riak_bench.hrl
@@ -0,0 +1,13 @@


-define(FAIL_MSG(Str, Args), ?ERROR(Str, Args), halt(1)).

-define(CONSOLE(Str, Args), io:format(Str, Args)).

-define(DEBUG(Str, Args), riak_bench_log:log(debug, Str, Args)).
-define(INFO(Str, Args), riak_bench_log:log(info, Str, Args)).
-define(WARN(Str, Args), riak_bench_log:log(warn, Str, Args)).
-define(ERROR(Str, Args), riak_bench_log:log(error, Str, Args)).

-define(FMT(Str, Args), lists:flatten(io_lib:format(Str, Args))).

Binary file modified rebar
Binary file not shown.
77 changes: 77 additions & 0 deletions src/riak_bench.erl
@@ -0,0 +1,77 @@
%% -------------------------------------------------------------------
%%
%% riak_bench: Benchmarking Suite for Riak
%%
%% Copyright (c) 2009 Basho Techonologies
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied. See the License for the
%% specific language governing permissions and limitations
%% under the License.
%%
%% -------------------------------------------------------------------
-module(riak_bench).

-export([main/1]).

-include("riak_bench.hrl").

%% ====================================================================
%% API
%% ====================================================================

main([Config]) ->
%% Load baseline config
ok = application:load(riak_bench),

%% Initialize basic logging system
riak_bench_log:init(),

%% Load the config file
riak_bench_config:load(Config),

%% Setup working directory for this test. All logs, stats, and config
%% info will be placed here
{ok, Cwd} = file:get_cwd(),
TestId = id(),
TestDir = filename:join([Cwd, riak_bench_config:get(test_dir), TestId]),
ok = filelib:ensure_dir(filename:join(TestDir, "foobar")),
riak_bench_config:set(test_id, TestId),

%% Create a link to the test dir for convenience
TestLink = filename:join([Cwd, riak_bench_config:get(test_dir), "current"]),
[] = os:cmd(?FMT("rm -f ~s; ln -sf ~s ~s", [TestLink, TestDir, TestLink])),

%% Copy the config into the test dir for posterity
{ok, _} = file:copy(Config, filename:join(TestDir, filename:basename(Config))),

%% Spin up the application
application:start(sasl),
{ok, Pid} = riak_bench_sup:start_link(),

?CONSOLE("Started!\n", []),

?CONSOLE("Procs: ~p\n", [supervisor:which_children(Pid)]).



%% ====================================================================
%% Internal functions
%% ====================================================================


%%
%% Construct a string suitable for use as a unique ID for this test run
%%
id() ->
{{Y, M, D}, {H, Min, S}} = calendar:local_time(),
?FMT("~w~2..0w~2..0w_~2..0w~2..0w~2..0w", [Y, M, D, H, Min, S]).
65 changes: 65 additions & 0 deletions src/riak_bench_config.erl
@@ -0,0 +1,65 @@
%% -------------------------------------------------------------------
%%
%% riak_bench: Benchmarking Suite for Riak
%%
%% Copyright (c) 2009 Basho Techonologies
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied. See the License for the
%% specific language governing permissions and limitations
%% under the License.
%%
%% -------------------------------------------------------------------
-module(riak_bench_config).

-export([load/1,
set/2,
get/1]).

-include("riak_bench.hrl").

%% ===================================================================
%% Public API
%% ===================================================================

load(File) ->
case file:consult(File) of
{ok, Terms} ->
load_config(Terms);
{error, Reason} ->
?FAIL_MSG("Failed to parse config file ~s: ~p\n", [File, Reason])
end.

set(Key, Value) ->
ok = application:set_env(riak_bench, Key, Value).

get(Key) ->
case application:get_env(riak_bench, Key) of
{ok, Value} ->
Value;
undefined ->
erlang:error("Missing configuration key", [Key])
end.


%% ===================================================================
%% Internal functions
%% ===================================================================

load_config([]) ->
ok;
load_config([{Key, Value} | Rest]) ->
?MODULE:set(Key, Value),
load_config(Rest);
load_config([ Other | Rest]) ->
?WARN("Ignoring non-tuple config value: ~p\n", [Other]),
load_config(Rest).
34 changes: 24 additions & 10 deletions src/riak_bench_utils.erl → src/riak_bench_driver_http_raw.erl
Expand Up @@ -19,15 +19,29 @@
%% under the License.
%%
%% -------------------------------------------------------------------
-module(riak_bench_utils).
-module(riak_bench_driver_http_raw).

-export([get_env/1]).
-export([new/0,
run/4]).

get_env(Key) ->
case application:get_env(riak_bench, Key) of
undefined ->
erlang:error({app_env_key_not_found, Key});
{ok, Value} ->
Value
end.

-include("riak_bench.hrl").

%% ====================================================================
%% API
%% ====================================================================

new() ->
%% Make sure ibrowse is available
case code:which(ibrowse) of
non_existing ->
?FAIL_MSG("~s requires ibrowse to be installed.\n", [?MODULE]);
_ ->
ok
end,
{ok, undefined}.


run(get, KeyGen, ValueGen, State) ->
{ok, State};
run(put, KeyGen, ValueGen, State) ->
{ok, State}.
11 changes: 11 additions & 0 deletions src/riak_bench_keygen.erl
Expand Up @@ -20,3 +20,14 @@
%%
%% -------------------------------------------------------------------
-module(riak_bench_keygen).

-export([new/2]).


%% ====================================================================
%% API
%% ====================================================================

new(Type, Id) ->
ok.

63 changes: 63 additions & 0 deletions src/riak_bench_log.erl
@@ -0,0 +1,63 @@
%% -------------------------------------------------------------------
%%
%% riak_bench: Benchmarking Suite for Riak
%%
%% Copyright (c) 2009 Basho Techonologies
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied. See the License for the
%% specific language governing permissions and limitations
%% under the License.
%%
%% -------------------------------------------------------------------
-module(riak_bench_log).

-export([init/0,
log/3]).

%% ===================================================================
%% Public API
%% ===================================================================

init() ->
application:set_env(riak_bench, log_level, debug).

log(Level, Str, Args) ->
{ok, LogLevel} = application:get_env(riak_bench, log_level),
case should_log(LogLevel, Level) of
true ->
io:format(log_prefix(Level) ++ Str, Args);
false ->
ok
end.

%% ===================================================================
%% Internal functions
%% ===================================================================

should_log(debug, _) -> true;
should_log(info, debug) -> false;
should_log(info, _) -> true;
should_log(warn, debug) -> false;
should_log(warn, info) -> false;
should_log(warn, _) -> true;
should_log(error, error) -> true;
should_log(error, _) -> false;
should_log(_, _) -> false.

log_prefix(debug) -> "DEBUG:" ;
log_prefix(info) -> "INFO: ";
log_prefix(warn) -> "WARN: ";
log_prefix(error) -> "ERROR: ".



19 changes: 18 additions & 1 deletion src/riak_bench_sup.erl
Expand Up @@ -29,6 +29,7 @@
%% Supervisor callbacks
-export([init/1]).

-include("riak_bench.hrl").

%% Helper macro for declaring children of supervisor
-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).
Expand All @@ -46,4 +47,20 @@ start_link() ->
%% ===================================================================

init([]) ->
{ok, {{one_for_one, 5, 10}, [?CHILD(riak_bench_stats, worker)]}}.
%% Get the number concurrent workers we're expecting and generate child
%% specs for each
Workers = worker_specs(riak_bench_config:get(concurrent), []),
{ok, {{one_for_one, 5, 10}, [?CHILD(riak_bench_stats, worker)] ++ Workers}}.


%% ===================================================================
%% Internal functions
%% ===================================================================

worker_specs(0, Acc) ->
Acc;
worker_specs(Count, Acc) ->
Id = list_to_atom(lists:concat(['riak_bench_worker_', Count])),
Spec = {Id, {riak_bench_worker, start_link, [Count]},
permanent, 5000, worker, [riak_bench_worker]},
worker_specs(Count-1, [Spec | Acc]).
10 changes: 10 additions & 0 deletions src/riak_bench_valgen.erl
Expand Up @@ -20,3 +20,13 @@
%%
%% -------------------------------------------------------------------
-module(riak_bench_valgen).

-export([new/2]).


%% ====================================================================
%% API
%% ====================================================================

new(Type, Id) ->
ok.

0 comments on commit 165b800

Please sign in to comment.