Permalink
Browse files

hook up low prio queue based on info berp

  • Loading branch information...
1 parent 53ca1e1 commit 2bd72fc93f5e305f5501b1f5a6e8d3fe2111ea7a @mojombo committed Dec 10, 2009
Showing with 29 additions and 10 deletions.
  1. +2 −0 contrib/ebench.erl
  2. +23 −7 elib/ernie_server.erl
  3. +4 −3 elib/native.erl
View
@@ -45,6 +45,8 @@ hit(Waiter, Mod, Fun) ->
% io:format("outgoing!~n", []),
Host = "localhost",
{ok, Sock} = gen_tcp:connect(Host, 8000, [binary, {packet, 4}]),
+ % Info = term_to_binary({info, priority, [low]}),
+ % ok = gen_tcp:send(Sock, Info),
Request = term_to_binary({call, Mod, Fun, args(Fun)}),
ok = gen_tcp:send(Sock, Request),
receive
View
@@ -15,8 +15,9 @@
map = undefined}). % module map. tuples of {Mod, Id}
-record(request, {sock = undefined, % connection socket
- info = undefined, % info binary (if any)
- action = undefined}). % action binary
+ infos = [], % list of info binaries
+ action = undefined, % action binary
+ priority = high}). % priority [ high | low ]
%%====================================================================
%% API
@@ -151,21 +152,36 @@ receive_term(Request, State) ->
case Term of
{call, '__admin__', Fun, Args} ->
ernie_admin:process(Sock, Fun, Args, State);
- {info, _Command, _Args} ->
- Request2 = Request#request{info = BinaryTerm},
- receive_term(Request2, State);
+ {info, Command, Args} ->
+ Infos = Request#request.infos,
+ Infos2 = [BinaryTerm | Infos],
+ Request2 = Request#request{infos = Infos2},
+ Request3 = process_info(Request2, Command, Args),
+ receive_term(Request3, State);
_Any ->
Request2 = Request#request{action = BinaryTerm},
close_if_cast(Term, Request2),
- Hq2 = queue:in(Request2, State#state.hq),
+ case Request2#request.priority of
+ high ->
+ Hq2 = queue:in(Request2, State#state.hq),
+ Lq2 = State#state.lq;
+ low ->
+ Hq2 = State#state.hq,
+ Lq2 = queue:in(Request2, State#state.lq)
+ end,
ernie_server:kick(),
- State#state{hq = Hq2}
+ State#state{hq = Hq2, lq = Lq2}
end;
{error, closed} ->
ok = gen_tcp:close(Sock),
State
end.
+process_info(Request, priority, [Priority]) ->
+ Request#request{priority = Priority};
+process_info(Request, _Command, _Args) ->
+ Request.
+
process_request(Request, Priority, Q2, State) ->
ActionTerm = binary_to_term(Request#request.action),
{_Type, Mod, _Fun, _Args} = ActionTerm,
View
@@ -1,9 +1,10 @@
-module(native).
-export([process/2]).
--record(request, {sock = undefined,
- info = undefined,
- action = undefined}).
+-record(request, {sock = undefined, % connection socket
+ infos = [], % list of info binaries
+ action = undefined, % action binary
+ priority = high}). % priority [ high | low ]
process(ActionTerm, Request) ->
{_Type, Mod, Fun, Args} = ActionTerm,

0 comments on commit 2bd72fc

Please sign in to comment.