add traffic control for each TCP connection

This commit is contained in:
破娃酱
2017-02-12 22:35:26 +08:00
parent 2750af4a2e
commit 72ca31dad9
5 changed files with 75 additions and 18 deletions
+2 -2
View File
@@ -88,11 +88,11 @@ class LRUCache(collections.MutableMapping):
for key in self._keys_to_last_time:
return key
def sweep(self):
def sweep(self, sweep_item_cnt = SWEEP_MAX_ITEMS):
# O(n - m)
now = time.time()
c = 0
while c < SWEEP_MAX_ITEMS:
while c < sweep_item_cnt:
if len(self._keys_to_last_time) == 0:
break
for key in self._keys_to_last_time: