Skip to content

Commit

Permalink
Fix off-by-one bug of disconnect frequency
Browse files Browse the repository at this point in the history
Before this commit, for disconnect frequency of Ops (>0), both http
raw and cs drivers disconnected after (Ops + 1) operations instead of
just Ops operations.
  • Loading branch information
shino committed Jan 6, 2015
1 parent d3be3e9 commit 8f3a681
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/basho_bench_driver_cs.erl
Expand Up @@ -374,13 +374,17 @@ maybe_disconnect(Url) ->
Seconds -> should_disconnect_secs(Seconds,Url) andalso disconnect(Url)
end.

should_disconnect_ops(Count, _) when Count =< 0 ->
false;
should_disconnect_ops(Count, _) when Count =:= 1 ->
true;
should_disconnect_ops(Count, {Host, Port}) ->
Key = {ops_since_disconnect, {Host, Port}},
case erlang:get(Key) of
undefined ->
erlang:put(Key, 1),
false;
Count ->
CountUntilLastOne when CountUntilLastOne =:= Count - 1 ->
erlang:put(Key, 0),
true;
Incr ->
Expand Down
6 changes: 5 additions & 1 deletion src/basho_bench_driver_http_raw.erl
Expand Up @@ -468,13 +468,17 @@ maybe_disconnect(Url) ->
Seconds -> should_disconnect_secs(Seconds,Url) andalso disconnect(Url)
end.

should_disconnect_ops(Count, _Url) when Count =< 0 ->
false;
should_disconnect_ops(Count, _Url) when Count =:= 1 ->
true;
should_disconnect_ops(Count, Url) ->
Key = {ops_since_disconnect, Url#url.host},
case erlang:get(Key) of
undefined ->
erlang:put(Key, 1),
false;
Count ->
CountUntilLastOne when CountUntilLastOne =:= Count - 1 ->
erlang:put(Key, 0),
true;
Incr ->
Expand Down

0 comments on commit 8f3a681

Please sign in to comment.