Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Devin Torres
committed
Feb 6, 2012
0 parents
commit f78d74c
Showing
11 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ebin/* | ||
deps/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}} | ||
]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} | ||
]} | ||
]} | ||
]} | ||
]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 $@ |