Skip to content

Commit 64fba72

Browse files
committed
Number of pools in adapter is configurable
Default increased from 10 to 25 Signed-off-by: Joffrey F <[email protected]>
1 parent 06b6a62 commit 64fba72

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

docker/client.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class Client(
4040
api.VolumeApiMixin):
4141
def __init__(self, base_url=None, version=None,
4242
timeout=constants.DEFAULT_TIMEOUT_SECONDS, tls=False,
43-
user_agent=constants.DEFAULT_USER_AGENT):
43+
user_agent=constants.DEFAULT_USER_AGENT,
44+
num_pools=constants.DEFAULT_NUM_POOLS):
4445
super(Client, self).__init__()
4546

4647
if tls and not base_url:
@@ -58,7 +59,9 @@ def __init__(self, base_url=None, version=None,
5859
base_url, constants.IS_WINDOWS_PLATFORM, tls=bool(tls)
5960
)
6061
if base_url.startswith('http+unix://'):
61-
self._custom_adapter = UnixAdapter(base_url, timeout)
62+
self._custom_adapter = UnixAdapter(
63+
base_url, timeout, num_pools=num_pools
64+
)
6265
self.mount('http+docker://', self._custom_adapter)
6366
self._unmount('http://', 'https://')
6467
self.base_url = 'http+docker://localunixsocket'
@@ -68,7 +71,9 @@ def __init__(self, base_url=None, version=None,
6871
'The npipe:// protocol is only supported on Windows'
6972
)
7073
try:
71-
self._custom_adapter = NpipeAdapter(base_url, timeout)
74+
self._custom_adapter = NpipeAdapter(
75+
base_url, timeout, num_pools=num_pools
76+
)
7277
except NameError:
7378
raise errors.DockerException(
7479
'Install pypiwin32 package to enable npipe:// support'
@@ -80,7 +85,9 @@ def __init__(self, base_url=None, version=None,
8085
if isinstance(tls, TLSConfig):
8186
tls.configure_client(self)
8287
elif tls:
83-
self._custom_adapter = ssladapter.SSLAdapter()
88+
self._custom_adapter = ssladapter.SSLAdapter(
89+
num_pools=num_pools
90+
)
8491
self.mount('https://', self._custom_adapter)
8592
self.base_url = base_url
8693

docker/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
IS_WINDOWS_PLATFORM = (sys.platform == 'win32')
1616

1717
DEFAULT_USER_AGENT = "docker-py/{0}".format(version)
18+
DEFAULT_NUM_POOLS = 25

docker/transport/npipeconn.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import six
22
import requests.adapters
33

4+
from .. import constants
45
from .npipesocket import NpipeSocket
56

67
if six.PY3:
@@ -33,9 +34,9 @@ def connect(self):
3334

3435

3536
class NpipeHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool):
36-
def __init__(self, npipe_path, timeout=60):
37+
def __init__(self, npipe_path, timeout=60, maxsize=10):
3738
super(NpipeHTTPConnectionPool, self).__init__(
38-
'localhost', timeout=timeout
39+
'localhost', timeout=timeout, maxsize=maxsize
3940
)
4041
self.npipe_path = npipe_path
4142
self.timeout = timeout
@@ -47,11 +48,12 @@ def _new_conn(self):
4748

4849

4950
class NpipeAdapter(requests.adapters.HTTPAdapter):
50-
def __init__(self, base_url, timeout=60):
51+
def __init__(self, base_url, timeout=60,
52+
num_pools=constants.DEFAULT_NUM_POOLS):
5153
self.npipe_path = base_url.replace('npipe://', '')
5254
self.timeout = timeout
5355
self.pools = RecentlyUsedContainer(
54-
10, dispose_func=lambda p: p.close()
56+
num_pools, dispose_func=lambda p: p.close()
5557
)
5658
super(NpipeAdapter, self).__init__()
5759

docker/transport/unixconn.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import requests.adapters
33
import socket
44

5+
from .. import constants
6+
57
if six.PY3:
68
import http.client as httplib
79
else:
@@ -12,6 +14,7 @@
1214
except ImportError:
1315
import urllib3
1416

17+
1518
RecentlyUsedContainer = urllib3._collections.RecentlyUsedContainer
1619

1720

@@ -32,28 +35,31 @@ def connect(self):
3235

3336

3437
class UnixHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool):
35-
def __init__(self, base_url, socket_path, timeout=60):
38+
def __init__(self, base_url, socket_path, timeout=60, maxsize=10):
3639
super(UnixHTTPConnectionPool, self).__init__(
37-
'localhost', timeout=timeout
40+
'localhost', timeout=timeout, maxsize=maxsize
3841
)
3942
self.base_url = base_url
4043
self.socket_path = socket_path
4144
self.timeout = timeout
4245

4346
def _new_conn(self):
44-
return UnixHTTPConnection(self.base_url, self.socket_path,
45-
self.timeout)
47+
return UnixHTTPConnection(
48+
self.base_url, self.socket_path, self.timeout
49+
)
4650

4751

4852
class UnixAdapter(requests.adapters.HTTPAdapter):
49-
def __init__(self, socket_url, timeout=60):
53+
def __init__(self, socket_url, timeout=60,
54+
num_pools=constants.DEFAULT_NUM_POOLS):
5055
socket_path = socket_url.replace('http+unix://', '')
5156
if not socket_path.startswith('/'):
5257
socket_path = '/' + socket_path
5358
self.socket_path = socket_path
5459
self.timeout = timeout
55-
self.pools = RecentlyUsedContainer(10,
56-
dispose_func=lambda p: p.close())
60+
self.pools = RecentlyUsedContainer(
61+
num_pools, dispose_func=lambda p: p.close()
62+
)
5763
super(UnixAdapter, self).__init__()
5864

5965
def get_connection(self, url, proxies=None):

0 commit comments

Comments
 (0)