diff options
author | James Socol <me@jamessocol.com> | 2014-08-21 11:17:14 -0400 |
---|---|---|
committer | James Socol <me@jamessocol.com> | 2014-08-21 11:17:14 -0400 |
commit | 502946811d0b3520599edff477c4fdf0afc79286 (patch) | |
tree | b9fb8c60d9c988e4bac8b5177b138f8000702ee7 | |
parent | 1fd482a418c556a1e5ee10d375033a80c5430301 (diff) | |
parent | ce5e64d8937eb491708d7f4e36cf90cb3b5ad00e (diff) | |
download | pystatsd-502946811d0b3520599edff477c4fdf0afc79286.tar.gz |
Merge pull request #51 from davidblewett/patch-1
Optimize Pipeline by using a deque
-rw-r--r-- | statsd/client.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/statsd/client.py b/statsd/client.py index 4ea0b57..ecad262 100644 --- a/statsd/client.py +++ b/statsd/client.py @@ -1,4 +1,5 @@ from __future__ import with_statement +from collections import deque from functools import wraps import random import socket @@ -140,7 +141,7 @@ class Pipeline(StatsClient): self._client = client self._prefix = client._prefix self._maxudpsize = client._maxudpsize - self._stats = [] + self._stats = deque() def _after(self, data): if data is not None: @@ -153,12 +154,12 @@ class Pipeline(StatsClient): self.send() def send(self): - # Use pop(0) to preserve the order of the stats. + # Use popleft to preserve the order of the stats. if not self._stats: return - data = self._stats.pop(0) + data = self._stats.popleft() while self._stats: - stat = self._stats.pop(0) + stat = self._stats.popleft() if len(stat) + len(data) + 1 >= self._maxudpsize: self._client._after(data) data = stat |