Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

on changes, remove the connection from the pool.

Changes connections are generally long-lived conections, keeping them in
the pool limit the number of concurrent connections. This change fix it
by removing them from the ranch connection ssupervisor once the changes
connections are accepted.
  • Loading branch information...
commit 8d6f71e79c8382e83e9587b0d81991ec955d34bb 1 parent ca919e4
@benoitc benoitc authored
View
4 apps/couch_changes/src/couch_httpd_changes.erl
@@ -40,6 +40,10 @@ handle_changes_req1(Req, #db{name=DbName}=Db) ->
end.
do_changes_req(Req, Db) ->
+ %% remove connections from the pool, changes connections are
+ %% generally long-lived connections.
+ couch_httpd_protocol:remove_connection(),
+
MakeCallback = fun(Resp) ->
fun({change, {ChangeProp}=Change, _}, "eventsource") ->
Seq = proplists:get_value(<<"seq">>, ChangeProp),
View
11 apps/couch_httpd/src/couch_httpd_protocol.erl
@@ -13,6 +13,7 @@
-export([loop/1]).
-export([after_response/2, reentry/1]).
-export([new_request/3, call_body/2]).
+-export([remove_connection/0]).
-include("couch_httpd.hrl").
@@ -45,6 +46,7 @@ start_link(Ref, Socket, Transport, Opts) ->
-spec init(any(), inet:socket(), module(), any()) -> ok | none().
init(Ref, Socket, Transport, Opts) ->
{loop, HttpLoop} = proplists:lookup(loop, Opts),
+ put(ranch_ref, Ref),
ok = ranch:accept_ack(Ref),
loop(#hstate{socket = Socket,
transport = Transport,
@@ -157,6 +159,15 @@ after_response(Body, Req) ->
loop=Body})
end.
+%% @doc Remove the calling process' connection from the pool.
+%%
+%% Useful if you have long-lived connections that aren't taking up
+%% resources and shouldn't be counted in the limited number of running
+%% connections.
+remove_connection() ->
+ Ref = get(ranch_ref),
+ ranch:remove_connection(Ref).
+
mochiweb_socket(#hstate{transport=Transport, socket=Socket}) ->
case Transport of

0 comments on commit 8d6f71e

Please sign in to comment.
Something went wrong with that request. Please try again.