summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgarren smith <garren.smith@gmail.com>2020-08-19 16:16:55 +0200
committerGitHub <noreply@github.com>2020-08-19 16:16:55 +0200
commit1c0c9f40225668a67e73d11583c7bd22c042d1f2 (patch)
treebe8c1384f972975824bcfb341d61ccf84e4ce149
parent4d7149cb208070859f6175084555699d1af5f7cb (diff)
downloadcouchdb-1c0c9f40225668a67e73d11583c7bd22c042d1f2.tar.gz
add has_failures to couch_rate_limiter (#3088)
Fixes the case where no writes are done for an index, the rater limiter assumed it was a failure.
-rw-r--r--src/couch_rate/src/couch_rate_limiter.erl17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/couch_rate/src/couch_rate_limiter.erl b/src/couch_rate/src/couch_rate_limiter.erl
index 6f852b1d8..97a630206 100644
--- a/src/couch_rate/src/couch_rate_limiter.erl
+++ b/src/couch_rate/src/couch_rate_limiter.erl
@@ -80,7 +80,8 @@
regular_delay = 100 :: timeout(),
congested_delay = 5000 :: timeout(),
initial_budget = 100,
- latency = 0
+ latency = 0,
+ has_failures = false
}).
-type state() :: #?STATE{}.
@@ -199,7 +200,8 @@ success(_Id, #?STATE{} = State, Writes) ->
writes = Writes,
mean_writes = average(MeanWrites, WinSize, Writes),
mean_reads = average(MeanReads, WinSize, Reads),
- latency = TimerFun() - TS
+ latency = TimerFun() - TS,
+ has_failures = false
})}.
@@ -215,7 +217,8 @@ failure(_Id, #?STATE{} = State) ->
} = State,
{ok, update_min(State#?STATE{
writes = 0,
- latency = TimerFun() - TS
+ latency = TimerFun() - TS,
+ has_failures = true
})}.
@@ -266,18 +269,18 @@ pattern(Id, #?STATE{} = State) ->
#?STATE{
underload_threshold = UnderloadThreshold,
overload_threshold = OverloadThreshold,
- writes = W,
- mean_writes = MW
+ mean_writes = MW,
+ has_failures = HasFailures
} = State,
case min_latency(Id, State) of
MinRollingLatency when MinRollingLatency > OverloadThreshold ->
overloaded;
MinRollingLatency when MinRollingLatency > UnderloadThreshold ->
optimal;
- MinRollingLatency when MinRollingLatency > 0 andalso W == 0 ->
- failed;
MinRollingLatency when MinRollingLatency == 0 andalso MW == 0.0 ->
init;
+ _ when HasFailures ->
+ failed;
_ ->
underloaded
end.