Skip to content

Commit

Permalink
Properly cleanup qcache processes
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Rowe committed Aug 22, 2012
1 parent 1139c52 commit 1195145
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
14 changes: 10 additions & 4 deletions README.md
Expand Up @@ -249,7 +249,7 @@ added to the parameter list of your application.
{amqp_username, <<"guest">>},
{amqp_password, <<"guest">>},
{amqp_virtual_host, <<"/">>},
{amqp_host, [{"localhost",5672}] },
{amqp_servers, [{"localhost",5672}] },
{amqp_encoding, <<"application/erlang">>},

{amqp_exchanges, [
Expand Down Expand Up @@ -278,16 +278,22 @@ routing key. Options are specified as a proplist. Current options include
```erlang
{encoding, binary()},
{type, binary()},
{durable, boolean()},
{exclusive, boolean()},

{durable, boolean()},
{exclusive, boolean()},
{queue, binary()}
```

The encoding property is only available for pub channels.

## Performance
The qcache model is slow due to the gen_server call. This will be moved to an
ETS table to manage all connections.

### Processes
A gen_qserver and gen_qfsm both utilize a qcache, so each server without any
connections defined creates 2 processes. Once this is moved to ETS, it will
be 1 process per server.

## Future

* Message-specific overrides for encoding (currently this is done at the
Expand Down
5 changes: 3 additions & 2 deletions src/gen_qserver.erl
Expand Up @@ -220,15 +220,16 @@ handle_info(Info, #gen_qstate{module=Module,
end.


terminate(Reason, State) ->
Handles = qcache:connections(State#gen_qstate.cache_pid),
terminate(Reason, #gen_qstate{cache_pid=CachePid}=State) ->
Handles = qcache:connections(CachePid),
Module = State#gen_qstate.module,
ModuleState = State#gen_qstate.module_state,
Module:terminate(Reason, ModuleState),
Fn = fun(PList) ->
bunny_farm:close(?PV(handle,PList), ?PV(tag,PList))
end,
lists:map(Fn, Handles),
gen_server:cast(CachePid,stop),
ok.

code_change(_OldVersion, State, _Extra) ->
Expand Down
2 changes: 2 additions & 0 deletions src/qcache.erl
Expand Up @@ -115,6 +115,8 @@ handle_call({get_conn,Tuple}, _From, State) when is_tuple(Tuple) ->
{reply, Conn, State}.


handle_cast(stop, State) -> {stop,normal,State};

%% This replaces existing handles with the same exchange name.
handle_cast({put_conn,PropList}, State) when is_list(PropList) ->
QConn = to_qconn(PropList),
Expand Down
2 changes: 1 addition & 1 deletion test/my_qserver.erl
Expand Up @@ -57,7 +57,7 @@ handle_cast({set_value,K,V}, State) ->
TupleList = lists:keystore(K,1,State#state.tuples, {K,V}),
{noreply, State#state{tuples=TupleList}};

handle_cast(stop, State) -> {noreply,State};
handle_cast(stop, State) -> {stop,normal,State};

handle_cast(A, State) ->
error_logger:info_msg("[my_qserver] Got unexpected cast: ~p~n", [A]),
Expand Down

0 comments on commit 1195145

Please sign in to comment.