From 7f0ebb25bd13cb1f6398c34751427369c9605fd1 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Fri, 4 Jul 2014 11:10:12 +1200 Subject: [PATCH] Use a requests.Session object to enable pooling. Without this a new Session, which has a new PoolManager and thus a new HTTPS connection pool is used for every single request. We may have an issue with leaking connections (based on my debug runs so far) but the default behaviour in that case degrades to unpooled (new connection made, used, thrown away) so it will be no worse other than the small overhead of 10 (the default) sockets & SSL session metadata. Change-Id: I4b2a4efa414dfc5f8f57b6640ba6796b8a109f58 --- gertty/sync.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gertty/sync.py b/gertty/sync.py index e7fd0a6..0352d46 100644 --- a/gertty/sync.py +++ b/gertty/sync.py @@ -505,6 +505,7 @@ class Sync(object): self.app = app self.log = logging.getLogger('gertty.sync') self.queue = MultiQueue([HIGH_PRIORITY, NORMAL_PRIORITY, LOW_PRIORITY]) + self.session = requests.Session() self.submitTask(UploadReviewsTask(HIGH_PRIORITY)) self.submitTask(SyncProjectListTask(HIGH_PRIORITY)) self.submitTask(SyncSubscribedProjectsTask(HIGH_PRIORITY)) @@ -562,7 +563,7 @@ class Sync(object): def get(self, path): url = self.url(path) self.log.debug('GET: %s' % (url,)) - r = requests.get(url, + r = self.session.get(url, verify=self.app.config.verify_ssl, auth=requests.auth.HTTPDigestAuth(self.app.config.username, self.app.config.password), @@ -576,7 +577,7 @@ class Sync(object): url = self.url(path) self.log.debug('POST: %s' % (url,)) self.log.debug('data: %s' % (data,)) - r = requests.post(url, data=json.dumps(data).encode('utf8'), + r = self.session.post(url, data=json.dumps(data).encode('utf8'), verify=self.app.config.verify_ssl, auth=requests.auth.HTTPDigestAuth(self.app.config.username, self.app.config.password),