projects
/
prosody.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
mod_s2s: Detect TLS compression
[prosody.git]
/
util
/
throttle.lua
diff --git
a/util/throttle.lua
b/util/throttle.lua
index 82b0a67ba57903a8d184279b1afb2f10852d86c7..55e1d07b3f5a836b450fc65cf23a1c31b7363e49 100644
(file)
--- a/
util/throttle.lua
+++ b/
util/throttle.lua
@@
-1,6
+1,7
@@
local gettime = require "socket".gettime;
local setmetatable = setmetatable;
local gettime = require "socket".gettime;
local setmetatable = setmetatable;
+local floor = math.floor;
module "throttle"
module "throttle"
@@
-11,7
+12,7
@@
function throttle:update()
local newt = gettime();
local elapsed = newt - self.t;
self.t = newt;
local newt = gettime();
local elapsed = newt - self.t;
self.t = newt;
- local balance =
self.rate * elapsed
+ self.balance;
+ local balance =
floor(self.rate * elapsed)
+ self.balance;
if balance > self.max then
self.balance = self.max;
else
if balance > self.max then
self.balance = self.max;
else
@@
-34,7
+35,7
@@
function throttle:poll(cost, split)
if split then
self.balance = 0;
end
if split then
self.balance = 0;
end
- return false, balance, (cost-
self.
balance);
+ return false, balance, (cost-balance);
end
end
end
end