Commits

Anonymous committed 49df0c5

Removing js_data testing app

Comments (0)

Files changed (7)

apps/js_data/ebin/js_data.app

-% -*- mode: erlang -*-
-{application, js_data,
- [{description,  "Blub"},
-  {vsn,          "0.1"},
-  {modules,      [jsd_generator, mrstress, stress_collector]},
-  {registered,   []},
-  {applications, [kernel, stdlib]}]}.

apps/js_data/rebar

Binary file removed.

apps/js_data/rebar.config

Empty file removed.

apps/js_data/src/jsd_generator.erl

--module(jsd_generator).
-
--compile([export_all]).
-%-export([generate/2]).
-
-start_proc_count() ->
-    spawn(fun() -> proc_count([], []) end).
-
-proc_count([], []) ->
-    timer:sleep(5000),
-    proc_count(erlang:processes(), []);
-proc_count(Last, Accum) ->
-    timer:sleep(5000),
-    Current = erlang:processes(),
-    case diff(Current, Last) of
-        [] ->
-            proc_count(Current, display_procs(Accum));
-        Procs ->
-            proc_count(Current, display_procs(Procs ++ Accum))
-    end.
-
-display_procs(Procs) ->
-    case prune(Procs) of
-        [] ->
-            [];
-        Orphans ->
-            Info = get_info(Orphans),
-            lists:foreach(fun({Pid, Mod}) ->
-                                  io:format("~p: ~p~n", [Pid, Mod]) end, Info),
-            io:format("~p total orphans~n", [length(Orphans)]),
-            Orphans
-    end.
-
-prune(Procs) ->
-    lists:filter(fun(P) ->
-                         lists:member(P, erlang:processes()) end, Procs).
-
-diff(Current, Last) ->
-    lists:foldl(fun(C, A) ->
-                        case lists:member(C, Last) of
-                            false ->
-                                [C|A];
-                            true ->
-                                A
-                        end end, [], Current).
-
-get_info(Procs) ->
-    lists:map(fun(P) ->
-                      {_, {Mod, _, _}} = erlang:process_info(P, current_function),
-                      {P, Mod} end, Procs).
-
-generate(Client, Count) ->
-    rand_init(),
-    Records = generate_data(Client, Count, []),
-    Client:put(riak_object:new(<<"customers">>, <<"customer_list">>, Records), 1).
-
-stress(Count) ->
-    {ok, C} = riak:client_connect('riak@127.0.0.1'),
-    jsd_generator:generate(C, 1000),
-    Start = erlang:now(),
-    stress(C, Count),
-    End = erlang:now(),
-    Elapsed = timer:now_diff(End, Start),
-    {Elapsed, Elapsed / Count}.
-
-stress(_Client, 0) ->
-    io:format("~n"),
-    ok;
-stress(Client, Count) ->
-    if
-        Count rem 1000 == 0 ->
-            io:format(".");
-        true ->
-            nop
-    end,
-    M = fun(Obj, _, _) ->
-                Values = riak_object:get_value(Obj), [proplists:get_value(avg_sales, V) || V <- Values] end,
-    R = fun(Values, _) ->
-                lists:sum(Values) / length(Values) end,
-    %M = <<"function(values, key_data, arg) { return values.map(function(value) { return value[\"avg_sales\"]; });};">>,
-    %R = <<"function(values, arg) { var accum = 0; values.map(function(v) { accum = accum + v;}); return accum / values.length; };">>,
-    {ok, _} = Client:mapred([{<<"customers">>, <<"customer_list">>}], [{map, {qfun, M}, none, false},
-                                                                       {reduce, {qfun, R}, none, true}]),
-    stress(Client, Count - 1).
-
-
-%% Internal functions
-generate_data(_Client, 0, Accum) ->
-    lists:reverse(Accum);
-generate_data(Client, Count, Accum) ->
-    generate_data(Client, Count - 1, [generate_record(Count)|Accum]).
-
-generate_record(Count) ->
-    [{id, generate_id(Count)},
-     {name, generate_name()},
-     {sales_group, rand_int(8)},
-     {avg_sales, rand_float(500)},
-     {last_sales_date, rand_timestamp(120)}].
-
-generate_id(Id) ->
-    list_to_binary(pad_id(integer_to_list(Id))).
-
-pad_id(Id) when length(Id) < 9 ->
-    pad_id(["0"|Id]);
-pad_id(Id) ->
-    Id.
-
-rand_timestamp(Limit) ->
-    Now = erlang:now(),
-    T1 = calendar:datetime_to_gregorian_seconds(calendar:now_to_universal_time(Now)) -
-         calendar:datetime_to_gregorian_seconds({{1970,1,1},{0,0,0}}),
-    T1 - (rand_int(Limit) * 86400).
-
-generate_name() ->
-    FirstName = rand_string(),
-    LastName = rand_string(),
-    list_to_binary([LastName, ", ", FirstName]).
-
-rand_float(Limit) ->
-    [F] = io_lib:format("~6.2f", [(random:uniform() * Limit)]),
-    list_to_float(string:strip(lists:flatten(F))).
-
-rand_int() ->
-    rand_int(2000000).
-
-rand_int(Limit) ->
-    random:uniform(Limit).
-
-rand_init() ->
-    {T1, T2, T3} = erlang:now(),
-    random:seed(T1, T2, T3).
-
-rand_string() ->
-    rand_string([rand_alpha()], rand_int(15)).
-
-rand_string(Accum, 0) ->
-    lists:reverse(Accum);
-rand_string(Accum, Count) ->
-    rand_string([rand_alpha(lower)|Accum], Count - 1).
-
-rand_alpha(lower) ->
-    rand_alpha() + 31.
-
-rand_alpha() ->
-    random:uniform(26) + 64.
-
-integer_to_binary(N) ->
-    list_to_binary(integer_to_list(N)).

apps/js_data/src/mrstress.erl

--module(mrstress).
-
--compile([export_all]).
-
-populate(InputSize) ->
-    {ok, Client} = riak:client_connect('riak@127.0.0.1'),
-    create_entries(Client, generate_inputs(<<"stress">>, InputSize)).
-
-create_entries(_Client, []) ->
-    ok;
-create_entries(Client, [{Bucket, Key}|T]) ->
-    Obj = riak_object:new(Bucket, Key, <<"1">>),
-    Md = dict:store(<<"content-type">>, "text/plain", dict:new()),
-    Client:put(riak_object:update_metadata(Obj, Md), 1),
-    create_entries(Client, T).
-
-config(Lang, Clients, Count, KeyCount) ->
-    [{lang, Lang}, {clients, Clients}, {count, Count}, {keys, KeyCount}].
-
-stress(Config) ->
-    {T1, T2, T3} = erlang:now(),
-    random:seed(T1, T2, T3),
-    Lang = proplists:get_value(lang, Config),
-    Count = proplists:get_value(count, Config, 100),
-    Clients = proplists:get_value(clients, Config, 1),
-    KeyCount = proplists:get_value(keys, Config, 10),
-    InputPercent = proplists:get_value(input_size, Config, 0.15),
-    InputSize = erlang:trunc(KeyCount * InputPercent),
-    io:format("Using ~p out of ~p entries per mapred call~n", [InputSize, KeyCount]),
-    populate(KeyCount),
-    RawSuffix = integer_to_list(calendar:datetime_to_gregorian_seconds(calendar:now_to_local_time(erlang:now()))),
-    Suffix = string:substr(RawSuffix, length(RawSuffix) - 5),
-    LogFile = proplists:get_value(log_file, Config, "/tmp/stress_" ++ Suffix ++ ".log"),
-    stress_collector:start(LogFile),
-    Inputs = generate_inputs(<<"stress">>, KeyCount),
-    start_test(Lang, Count, Clients, InputSize, Inputs),
-    wait_for_end(Clients).
-
-wait_for_end(0) ->
-    timer:sleep(1000),
-    stress_collector:test_complete();
-wait_for_end(Clients) ->
-    receive
-        done ->
-            wait_for_end(Clients - 1)
-    end.
-
-start_test(_Lang, _Count, 0, _, _) ->
-    ok;
-start_test(Lang, Count, Clients, InputSize, Inputs) ->
-    Owner = self(),
-    spawn(fun() -> {ok, Client} = riak:client_connect('riak@127.0.0.1'),
-                   stress(Lang, Count, Client, Owner, Inputs, InputSize) end),
-    start_test(Lang, Count, Clients - 1, InputSize, Inputs).
-
-stress(_Lang, 0, _Client, Owner, _, _) ->
-    Owner ! done,
-    ok;
-stress(javascript, Count, Client, Owner, Inputs, InputSize) ->
-    %M = <<"function(v, _, _) { var value = v[\"values\"][0][\"data\"]; return [parseInt(value)]; }">>,
-    R = <<"function(v, _) { var sum = 0; v.forEach(function(x) { sum = sum + x; }); return [sum]; }">>,
-    R1 = <<"function(values, _) { return values.map(function(v) { return parseInt(v); }); }">>,
-    Selected = select_inputs(Inputs, InputSize, []),
-    Start = erlang:now(),
-    case Client:mapred(Selected, [{map, {jsfun, <<"Riak.mapValues">>}, none, false},
-                                  {reduce, {jsanon, R1}, none, false},
-                                  {reduce, {jsanon, R}, none, true}]) of
-        {ok, [InputSize]} ->
-            End = erlang:now(),
-            stress_collector:log(timer:now_diff(End, Start), 0),
-            stress(javascript, Count - 1, Client, Owner, Inputs, InputSize);
-        _Error ->
-            End = erlang:now(),
-            io:format("Error: ~p~n", [_Error]),
-            stress_collector:log(0, timer:now_diff(End, Start)),
-            stress(javascript, 0, Client, Owner, Inputs, InputSize)
-    end;
-
-stress(erlang, Count, Client, Owner, Inputs, InputSize) ->
-    M = fun(Obj, _, _) ->
-                Value = riak_object:get_value(Obj),
-                [list_to_integer(binary_to_list(Value))] end,
-    R = fun(Values, _) -> [lists:sum(Values)] end,
-    Selected = select_inputs(Inputs, InputSize, []),
-    Correct = length(Selected),
-    Start = erlang:now(),
-    case Client:mapred(Selected, [{map, {qfun, M}, none, false},
-                                {reduce, {qfun, R}, none, true}]) of
-        {ok, [Correct]} ->
-            End = erlang:now(),
-            stress_collector:log(timer:now_diff(End, Start), 0),
-            stress(erlang, Count - 1, Client, Owner, Inputs, InputSize);
-        _Error ->
-            End = erlang:now(),
-            io:format("Error: ~p~n", [_Error]),
-            stress_collector:log(0, timer:now_diff(End, Start)),
-            stress(erlang, Count, Client, Owner, Inputs, InputSize)
-    end.
-
-generate_inputs(Bucket, Size) ->
-    [{Bucket, list_to_binary("test" ++ integer_to_list(X))} || X <- lists:seq(1, Size)].
-
-select_inputs(_Inputs, InputSize, Accum) when length(Accum) == InputSize ->
-    Accum;
-select_inputs(Inputs, InputSize, Accum) ->
-    Pos = random:uniform(InputSize),
-    Input = lists:nth(Pos, Inputs),
-    case lists:member(Input, Accum) of
-        false ->
-            select_inputs(Inputs, InputSize, [Input|Accum]);
-        true ->
-            select_inputs(Inputs, InputSize, Accum)
-    end.

apps/js_data/src/stress_collector.erl

--module(stress_collector).
-
--behaviour(gen_server).
-
-%% API
--export([start/1, log/2, test_complete/0]).
-
-%% gen_server callbacks
--export([init/1, handle_call/3, handle_cast/2, handle_info/2,
-         terminate/2, code_change/3]).
-
--define(SERVER, ?MODULE).
-
--record(state, {fd, counter}).
-
-log(Success, Error) ->
-    gen_server:cast(?SERVER, {log, Success, Error}).
-
-test_complete() ->
-    gen_server:cast(?SERVER, test_complete).
-
-start(FileName) ->
-    gen_server:start({local, ?SERVER}, ?MODULE, [FileName], []).
-
-init([FileName]) ->
-    {ok, Fd} = file:open(FileName, [write]),
-    file:write(Fd, io_lib:format("TestId,Success,Error~n", [])),
-    {ok, #state{fd=Fd, counter=1}}.
-
-handle_call(_Request, _From, State) ->
-    {reply, ignore, State}.
-
-handle_cast(test_complete, #state{fd=Fd}=State) ->
-    file:close(Fd),
-    {stop, normal, State};
-handle_cast({log, SuccessTime, ErrorTime}, #state{fd=Fd, counter=Counter}=State) ->
-    file:write(Fd, io_lib:format("~s,~s,~s~n", [integer_to_list(Counter), integer_to_list(SuccessTime),
-                                                integer_to_list(ErrorTime)])),
-    {noreply, State#state{counter=Counter + 1}};
-
-handle_cast(_Msg, State) ->
-    {noreply, State}.
-
-handle_info(_Info, State) ->
-    {noreply, State}.
-
-terminate(_Reason, _State) ->
-    ok.
-
-code_change(_OldVsn, State, _Extra) ->
-    {ok, State}.
-
-%% Internal functions

apps/js_data/start_client

-#!/bin/bash
-./rebar compile;
-erl -name 'client@127.0.0.1' -setcookie riak -pa ../riak/ebin -pa ebin
-