Browse Source

Encapsulated conn ets table use in ibrowse_lb

Moved all interactions with ets table tracking
connections to API functions on ibrowse_lb,
to reduce knowledge of ets table and its structure.

Also fixed "bug" where ceiling for pipelining
threshold was different than the set value for increment;
made them the same.
pull/123/head
benjaminplee 10 years ago
parent
commit
38242f4fd0
2 changed files with 17 additions and 13 deletions
  1. +3
    -12
      src/ibrowse_http_client.erl
  2. +14
    -1
      src/ibrowse_lb.erl

+ 3
- 12
src/ibrowse_http_client.erl View File

@ -1939,31 +1939,22 @@ to_lower([], Acc) ->
shutting_down(#state{lb_ets_tid = undefined}) -> shutting_down(#state{lb_ets_tid = undefined}) ->
ok; ok;
shutting_down(#state{lb_ets_tid = Tid}) -> shutting_down(#state{lb_ets_tid = Tid}) ->
catch ets:delete(Tid, self()).
ibrowse_lb:report_connection_down(Tid).
inc_pipeline_counter(#state{is_closing = true} = State) -> inc_pipeline_counter(#state{is_closing = true} = State) ->
State; State;
inc_pipeline_counter(#state{lb_ets_tid = undefined} = State) -> inc_pipeline_counter(#state{lb_ets_tid = undefined} = State) ->
State; State;
inc_pipeline_counter(#state{lb_ets_tid = Tid} = State) -> inc_pipeline_counter(#state{lb_ets_tid = Tid} = State) ->
update_counter(Tid, self(), {2,1,99999,9999}),
ibrowse_lb:report_request_underway(Tid),
State. State.
update_counter(Tid, Key, Args) ->
ets:update_counter(Tid, Key, Args).
dec_pipeline_counter(#state{is_closing = true} = State) -> dec_pipeline_counter(#state{is_closing = true} = State) ->
State; State;
dec_pipeline_counter(#state{lb_ets_tid = undefined} = State) -> dec_pipeline_counter(#state{lb_ets_tid = undefined} = State) ->
State; State;
dec_pipeline_counter(#state{lb_ets_tid = Tid} = State) -> dec_pipeline_counter(#state{lb_ets_tid = Tid} = State) ->
_ = try
update_counter(Tid, self(), {2,-1,0,0}),
update_counter(Tid, self(), {3,-1,0,0})
catch
_:_ ->
ok
end,
ibrowse_lb:report_request_complete(Tid),
State. State.
flatten([H | _] = L) when is_integer(H) -> flatten([H | _] = L) when is_integer(H) ->

+ 14
- 1
src/ibrowse_lb.erl View File

@ -14,7 +14,10 @@
-export([ -export([
start_link/1, start_link/1,
spawn_connection/6, spawn_connection/6,
stop/1
stop/1,
report_connection_down/1,
report_request_underway/1,
report_request_complete/1
]). ]).
%% gen_server callbacks %% gen_server callbacks
@ -68,6 +71,16 @@ stop(Lb_pid) ->
ok ok
end. end.
report_connection_down(Tid) ->
catch ets:delete(Tid, self()).
report_request_underway(Tid) ->
catch ets:update_counter(Tid, self(), {2, 1, 9999, 9999}).
report_request_complete(Tid) ->
catch ets:update_counter(Tid, self(), {2, -1, 0, 0}),
catch ets:update_counter(Tid, self(), {3, -1, 0, 0}).
%%==================================================================== %%====================================================================
%% Server functions %% Server functions
%%==================================================================== %%====================================================================

Loading…
Cancel
Save