couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [01/45] mochiweb commit: updated refs/heads/master to cb521b3
Date Tue, 25 Aug 2015 17:38:19 GMT
Repository: couchdb-mochiweb
Updated Branches:
  refs/heads/master b9d515384 -> cb521b34c


Add a simple implementation of max connections

max limits the sum of active connections and listeners.
The implementation assumes that max is greater than acceptor_pool_size,
and always maintains the acceptor_pool at acceptor_pool_size as long
as the max is not exceeded.

If max is less than acceptor_pool_size, acceptor_pool_size is the
effective max.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/commit/b4132263
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/tree/b4132263
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/diff/b4132263

Branch: refs/heads/master
Commit: b413226386ed227ee5ddf3fcb8a1eb6c09922ba3
Parents: 8eb1f22
Author: Prashanth Mundkur <prashanth.mundkur@gmail.com>
Authored: Fri Apr 15 00:28:02 2011 -0700
Committer: Shayan Pooya <shayan@chango.com>
Committed: Sun Mar 23 17:43:09 2014 -0400

----------------------------------------------------------------------
 src/mochiweb_socket_server.erl | 41 +++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/b4132263/src/mochiweb_socket_server.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb_socket_server.erl b/src/mochiweb_socket_server.erl
index a3d4da3..7d62927 100644
--- a/src/mochiweb_socket_server.erl
+++ b/src/mochiweb_socket_server.erl
@@ -18,7 +18,6 @@
         {port,
          loop,
          name=undefined,
-         %% NOTE: This is currently ignored.
          max=2048,
          ip=any,
          listen=null,
@@ -74,7 +73,16 @@ parse_options(State=#mochiweb_socket_server{}) ->
 parse_options(Options) ->
     parse_options(Options, #mochiweb_socket_server{}).
 
-parse_options([], State) ->
+parse_options([], State=#mochiweb_socket_server{acceptor_pool_size=PoolSize,
+                                                max=Max}) ->
+    case Max < PoolSize of
+        true ->
+            error_logger:info_report([{warning, "max is set lower than acceptor_pool_size"},
+                                      {max, Max},
+                                      {acceptor_pool_size, PoolSize}]);
+        false ->
+            ok
+    end,
     State;
 parse_options([{name, L} | Rest], State) when is_list(L) ->
     Name = {local, list_to_atom(L)},
@@ -113,8 +121,6 @@ parse_options([{acceptor_pool_size, Max} | Rest], State) ->
     parse_options(Rest,
                   State#mochiweb_socket_server{acceptor_pool_size=MaxInt});
 parse_options([{max, Max} | Rest], State) ->
-    error_logger:info_report([{warning, "TODO: max is currently unsupported"},
-                              {max, Max}]),
     MaxInt = ensure_int(Max),
     parse_options(Rest, State#mochiweb_socket_server{max=MaxInt});
 parse_options([{ssl, Ssl} | Rest], State) when is_boolean(Ssl) ->
@@ -204,6 +210,8 @@ listen(Port, Opts, State=#mochiweb_socket_server{ssl=Ssl, ssl_opts=SslOpts})
->
 
 do_get(port, #mochiweb_socket_server{port=Port}) ->
     Port;
+do_get(waiting_acceptors, #mochiweb_socket_server{acceptor_pool=Pool}) ->
+    sets:size(Pool);
 do_get(active_sockets, #mochiweb_socket_server{active_sockets=ActiveSockets}) ->
     ActiveSockets.
 
@@ -271,16 +279,33 @@ code_change(_OldVsn, State, _Extra) ->
 
 recycle_acceptor(Pid, State=#mochiweb_socket_server{
                         acceptor_pool=Pool,
+                        acceptor_pool_size=PoolSize,
                         listen=Listen,
                         loop=Loop,
+                        max=Max,
                         active_sockets=ActiveSockets}) ->
     case sets:is_element(Pid, Pool) of
         true ->
-            Acceptor = mochiweb_acceptor:start_link(self(), Listen, Loop),
-            Pool1 = sets:add_element(Acceptor, sets:del_element(Pid, Pool)),
-            State#mochiweb_socket_server{acceptor_pool=Pool1};
+            Pool1 = sets:del_element(Pid, Pool),
+            case ActiveSockets + sets:size(Pool1) < Max of
+                true ->
+                    Acceptor = mochiweb_acceptor:start_link(self(), Listen, Loop),
+                    Pool2 = sets:add_element(Acceptor, Pool1),
+                    State#mochiweb_socket_server{acceptor_pool=Pool2};
+                false ->
+                    State#mochiweb_socket_server{acceptor_pool=Pool1}
+            end;
         false ->
-            State#mochiweb_socket_server{active_sockets=ActiveSockets - 1}
+            Pool1 =
+                case sets:size(Pool) < PoolSize of
+                    true ->
+                        Acceptor = mochiweb_acceptor:start_link(self(), Listen, Loop),
+                        sets:add_element(Acceptor, Pool);
+                    false ->
+                        Pool
+                end,
+            State#mochiweb_socket_server{active_sockets=ActiveSockets - 1,
+                                         acceptor_pool=Pool1}
     end.
 
 handle_info(Msg, State) when ?is_old_state(State) ->


Mime
View raw message