Browse Source

Merge branch 'erlang' of https://github.com/Licenser/FrameworkBenchmarks into Licenser-erlang

Patrick Falls 12 years ago
parent
commit
a12990cf07

+ 5 - 0
cowboy/.gitignore

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

+ 4 - 0
cowboy/Makefile

@@ -0,0 +1,4 @@
+all:
+	./rebar get-deps
+	./rebar compile
+	erl -pa ebin deps/*/ebin -s hello_world -noshell -detached

+ 12 - 0
cowboy/benchmark_config

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

BIN
cowboy/rebar


+ 7 - 0
cowboy/rebar.config

@@ -0,0 +1,7 @@
+{deps,
+ [
+  {jiffy, ".*", {git, "https://github.com/davisp/jiffy.git", {tag, "0.8.3"}}},
+  {mimetypes, ".*", {git, "http://github.com/spawngrid/mimetypes.git", {branch, master}}},
+  {emysql, ".*", {git, "https://github.com/Eonblast/Emysql.git"}},
+  {cowboy, ".*", {git, "https://github.com/extend/cowboy.git", {tag, "0.8.3"}}}
+ ]}.

+ 21 - 0
cowboy/setup_erlang.py

@@ -0,0 +1,21 @@
+
+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("./rebar get-deps", shell=True, cwd="cowboy")
+    subprocess.check_call("./rebar compile", shell=True, cwd="cowboy")
+    subprocess.check_call("erl -pa ebin deps/*/ebin -s hello_world -noshell -detached", shell=True, cwd="cowboy")
+    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

+ 29 - 0
cowboy/src/db_handler.erl

@@ -0,0 +1,29 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+%% @doc Hello world handler.
+-module(db_handler).
+
+-export([init/3]).
+-export([handle/2]).
+-export([terminate/3]).
+
+init(_Transport, Req, []) ->
+	{ok, Req, undefined}.
+
+handle(Req, State) ->
+        random:seed(erlang:now()),
+        {JSON, Req2} = case cowboy_req:qs_val(<<"queries">>, Req) of
+		{undefined, Req1} ->
+			{result_packet, _, _, [[ID, Rand]], _} = emysql:execute(test_pool, db_stmt, [random:uniform(10000)]),
+			{[{[{<<"id">>, ID}, {<<"randomNumber">>, Rand}]}], Req1};
+		{N, Req1} ->
+			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, Req1}
+		end,
+	{ok, Req3} = cowboy_req:reply(200, [{<<"Content-Type">>, <<"application/json">>}], jiffy:encode(JSON), Req2),
+	{ok, Req3, State}.
+
+terminate(_Reason, _Req, _State) ->
+	ok.

+ 15 - 0
cowboy/src/hello_world.app.src

@@ -0,0 +1,15 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+{application, hello_world, [
+	{description, "Cowboy Hello World example."},
+	{vsn, "1"},
+	{modules, []},
+	{registered, []},
+	{applications, [
+		kernel,
+		stdlib,
+		cowboy
+	]},
+	{mod, {hello_world_app, []}},
+	{env, []}
+]}.

+ 14 - 0
cowboy/src/hello_world.erl

@@ -0,0 +1,14 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+-module(hello_world).
+
+%% API.
+-export([start/0]).
+
+%% API.
+
+start() ->
+	ok = application:start(crypto),
+	ok = application:start(ranch),
+	ok = application:start(cowboy),
+	ok = application:start(hello_world).

+ 32 - 0
cowboy/src/hello_world_app.erl

@@ -0,0 +1,32 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+%% @private
+-module(hello_world_app).
+-behaviour(application).
+
+%% API.
+-export([start/2]).
+-export([stop/1]).
+
+%% API.
+
+start(_Type, _Args) ->
+        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 = ?">>),
+	Dispatch = cowboy_router:compile([
+		{'_', [
+			{"/json", json_handler, []},
+			{"/db", db_handler, []}
+		]}
+	]),
+	{ok, _} = cowboy:start_http(http, 100, [{port, 8080}], [
+		{env, [{dispatch, Dispatch}]}
+	]),
+	hello_world_sup:start_link().
+
+stop(_State) ->
+	ok.

+ 23 - 0
cowboy/src/hello_world_sup.erl

@@ -0,0 +1,23 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+%% @private
+-module(hello_world_sup).
+-behaviour(supervisor).
+
+%% API.
+-export([start_link/0]).
+
+%% supervisor.
+-export([init/1]).
+
+%% API.
+
+-spec start_link() -> {ok, pid()}.
+start_link() ->
+	supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+%% supervisor.
+
+init([]) ->
+	Procs = [],
+	{ok, {{one_for_one, 10, 10}, Procs}}.

+ 18 - 0
cowboy/src/json_handler.erl

@@ -0,0 +1,18 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+%% @doc Hello world handler.
+-module(json_handler).
+
+-export([init/3]).
+-export([handle/2]).
+-export([terminate/3]).
+
+init(_Transport, Req, []) ->
+	{ok, Req, undefined}.
+
+handle(Req, State) ->
+	{ok, Req2} = cowboy_req:reply(200, [{<<"Content-Type">>, <<"application/json">>}], jiffy:encode({[{<<"message">>, <<"Hello, World!">>}]}), Req),
+	{ok, Req2, State}.
+
+terminate(_Reason, _Req, _State) ->
+	ok.

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"}}
+ ]}.

+ 21 - 0
elli/setup_erlang.py

@@ -0,0 +1,21 @@
+
+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("./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]} }.
+

+ 6 - 0
installer.py

@@ -30,6 +30,12 @@ class Installer:
     # Languages
     #######################################
 
+    #
+    # Erlang
+    #
+    self.__run_command("curl -klO https://elearning.erlang-solutions.com/couchdb//rbingen_adapter//package_R16B_precise64_1361901944/esl-erlang_16.b-1~ubuntu~precise_amd64.deb")
+    self.__run_command("sudo /usr/bin/dpkg --install esl-erlang_16.b-1~ubuntu~precise_amd64.deb")
+
     #
     # Python
     #

+ 3 - 3
nodejs/hello.js

@@ -18,10 +18,10 @@ var http = require('http')
   , url = require('url')
   , async = require('async')
   , mongoose = require('mongoose')
-  , conn = mongoose.connect('mongodb://localhost/hello_world')
+  , conn = mongoose.connect('mongodb://172.16.234.132/hello_world')
   , mysql = require('mysql')
   , pool  = mysql.createPool({
-      host: 'localhost',
+      host: '172.16.234.132',
       user     : 'benchmarkdbuser',
       password : 'benchmarkdbpass',
       database : 'hello_world',
@@ -29,7 +29,7 @@ var http = require('http')
     })
   , Sequelize = require("sequelize")
   , sequelize = new Sequelize('hello_world', 'benchmarkdbuser', 'benchmarkdbpass', {
-    host: 'localhost',
+    host: '172.16.234.132',
     logging: false,
     define: { timestamps: false },
     maxConcurrentQueries: 100,