summaryrefslogtreecommitdiff
path: root/docker/transport/unixconn.py
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2016-09-12 17:43:50 -0700
committerJoffrey F <joffrey@docker.com>2016-09-12 17:43:50 -0700
commitbe7d0f01844d5c08ee157446ce96f5bc6381507c (patch)
tree7954e3ae1241b4fe5ffbe3e0908d4fb89c969a17 /docker/transport/unixconn.py
parent72e7afe17a9aa8b002a726377ce86cc9e13f6f35 (diff)
downloaddocker-py-1207-configurable-num-pools.tar.gz
Number of pools in adapter is configurable1207-configurable-num-pools
Default increased from 10 to 25 Signed-off-by: Joffrey F <joffrey@docker.com>
Diffstat (limited to 'docker/transport/unixconn.py')
-rw-r--r--docker/transport/unixconn.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/docker/transport/unixconn.py b/docker/transport/unixconn.py
index e09b6bf..b7905a0 100644
--- a/docker/transport/unixconn.py
+++ b/docker/transport/unixconn.py
@@ -2,6 +2,8 @@ import six
import requests.adapters
import socket
+from .. import constants
+
if six.PY3:
import http.client as httplib
else:
@@ -12,6 +14,7 @@ try:
except ImportError:
import urllib3
+
RecentlyUsedContainer = urllib3._collections.RecentlyUsedContainer
@@ -32,28 +35,31 @@ class UnixHTTPConnection(httplib.HTTPConnection, object):
class UnixHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool):
- def __init__(self, base_url, socket_path, timeout=60):
+ def __init__(self, base_url, socket_path, timeout=60, maxsize=10):
super(UnixHTTPConnectionPool, self).__init__(
- 'localhost', timeout=timeout
+ 'localhost', timeout=timeout, maxsize=maxsize
)
self.base_url = base_url
self.socket_path = socket_path
self.timeout = timeout
def _new_conn(self):
- return UnixHTTPConnection(self.base_url, self.socket_path,
- self.timeout)
+ return UnixHTTPConnection(
+ self.base_url, self.socket_path, self.timeout
+ )
class UnixAdapter(requests.adapters.HTTPAdapter):
- def __init__(self, socket_url, timeout=60):
+ def __init__(self, socket_url, timeout=60,
+ num_pools=constants.DEFAULT_NUM_POOLS):
socket_path = socket_url.replace('http+unix://', '')
if not socket_path.startswith('/'):
socket_path = '/' + socket_path
self.socket_path = socket_path
self.timeout = timeout
- self.pools = RecentlyUsedContainer(10,
- dispose_func=lambda p: p.close())
+ self.pools = RecentlyUsedContainer(
+ num_pools, dispose_func=lambda p: p.close()
+ )
super(UnixAdapter, self).__init__()
def get_connection(self, url, proxies=None):