Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit f78d74cae1e74d282960f949e715701f401f53ed Devin Torres committed Feb 6, 2012
Showing with 150 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +17 −0 Makefile
  3. +13 −0 README.md
  4. BIN rebar
  5. +7 −0 rebar.config
  6. +15 −0 src/benchmark.app.src
  7. +23 −0 src/benchmark.erl
  8. +16 −0 src/benchmark_handler.erl
  9. +20 −0 src/benchmark_sup.erl
  10. +33 −0 src/benchmark_worker.erl
  11. +4 −0 start.sh
@@ -0,0 +1,2 @@
+ebin/*
+deps/*
@@ -0,0 +1,17 @@
+REBAR = ./rebar
+
+.PHONY: all compile test clean get-deps
+
+all: compile
+
+compile:
+ @$(REBAR) compile
+
+test:
+ @$(REBAR) eunit skip_deps=true
+
+clean:
+ @$(REBAR) clean
+
+get-deps:
+ @$(REBAR) get-deps
@@ -0,0 +1,13 @@
+A super flawed Poolboy benchmark using Cowboy and a simple worker, probably
+benchmarking Cowboy harder than Poolboy.
+
+The pool size is 500 workers with a max overflow of another 500.
+
+ $ make get-deps
+ $ make
+ $ ./start.sh
+ $ ab -k -n1000000 -c20 http://127.0.0.1:9001/
+ $ ab -k -n1000000 -c50 http://127.0.0.1:9001/
+ $ ab -k -n1000000 -c100 http://127.0.0.1:9001/
+ $ ab -k -n1000000 -c200 http://127.0.0.1:9001/
+ $ ab -k -n1000000 -c500 http://127.0.0.1:9001/
BIN rebar
Binary file not shown.
@@ -0,0 +1,7 @@
+{erl_opts, [debug_info]}.
+{deps, [
+ {cowboy, "0.5",
+ {git, "https://github.com/extend/cowboy.git", master}},
+ {poolboy, "0.6",
+ {git, "https://github.com/devinus/poolboy.git", master}}
+]}.
@@ -0,0 +1,15 @@
+{application, benchmark, [
+ {description, "A super flawed Poolboy benchmark"},
+ {vsn, "0.1.0"},
+ {registered, []},
+ {applications, [kernel, stdlib]},
+ {mod, {benchmark, []}},
+ {env, [
+ {pools, [
+ {pool1, [
+ {size, 500},
+ {max_overflow, 500}
+ ]}
+ ]}
+ ]}
+]}.
@@ -0,0 +1,23 @@
+-module(benchmark).
+
+-behaviour(application).
+-export([start/0, start/2, stop/1]).
+
+start() ->
+ application:start(benchmark).
+
+start(_Type, _Args) ->
+ application:start(cowboy),
+ Dispatch = [
+ {'_', [
+ {'_', benchmark_handler, []}
+ ]}
+ ],
+ cowboy:start_listener(benchmark, 1000,
+ cowboy_tcp_transport, [{port, 9001}],
+ cowboy_http_protocol, [{dispatch, Dispatch}]
+ ),
+ benchmark_sup:start_link().
+
+stop(_State) ->
+ ok.
@@ -0,0 +1,16 @@
+-module(benchmark_handler).
+-behaviour(cowboy_http_handler).
+-export([init/3, handle/2, terminate/2]).
+
+init({_Any, http}, Req, []) ->
+ {ok, Req, undefined}.
+
+handle(Req, State) ->
+ Worker = poolboy:checkout(pool1),
+ Reply = gen_server:call(Worker, get),
+ poolboy:checkin(pool1, Worker),
+ {ok, Req2} = cowboy_http_req:reply(200, [], Reply, Req),
+ {ok, Req2, State}.
+
+terminate(_Req, _State) ->
+ ok.
@@ -0,0 +1,20 @@
+-module(benchmark_sup).
+
+-behaviour(supervisor).
+
+-export([start_link/0]).
+-export([init/1]).
+
+start_link() ->
+ supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+init([]) ->
+ {ok, Pools} = application:get_env(benchmark, pools),
+ PoolSpecs = lists:map(fun({PoolName, PoolConfig}) ->
+ Args = [{name, {local, PoolName}},
+ {worker_module, benchmark_worker}]
+ ++ PoolConfig,
+ {PoolName, {poolboy, start_link, [Args]},
+ permanent, 5000, worker, [poolboy]}
+ end, Pools),
+ {ok, {{one_for_one, 10, 10}, PoolSpecs}}.
@@ -0,0 +1,33 @@
+-module(benchmark_worker).
+-behaviour(gen_server).
+
+-export([start_link/1]).
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
+ terminate/2, code_change/3]).
+
+start_link(_Args) ->
+ gen_server:start_link(?MODULE, [], []).
+
+init(Args) ->
+ {ok, Args}.
+
+handle_call(get, _From, State) ->
+ {reply, <<"ok">>, State};
+handle_call(_Request, _From, State) ->
+ {reply, ok, State}.
+
+handle_cast(_Msg, State) ->
+ {noreply, State}.
+
+handle_info(stop, State) ->
+ {stop, shutdown, State};
+handle_info({'EXIT', _, _}, State) ->
+ {stop, shutdown, State};
+handle_info(_Info, State) ->
+ {noreply, State}.
+
+terminate(_Reason, _State) ->
+ ok.
+
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
@@ -0,0 +1,4 @@
+#!/bin/sh
+APP=benchmark
+cd `dirname $0`
+exec erl -smp auto +K true +A 16 -pa $PWD/ebin $PWD/deps/*/ebin -boot start_sasl -s $APP $@

0 comments on commit f78d74c

Please sign in to comment.