From 13cf80a326063867181f5007bcad73c1df040ec3 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Mon, 6 Feb 2017 19:29:20 +0900 Subject: [PATCH] Re-enable bandwidth throttling --- server/session.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/session.py b/server/session.py index 01ea8e9..9f16b87 100644 --- a/server/session.py +++ b/server/session.py @@ -38,6 +38,7 @@ class SessionBase(JSONSession): self.requests = [] self.start_time = time.time() self.close_time = 0 + self.bw_limit = self.env.bandwidth_limit self.bw_time = self.start_time self.bw_interval = 3600 self.bw_used = 0 @@ -86,6 +87,15 @@ class SessionBase(JSONSession): self.log_info(msg) self.controller.remove_session(self) + def using_bandwidth(self, amount): + now = time.time() + # Reduce the recorded usage in proportion to the elapsed time + elapsed = now - self.bw_time + self.bandwidth_start = now + refund = int(elapsed / self.bw_interval * self.bw_limit) + refund = min(refund, self.bw_used) + self.bw_used += amount - refund + def sub_count(self): return 0