Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Devin Torres committed Feb 6, 2012
0 parents commit f78d74c
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
ebin/*
deps/*
17 changes: 17 additions & 0 deletions Makefile
@@ -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
13 changes: 13 additions & 0 deletions README.md
@@ -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/
Binary file added rebar
Binary file not shown.
7 changes: 7 additions & 0 deletions rebar.config
@@ -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}}
]}.
15 changes: 15 additions & 0 deletions src/benchmark.app.src
@@ -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}
]}
]}
]}
]}.
23 changes: 23 additions & 0 deletions src/benchmark.erl
@@ -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.
16 changes: 16 additions & 0 deletions src/benchmark_handler.erl
@@ -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.
20 changes: 20 additions & 0 deletions src/benchmark_sup.erl
@@ -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}}.
33 changes: 33 additions & 0 deletions src/benchmark_worker.erl
@@ -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}.
4 changes: 4 additions & 0 deletions start.sh
@@ -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.