aboutsummaryrefslogtreecommitdiffstats
path: root/util/throttle.lua
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2017-09-17 13:29:14 -0400
committerWaqas Hussain <waqas20@gmail.com>2017-09-17 13:29:14 -0400
commitd88cbfbecd492fba389560a695d8210799970809 (patch)
treed1ffe5ed362459cd3fa98ae7dc73a14d7ee78e73 /util/throttle.lua
parent4fcc7cd0497557d7417f846edb8f4fdf1cea1530 (diff)
downloadprosody-d88cbfbecd492fba389560a695d8210799970809.tar.gz
prosody-d88cbfbecd492fba389560a695d8210799970809.zip
util.throttle: Fix initial time setting (double accounting the first time) and fractional balance updates (0.1*10 was not the same as 1*1)
Diffstat (limited to 'util/throttle.lua')
-rw-r--r--util/throttle.lua4
1 files changed, 2 insertions, 2 deletions
diff --git a/util/throttle.lua b/util/throttle.lua
index 18692a8a..a8191886 100644
--- a/util/throttle.lua
+++ b/util/throttle.lua
@@ -12,7 +12,7 @@ function throttle:update()
local newt = gettime();
local elapsed = newt - self.t;
self.t = newt;
- local balance = floor(self.rate * elapsed) + self.balance;
+ local balance = (self.rate * elapsed) + self.balance;
if balance > self.max then
self.balance = self.max;
else
@@ -40,7 +40,7 @@ function throttle:poll(cost, split)
end
local function create(max, period)
- return setmetatable({ rate = max / period, max = max, t = 0, balance = max }, throttle_mt);
+ return setmetatable({ rate = max / period, max = max, t = gettime(), balance = max }, throttle_mt);
end
return {