diff --git a/shadowsocks/eventloop.py b/shadowsocks/eventloop.py index 5707154..e36f858 100644 --- a/shadowsocks/eventloop.py +++ b/shadowsocks/eventloop.py @@ -223,7 +223,7 @@ class EventLoop(object): callback() self._last_time = now if events and not handle: - time.sleep(0.02) + time.sleep(0.001) def __del__(self): self._impl.close() diff --git a/shadowsocks/tcprelay.py b/shadowsocks/tcprelay.py index f6e9f7a..7f2d3c9 100644 --- a/shadowsocks/tcprelay.py +++ b/shadowsocks/tcprelay.py @@ -97,7 +97,7 @@ UDP_MAX_BUF_SIZE = 65536 class SpeedTester(object): def __init__(self, max_speed = 0): self.max_speed = max_speed * 1024 - self.timeout = 3 + self.timeout = 5 self._cache = deque() self.sum_len = 0 @@ -109,12 +109,12 @@ class SpeedTester(object): def isExceed(self): if self.max_speed > 0: if self.sum_len > 0: - if self._cache[0][0] + self.timeout < time.time(): + cut_t = time.time() + t = max(cut_t - self._cache[0][0], 0.01) + speed = self.sum_len / t + if self._cache[0][0] + self.timeout < cut_t: self.sum_len -= self._cache[0][1] self._cache.popleft() - if self.sum_len > 0: - t = max(time.time() - self._cache[0][0], 0.1) - speed = (self.sum_len - self._cache[0][1]) / (time.time() - self._cache[0][0]) return speed >= self.max_speed return False