Skip to content

Commit

Permalink
adds parameters to configure number of connections to pool
Browse files Browse the repository at this point in the history
  • Loading branch information
marrony committed Nov 3, 2016
1 parent 3d5c403 commit a9ffffe
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion faunadb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from requests import Request, Session
from requests.auth import HTTPBasicAuth
from requests.adapters import HTTPAdapter

from faunadb.errors import _get_or_raise, FaunaError, UnexpectedError
from faunadb.query import _wrap
Expand Down Expand Up @@ -53,6 +54,8 @@ def __init__(
port=None,
timeout=60,
observer=None,
pool_connections=10,
pool_maxsize=10,
**kwargs):
"""
:param secret:
Expand All @@ -67,6 +70,10 @@ def __init__(
Read timeout in seconds.
:param observer:
Callback that will be passed a :any:`RequestResult` after every completed request.
:param pool_connections:
The number of connection pools to cache.
:param pool_maxsize:
The maximum number of connections to save in the pool.
"""

self.domain = domain
Expand All @@ -77,8 +84,15 @@ def __init__(
self.base_url = "%s://%s:%s" % (self.scheme, self.domain, self.port)
self.observer = observer

self.pool_connections = pool_connections
self.pool_maxsize = pool_maxsize

if ('session' not in kwargs) or ('counter' not in kwargs):
self.session = Session()
self.session.mount('https://', HTTPAdapter(pool_connections=pool_connections,
pool_maxsize=pool_maxsize))
self.session.mount('http://', HTTPAdapter(pool_connections=pool_connections,
pool_maxsize=pool_maxsize))
self.counter = _Counter(1)

self.session.headers.update({
Expand Down Expand Up @@ -133,7 +147,9 @@ def new_session_client(self, secret, observer=None):
timeout=self.session.timeout,
observer=observer or self.observer,
session=self.session,
counter=self.counter)
counter=self.counter,
pool_connections=self.pool_connections,
pool_maxsize=self.pool_maxsize)
else:
raise UnexpectedError("Cannnot create a session client from a closed session", None)

Expand Down

0 comments on commit a9ffffe

Please sign in to comment.