From 38242f4fd076acaeb012cf755afc9fd25b924c0d Mon Sep 17 00:00:00 2001 From: benjaminplee Date: Wed, 19 Nov 2014 18:21:49 +0000 Subject: [PATCH] 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. --- src/ibrowse_http_client.erl | 15 +++------------ src/ibrowse_lb.erl | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/ibrowse_http_client.erl b/src/ibrowse_http_client.erl index 6628427..7818a15 100644 --- a/src/ibrowse_http_client.erl +++ b/src/ibrowse_http_client.erl @@ -1939,31 +1939,22 @@ to_lower([], Acc) -> shutting_down(#state{lb_ets_tid = undefined}) -> ok; 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) -> State; inc_pipeline_counter(#state{lb_ets_tid = undefined} = State) -> 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. -update_counter(Tid, Key, Args) -> - ets:update_counter(Tid, Key, Args). - dec_pipeline_counter(#state{is_closing = true} = State) -> State; dec_pipeline_counter(#state{lb_ets_tid = undefined} = State) -> 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. flatten([H | _] = L) when is_integer(H) -> diff --git a/src/ibrowse_lb.erl b/src/ibrowse_lb.erl index 1d7df44..34f64f0 100644 --- a/src/ibrowse_lb.erl +++ b/src/ibrowse_lb.erl @@ -14,7 +14,10 @@ -export([ start_link/1, spawn_connection/6, - stop/1 + stop/1, + report_connection_down/1, + report_request_underway/1, + report_request_complete/1 ]). %% gen_server callbacks @@ -68,6 +71,16 @@ stop(Lb_pid) -> ok 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 %%====================================================================