Browse Source

Merge branch 'erlang-fw-mochiweb'

msmith-techempower 9 years ago
parent
commit
7a5d4cb415

+ 1 - 0
.travis.yml

@@ -49,6 +49,7 @@ env:
     - "TESTDIR=Erlang/chicagoboss"
     - "TESTDIR=Erlang/chicagoboss"
     - "TESTDIR=Erlang/cowboy"
     - "TESTDIR=Erlang/cowboy"
     - "TESTDIR=Erlang/elli"
     - "TESTDIR=Erlang/elli"
+    - "TESTDIR=Erlang/mochiweb"
     - "TESTDIR=Erlang/misultin"
     - "TESTDIR=Erlang/misultin"
     - "TESTDIR=Go/beego"
     - "TESTDIR=Go/beego"
     - "TESTDIR=Go/falcore"
     - "TESTDIR=Go/falcore"

+ 7 - 0
frameworks/Erlang/mochiweb/.gitignore

@@ -0,0 +1,7 @@
+.eunit
+deps
+ebin
+*.o
+*.beam
+*.plt
+erl_crash.dump

+ 13 - 0
frameworks/Erlang/mochiweb/Makefile

@@ -0,0 +1,13 @@
+REBAR=./rebar
+
+all:
+	@$(REBAR) -r get-deps compile
+
+clean:
+	@$(REBAR) clean
+
+run:
+	@./start.sh
+
+stop:
+	@killall beam.smp

+ 23 - 0
frameworks/Erlang/mochiweb/benchmark_config.json

@@ -0,0 +1,23 @@
+{
+  "framework": "mochiweb",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Platform",
+      "database": "MySQL",
+      "framework": "Mochiweb",
+      "language": "Erlang",
+      "orm": "Raw",
+      "platform": "Erlang",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "mochiweb",
+      "notes": "",
+      "versus": ""
+  }}]
+}

+ 9 - 0
frameworks/Erlang/mochiweb/priv/app.config

@@ -0,0 +1,9 @@
+%% -*- erlang -*-
+[{mochiweb_bench, [{http_port, 8080}]},
+
+ {erl_bench, [{db_pool, 256},
+              {db_user, "benchmarkdbuser"},
+              {db_password, "benchmarkdbpass"},
+              {db_host, "localhost"},
+              {db_port, 3306},
+              {db_name, "hello_world"}]}].

+ 5 - 0
frameworks/Erlang/mochiweb/rebar.config

@@ -0,0 +1,5 @@
+%% -*- erlang -*-
+{deps, [
+  {erl_bench, "0.0.1", {git, "git://github.com/b0oh/erl_bench.git", {tag, "v0.0.1"}}},
+  {mochiweb, "2.9.0", {git, "git://github.com/mochi/mochiweb.git", {tag, "v2.9.0"}}}
+]}.

+ 11 - 0
frameworks/Erlang/mochiweb/setup.sh

@@ -0,0 +1,11 @@
+#!/bin/bash
+
+sed -i 's|"benchmarkdbpass", ".*", 3306|"benchmarkdbpass", "'"${DBHOST}"'", 3306|g' src/mochiweb_bench_sup.erl
+
+fw_depends erlang
+
+rm -rf deps/* ebin/*
+rebar get-deps
+rebar compile
+
+erl +K true +sbwt very_long +swt very_low -pa ebin deps/*/ebin -boot start_sasl -config priv/app.config -s mochiweb_bench_app

+ 9 - 0
frameworks/Erlang/mochiweb/src/mochiweb_bench.app.src

@@ -0,0 +1,9 @@
+%% -*- erlang -*-
+{application, mochiweb_bench,
+ [{description, ""},
+  {vsn, "0.1"},
+  {modules, []},
+  {registered, []},
+  {mod, {mochiweb_bench_app, []}},
+  {env, []},
+  {applications, [kernel, stdlib, erl_bench]}]}.

+ 14 - 0
frameworks/Erlang/mochiweb/src/mochiweb_bench_app.erl

@@ -0,0 +1,14 @@
+-module(mochiweb_bench_app).
+-behaviour(application).
+-export([start/0]).
+-export([start/2, stop/1]).
+
+start() ->
+    application:ensure_all_started(mochiweb_bench).
+
+start(_Type, _StartArgs) ->
+    {ok, Port} = application:get_env(mochiweb_bench, http_port),
+    mochiweb_bench_sup:start_link([{port, Port}]).
+
+stop(_State) ->
+    ok.

+ 18 - 0
frameworks/Erlang/mochiweb/src/mochiweb_bench_sup.erl

@@ -0,0 +1,18 @@
+-module(mochiweb_bench_sup).
+-behaviour(supervisor).
+-export([start_link/1]).
+-export([init/1]).
+
+start_link(Options) ->
+    supervisor:start_link({local, ?MODULE}, ?MODULE, [Options]).
+
+init([Options]) ->
+    Web = worker(web_handler, Options),
+    Processes = [Web],
+    Strategy = {one_for_one, 10, 10},
+    {ok, {Strategy, Processes}}.
+
+worker(Mod, Options) ->
+    {Mod,
+     {Mod, start, [Options]},
+     permanent, 5000, worker, dynamic}.

+ 59 - 0
frameworks/Erlang/mochiweb/src/web_handler.erl

@@ -0,0 +1,59 @@
+-module(web_handler).
+-export([start/1, stop/0, dispatch/1]).
+
+start(Options) ->
+    mochiweb_http:start([{name, ?MODULE},
+                         {loop, {?MODULE, dispatch}} | Options]).
+
+stop() ->
+    mochiweb_http:stop(?MODULE).
+
+dispatch(Req) ->
+    Method = Req:get(method),
+    Path = string:tokens(Req:get(path), "/"),
+    handle(Method, Path, Req).
+
+%% handle
+
+handle('GET', ["json"], Req) ->
+    json(Req, erl_bench:hello_json());
+
+handle('GET', ["plaintext"], Req) ->
+    plain(Req, erl_bench:hello_plain());
+
+handle('GET', ["db"], Req) ->
+    json(Req, erl_bench:random_json());
+
+handle('GET', ["queries"], Req) ->
+    Queries = queries(Req),
+    json(Req, erl_bench:randoms_json(Queries));
+
+handle('GET', ["updates"], Req) ->
+    Queries = queries(Req),
+    json(Req, erl_bench:update_randoms_json(Queries));
+
+handle('GET', ["fortunes"], Req) ->
+    html(Req, erl_bench:fortunes_html());
+
+handle(_Method, _Path, Req) ->
+    Req:respond({404, [{"Content-Type", "text/plain"}], "Not Found"}).
+
+%% private
+
+json(Req, Json) ->
+    Req:ok({"application/json", Json}).
+
+plain(Req, Text) ->
+    Req:ok({"text/plain", Text}).
+
+html(Req, Html) ->
+    Req:ok({"text/html", Html}).
+
+queries(Req) ->
+    Params = Req:parse_qs(),
+    Queries = (catch list_to_integer(proplists:get_value("queries", Params, "1"))),
+    case {is_number(Queries), Queries > 500} of
+        {true, true} -> 500;
+        {false, _}   -> 1;
+        _ -> Queries
+    end.