summaryrefslogtreecommitdiff
path: root/apps/couch/src/couch_proc_manager.erl
diff options
context:
space:
mode:
Diffstat (limited to 'apps/couch/src/couch_proc_manager.erl')
-rw-r--r--apps/couch/src/couch_proc_manager.erl31
1 files changed, 18 insertions, 13 deletions
diff --git a/apps/couch/src/couch_proc_manager.erl b/apps/couch/src/couch_proc_manager.erl
index 0f35422b..568608bc 100644
--- a/apps/couch/src/couch_proc_manager.erl
+++ b/apps/couch/src/couch_proc_manager.erl
@@ -67,13 +67,29 @@ handle_call({ret_proc, #proc{client=Ref, pid=Pid} = Proc}, _From, State) ->
% #proc{} from our own table, so the alternative is to do a lookup in the
% table before the insert. Don't know which approach is cheaper.
case is_process_alive(Pid) of true ->
- maybe_reuse_proc(State#state.tab, Proc);
+ ets:insert(State#state.tab, Proc);
false -> ok end,
{reply, true, State};
handle_call(_Call, _From, State) ->
{reply, ignored, State}.
+handle_cast({os_proc_idle, Pid}, #state{tab=Tab}=State) ->
+ Limit = couch_config:get("query_server_config", "os_process_soft_limit", "100"),
+ case ets:info(Tab, size) > list_to_integer(Limit) of
+ true ->
+ ets:delete(Tab, Pid),
+ case is_process_alive(Pid) of
+ true ->
+ unlink(Pid),
+ gen_server:cast(Pid, stop);
+ _ ->
+ ok
+ end;
+ _ ->
+ ok
+ end,
+ {noreply, State};
handle_cast(_Msg, State) ->
{noreply, State}.
@@ -95,7 +111,7 @@ handle_info({'DOWN', Ref, _, _, _Reason}, State) ->
ok;
[#proc{pid = Pid} = Proc] ->
case is_process_alive(Pid) of true ->
- maybe_reuse_proc(State#state.tab, Proc);
+ ets:insert(State#state.tab, Proc);
false -> ok end
end,
{noreply, State};
@@ -110,17 +126,6 @@ terminate(_Reason, #state{tab=Tab}) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
-maybe_reuse_proc(Tab, #proc{pid = Pid} = Proc) ->
- Limit = couch_config:get("query_server_config", "os_process_soft_limit", "100"),
- case ets:info(Tab, size) > list_to_integer(Limit) of
- true ->
- ets:delete(Tab, Pid),
- unlink(Pid),
- exit(Pid, kill);
- false ->
- garbage_collect(Pid),
- ets:insert(Tab, Proc#proc{client=nil})
- end.
get_procs(Tab, Lang) when is_binary(Lang) ->
get_procs(Tab, binary_to_list(Lang));