projects
/
prosody.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
configure: Replaces tabs with spaces in --help
[prosody.git]
/
util
/
throttle.lua
diff --git
a/util/throttle.lua
b/util/throttle.lua
index 8b62e7974f3eb74ddd391ef1309b5a9de4efdbd5..55e1d07b3f5a836b450fc65cf23a1c31b7363e49 100644
(file)
--- a/
util/throttle.lua
+++ b/
util/throttle.lua
@@
-1,5
+1,7
@@
local gettime = require "socket".gettime;
local gettime = require "socket".gettime;
+local setmetatable = setmetatable;
+local floor = math.floor;
module "throttle"
module "throttle"
@@
-10,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
@@
-33,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