Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: ninenines/cowboy
base: master
...
head fork: ferd/cowboy
compare: bloomdigital
Checking mergeability… Don't worry, you can still create the pull request.
  • 8 commits
  • 5 files changed
  • 0 commit comments
  • 2 contributors
Commits on Sep 05, 2011
@lpgauth lpgauth Updated Quoted to 1.1.0 fd01446
Commits on Sep 06, 2011
@lpgauth lpgauth Add MaxKeepAlive of 500 43e0ba0
Commits on Apr 17, 2012
@ferd ferd Changing the acceptor stuff to be less strict
For our needs, this actually helps us serve a higher load with
no visible downside.
e46e802
@ferd ferd Removing warnings af777f0
Commits on Apr 23, 2012
@ferd ferd Fix to enable kernel filtering by LP 937a64e
Commits on Aug 06, 2012
@ferd ferd changing quoted branch for custom fixes and rebar 3.0.0 ec2e79d
Commits on Nov 20, 2012
@lpgauth lpgauth Added statsderl metric to follow connections d4d261a
Commits on Nov 22, 2012
@ferd ferd Merge pull request #1 from lpgauth/bloomdigital
Added statsderl metric to follow connections
53c7897
View
4 rebar.config
@@ -1,7 +1,7 @@
{cover_enabled, true}.
{deps, [
- {quoted, "1.0.3",
- {git, "git://github.com/klaar/quoted.erl.git", {tag, "1.0.3"}}},
+ {quoted, "1.1.0",
+ {git, "git://github.com/ferd/quoted.erl.git", "bloomdigital"}},
{proper, "1.0",
{git, "git://github.com/manopapad/proper.git", {tag, "v1.0"}}}
]}.
View
2  src/cowboy.app.src
@@ -14,7 +14,7 @@
{application, cowboy, [
{description, "Small, fast, modular HTTP server."},
- {vsn, "0.3.0"},
+ {vsn, "0.3.1"},
{modules, []},
{registered, [cowboy_clock, cowboy_sup]},
{applications, [
View
12 src/cowboy_acceptor.erl
@@ -35,13 +35,11 @@ start_link(LSocket, Transport, Protocol, Opts,
acceptor(LSocket, Transport, Protocol, Opts, MaxConns, ListenerPid, ReqsSup) ->
case Transport:accept(LSocket, 2000) of
{ok, CSocket} ->
+ statsderl:increment([<<"connections.accept">>], 1, 0.01),
{ok, Pid} = supervisor:start_child(ReqsSup,
[ListenerPid, CSocket, Transport, Protocol, Opts]),
Transport:controlling_process(CSocket, Pid),
- {ok, NbConns} = cowboy_listener:add_connection(ListenerPid,
- default, Pid),
- Pid ! shoot,
- limit_reqs(ListenerPid, NbConns, MaxConns);
+ Pid ! shoot;
{error, timeout} ->
ignore;
{error, _Reason} ->
@@ -51,9 +49,3 @@ acceptor(LSocket, Transport, Protocol, Opts, MaxConns, ListenerPid, ReqsSup) ->
end,
?MODULE:acceptor(LSocket, Transport, Protocol, Opts,
MaxConns, ListenerPid, ReqsSup).
-
--spec limit_reqs(pid(), non_neg_integer(), non_neg_integer()) -> ok.
-limit_reqs(_ListenerPid, NbConns, MaxConns) when NbConns =< MaxConns ->
- ok;
-limit_reqs(ListenerPid, _NbConns, MaxConns) ->
- cowboy_listener:wait(ListenerPid, default, MaxConns).
View
14 src/cowboy_http_protocol.erl
@@ -47,7 +47,8 @@
max_empty_lines :: integer(),
timeout :: timeout(),
connection = keepalive :: keepalive | close,
- buffer = <<>> :: binary()
+ buffer = <<>> :: binary(),
+ keep_alive_counter = 1 :: integer()
}).
%% API.
@@ -240,13 +241,14 @@ handler_terminate(HandlerState, Req, #state{handler={Handler, Opts}}) ->
end.
-spec next_request(any(), #http_req{}, #state{}) -> ok.
-next_request(HandlerState, Req=#http_req{buffer=Buffer}, State) ->
+next_request(HandlerState, Req=#http_req{buffer=Buffer}, State=#state{keep_alive_counter=KeepAliveCount}) ->
HandlerRes = handler_terminate(HandlerState, Req, State),
BodyRes = ensure_body_processed(Req),
RespRes = ensure_response(Req, State),
- case {HandlerRes, BodyRes, RespRes, State#state.connection} of
- {ok, ok, ok, keepalive} ->
- ?MODULE:parse_request(State#state{buffer=Buffer});
+ KeepAlive = KeepAliveCount =< 500,
+ case {HandlerRes, BodyRes, RespRes, State#state.connection, KeepAlive} of
+ {ok, ok, ok, keepalive, true} ->
+ ?MODULE:parse_request(State#state{buffer=Buffer, keep_alive_counter=KeepAliveCount+1});
_Closed ->
terminate(State)
end.
@@ -285,11 +287,13 @@ error_response(Code, #state{socket=Socket,
-spec error_terminate(http_status(), #state{}) -> ok.
error_terminate(Code, State) ->
+ statsderl:increment([<<"connections.error.">>, list_to_binary(integer_to_list(Code))], 1, 0.01),
error_response(Code, State#state{connection=close}),
terminate(State).
-spec terminate(#state{}) -> ok.
terminate(#state{socket=Socket, transport=Transport}) ->
+ statsderl:increment([<<"connections.close">>], 1, 0.01),
Transport:close(Socket),
ok.
View
29 src/cowboy_tcp_transport.erl
@@ -48,16 +48,8 @@ messages() -> {tcp, tcp_closed, tcp_error}.
-spec listen([{port, inet:ip_port()} | {ip, inet:ip_address()}])
-> {ok, inet:socket()} | {error, atom()}.
listen(Opts) ->
- {port, Port} = lists:keyfind(port, 1, Opts),
- Backlog = proplists:get_value(backlog, Opts, 1024),
- ListenOpts0 = [binary, {active, false},
- {backlog, Backlog}, {packet, raw}, {reuseaddr, true}],
- ListenOpts =
- case lists:keyfind(ip, 1, Opts) of
- false -> ListenOpts0;
- Ip -> [Ip|ListenOpts0]
- end,
- gen_tcp:listen(Port, ListenOpts).
+ {Port, ListenOpts} = parse_listen_options(Opts),
+ gen_tcp:listen(Port, ListenOpts).
%% @doc Accept an incoming connection on a listen socket.
%% @see gen_tcp:accept/2
@@ -104,3 +96,20 @@ peername(Socket) ->
-spec close(inet:socket()) -> ok.
close(Socket) ->
gen_tcp:close(Socket).
+
+%% Helpers
+parse_listen_options(Opts) ->
+ parse_listen_options(Opts, 0, [binary, {active, false}, {packet, raw}, {reuseaddr, true}]).
+
+parse_listen_options([{port, Port}|T], _, Opts) ->
+ parse_listen_options(T, Port, Opts);
+parse_listen_options([{backlog, Backlog}|T], Port, Opts) ->
+ parse_listen_options(T, Port, [{backlog, Backlog}|Opts]);
+parse_listen_options([{ip, IP}|T], Port, Opts) ->
+ parse_listen_options(T, Port, [{ip, IP}|Opts]);
+parse_listen_options([{raw, Protocol, OptionNum, ValueSpec}|T], Port, Opts) ->
+ parse_listen_options(T, Port, [{raw, Protocol, OptionNum, ValueSpec}|Opts]);
+parse_listen_options([_|T], Port, Opts) -> %% ignore other options
+ parse_listen_options(T, Port, Opts);
+parse_listen_options([], Port, Opts) ->
+ {Port, Opts}.

No commit comments for this range

Something went wrong with that request. Please try again.