Browse Source

Merge branch 'elli'

Heinz N. Gies 12 years ago
parent
commit
01bb336fd3

BIN
elli/.benchmark_config.swp


+ 5 - 0
elli/.gitignore

@@ -0,0 +1,5 @@
+erl_crash.dump
+__init__.py
+deps
+ebin
+*.deb

+ 12 - 0
elli/benchmark_config

@@ -0,0 +1,12 @@
+{
+  "framework": "elli",
+  "tests": [{
+    "default": {
+      "setup_file": "setup_erlang",
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/db?queries=",
+      "port": 8080,
+      "sort": 39
+  }}]
+}

BIN
elli/rebar


+ 6 - 0
elli/rebar.config

@@ -0,0 +1,6 @@
+{deps,
+ [
+  {jiffy, ".*", {git, "https://github.com/davisp/jiffy.git", {tag, "0.8.3"}}},
+  {emysql, ".*", {git, "https://github.com/Eonblast/Emysql.git"}},
+  {elli, "", {git, "git://github.com/knutin/elli.git"}}
+ ]}.

+ 23 - 0
elli/setup_erlang.py

@@ -0,0 +1,23 @@
+
+import subprocess
+import sys
+import setup_util
+
+def start(args):
+#  setup_util.replace_text("rails/config/database-ruby.yml", "host: .*", "host: " + args.database_host)
+  
+  try:
+    subprocess.check_call("/usr/bin/curl -klO https://elearning.erlang-solutions.com/couchdb//rbingen_adapter//package_R16B_precise64_1361901944/esl-erlang_16.b-1~ubuntu~precise_amd64.deb", shell=True, cwd="elli")
+    subprocess.check_call("sudo /usr/bin/dpkg --install esl-erlang_16.b-1~ubuntu~precise_amd64.deb", shell=True, cwd="elli")
+    subprocess.check_call("./rebar get-deps", shell=True, cwd="elli")
+    subprocess.check_call("./rebar compile", shell=True, cwd="elli")
+    subprocess.check_call("erl -pa ebin deps/*/ebin -s elli_bench -noshell -detached", shell=True, cwd="elli")
+    return 0
+  except subprocess.CalledProcessError:
+    return 1
+def stop():
+  try:
+    subprocess.check_call("killall beam.smp", shell=True, cwd="/usr/bin")
+    return 0
+  except subprocess.CalledProcessError:
+    return 1

+ 12 - 0
elli/src/elli_bench.app.src

@@ -0,0 +1,12 @@
+{application, elli_bench,
+ [
+  {description, ""},
+  {vsn, "1"},
+  {registered, []},
+  {applications, [
+                  kernel,
+                  stdlib
+                 ]},
+  {mod, { elli_bench_app, []}},
+  {env, []}
+ ]}.

+ 5 - 0
elli/src/elli_bench.erl

@@ -0,0 +1,5 @@
+-module(elli_bench).
+-export([start/0]).
+
+start() ->
+	application:start(elli_bench).

+ 16 - 0
elli/src/elli_bench_app.erl

@@ -0,0 +1,16 @@
+-module(elli_bench_app).
+
+-behaviour(application).
+
+%% Application callbacks
+-export([start/2, stop/1]).
+
+%% ===================================================================
+%% Application callbacks
+%% ===================================================================
+
+start(_StartType, _StartArgs) ->
+    elli_bench_sup:start_link().
+
+stop(_State) ->
+    ok.

+ 36 - 0
elli/src/elli_bench_cb.erl

@@ -0,0 +1,36 @@
+-module(elli_bench_cb).
+-export([handle/2, handle_event/3]).
+
+-include_lib("elli/include/elli.hrl").
+-behaviour(elli_handler).
+
+handle(Req, _Args) ->
+    %% Delegate to our handler function
+    handle(Req#req.method, elli_request:path(Req), Req).
+
+handle('GET',[<<"json">>], _Req) ->
+    %% Reply with a normal response. 'ok' can be used instead of '200'
+    %% to signal success.
+    {ok, [{<<"Content-Type">>, <<"application/json">>}], jiffy:encode({[{<<"message">>, <<"Hello, World!">>}]})};
+
+handle('GET',[<<"db">>], Req) ->
+        random:seed(erlang:now()),
+        JSON = case elli_request:get_arg(<<"queries">>, Req) of
+		undefined ->
+			{result_packet, _, _, [[ID, Rand]], _} = emysql:execute(test_pool, db_stmt, [random:uniform(10000)]),
+			[{[{<<"id">>, ID}, {<<"randomNumber">>, Rand}]}];
+		N ->
+			I = list_to_integer(binary_to_list(N)),
+			Res = [ {[{<<"id">>, ID}, {<<"randomNumber">>, Rand}]} || 
+			        {result_packet, _, _, [[ID, Rand]], _} <- [emysql:execute(test_pool, db_stmt, [random:uniform(10000)]) || _ <- lists:seq(1, I) ]],
+			Res
+		end,
+    {ok, [{<<"Content-Type">>, <<"application/json">>}], jiffy:encode(JSON)};
+
+handle(_, _, _Req) ->
+    {404, [], <<"Not Found">>}.
+
+%% @doc: Handle request events, like request completed, exception
+%% thrown, client timeout, etc. Must return 'ok'.
+handle_event(_Event, _Data, _Args) ->
+    ok.

+ 43 - 0
elli/src/elli_bench_sup.erl

@@ -0,0 +1,43 @@
+
+-module(elli_bench_sup).
+
+-behaviour(supervisor).
+
+%% API
+-export([start_link/0]).
+
+%% Supervisor callbacks
+-export([init/1]).
+
+%% Helper macro for declaring children of supervisor
+-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).
+
+%% ===================================================================
+%% API functions
+%% ===================================================================
+
+start_link() ->
+    supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+%% ===================================================================
+%% Supervisor callbacks
+%% ===================================================================
+
+init([]) ->
+    crypto:start(),
+    application:start(emysql),
+    emysql:add_pool(test_pool, 32,
+       "benchmarkdbuser", "benchmarkdbpass", "localhost", 3306,
+       "hello_world", utf8),
+    emysql:prepare(db_stmt, <<"SELECT * FROM World where id = ?">>),
+    ElliOpts = [{callback, elli_bench_cb}, {port, 8080}],
+    ElliSpec = {
+        fancy_http,
+        {elli, start_link, [ElliOpts]},
+        permanent,
+        5000,
+        worker,
+        [elli]},
+
+    {ok, { {one_for_one, 5, 10}, [ElliSpec]} }.
+