Browse Source

Removed speculative sizing and enforced common max

Difference between speculative and "real" size was no
longer material to the algorithm.  Used macro to enforce
consistent usage of ceiling for pipeline.
pull/123/head
benjaminplee 10 years ago
parent
commit
8b94a527f9
1 changed files with 9 additions and 11 deletions
  1. +9
    -11
      src/ibrowse_lb.erl

+ 9
- 11
src/ibrowse_lb.erl View File

@ -38,6 +38,8 @@
max_pipeline_size, max_pipeline_size,
proc_state}). proc_state}).
-define(PIPELINE_MAX, 99999).
-include("ibrowse.hrl"). -include("ibrowse.hrl").
%%==================================================================== %%====================================================================
@ -75,11 +77,10 @@ report_connection_down(Tid) ->
catch ets:delete(Tid, self()). catch ets:delete(Tid, self()).
report_request_underway(Tid) -> report_request_underway(Tid) ->
catch ets:update_counter(Tid, self(), {2, 1, 9999, 9999}).
catch ets:update_counter(Tid, self(), {2, 1, ?PIPELINE_MAX, ?PIPELINE_MAX}).
report_request_complete(Tid) -> report_request_complete(Tid) ->
catch ets:update_counter(Tid, self(), {2, -1, 0, 0}),
catch ets:update_counter(Tid, self(), {3, -1, 0, 0}).
catch ets:update_counter(Tid, self(), {2, -1, 0, 0}).
%%==================================================================== %%====================================================================
%% Server functions %% Server functions
@ -121,7 +122,7 @@ handle_call(stop, _From, #state{ets_tid = undefined} = State) ->
gen_server:reply(_From, ok), gen_server:reply(_From, ok),
{stop, normal, State}; {stop, normal, State};
handle_call(stop, _From, #state{ets_tid = Tid} = State) -> handle_call(stop, _From, #state{ets_tid = Tid} = State) ->
ets:foldl(fun({Pid, _, _}, Acc) ->
ets:foldl(fun({Pid, _}, Acc) ->
ibrowse_http_client:stop(Pid), ibrowse_http_client:stop(Pid),
Acc Acc
end, [], Tid), end, [], Tid),
@ -171,10 +172,8 @@ handle_info({trace, Bool}, #state{ets_tid = undefined} = State) ->
put(my_trace_flag, Bool), put(my_trace_flag, Bool),
{noreply, State}; {noreply, State};
handle_info({trace, Bool}, #state{ets_tid = Tid} = State) -> handle_info({trace, Bool}, #state{ets_tid = Tid} = State) ->
ets:foldl(fun({{_, Pid}, _}, Acc) when is_pid(Pid) ->
ets:foldl(fun({Pid, _}, Acc) when is_pid(Pid) ->
catch Pid ! {trace, Bool}, catch Pid ! {trace, Bool},
Acc;
(_, Acc) ->
Acc Acc
end, undefined, Tid), end, undefined, Tid),
put(my_trace_flag, Bool), put(my_trace_flag, Bool),
@ -224,8 +223,7 @@ find_best_connection('$end_of_table', _, _) ->
{error, retry_later}; {error, retry_later};
find_best_connection(Pid, Tid, Max_pipe) -> find_best_connection(Pid, Tid, Max_pipe) ->
case ets:lookup(Tid, Pid) of case ets:lookup(Tid, Pid) of
[{Pid, Cur_sz, Speculative_sz}] when Cur_sz < Max_pipe,
Speculative_sz < Max_pipe ->
[{Pid, Cur_sz}] when Cur_sz < Max_pipe ->
case record_request_for_connection(Tid, Pid) of case record_request_for_connection(Tid, Pid) of
{'EXIT', _} -> {'EXIT', _} ->
%% The selected process has shutdown %% The selected process has shutdown
@ -248,7 +246,7 @@ num_current_connections(Tid) ->
catch ets:info(Tid, size). catch ets:info(Tid, size).
record_new_connection(Tid, Pid) -> record_new_connection(Tid, Pid) ->
catch ets:insert(Tid, {Pid, 0, 0}).
catch ets:insert(Tid, {Pid, 0}).
record_request_for_connection(Tid, Pid) -> record_request_for_connection(Tid, Pid) ->
catch ets:update_counter(Tid, Pid, {3, 1, 9999999, 9999999}).
catch ets:update_counter(Tid, Pid, {2, 1, ?PIPELINE_MAX, ?PIPELINE_MAX}).

Loading…
Cancel
Save