summaryrefslogtreecommitdiffstats
path: root/policyhandler/deploy_handler.py
diff options
context:
space:
mode:
authorAlex Shatov <alexs@att.com>2017-09-13 16:22:17 -0400
committerAlex Shatov <alexs@att.com>2017-09-13 16:22:17 -0400
commit541b5bcdd5add5aec1fa77ae2b6ea79fc8ad6e9d (patch)
treedddad223074c44f2c4cb87883d32141bc958c366 /policyhandler/deploy_handler.py
parent42a989a6b9b6388947da6fc273728a24c19fa686 (diff)
setting the pool-size in requests session
* to cache the connections - performance improvement Change-Id: I5a9b3ee30d40dc8d1b8154d5345a00b716e07964 Issue-Id: DCAEGEN2-62 Signed-off-by: Alex Shatov <alexs@att.com>
Diffstat (limited to 'policyhandler/deploy_handler.py')
-rw-r--r--policyhandler/deploy_handler.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/policyhandler/deploy_handler.py b/policyhandler/deploy_handler.py
index 7d9c513..1d50fc3 100644
--- a/policyhandler/deploy_handler.py
+++ b/policyhandler/deploy_handler.py
@@ -27,10 +27,14 @@ from .config import Config
from .discovery import DiscoveryClient
from .onap.audit import REQUEST_X_ECOMP_REQUESTID, Audit, AuditHttpCode
+POOL_SIZE = 1
+
class DeployHandler(object):
""" deploy-handler """
_logger = logging.getLogger("policy_handler.deploy_handler")
_lazy_inited = False
+
+ _requests_session = None
_config = None
_url = None
_url_path = None
@@ -42,6 +46,17 @@ class DeployHandler(object):
if DeployHandler._lazy_inited:
return
DeployHandler._lazy_inited = True
+
+ DeployHandler._requests_session = requests.Session()
+ DeployHandler._requests_session.mount(
+ 'https://',
+ requests.adapters.HTTPAdapter(pool_connections=POOL_SIZE, pool_maxsize=POOL_SIZE)
+ )
+ DeployHandler._requests_session.mount(
+ 'http://',
+ requests.adapters.HTTPAdapter(pool_connections=POOL_SIZE, pool_maxsize=POOL_SIZE)
+ )
+
DeployHandler._target_entity = Config.config["deploy_handler"]
DeployHandler._url = DiscoveryClient.get_service_url(DeployHandler._target_entity)
DeployHandler._url_path = DeployHandler._url + '/policy'
@@ -66,7 +81,9 @@ class DeployHandler(object):
res = None
try:
- res = requests.post(DeployHandler._url_path, json=msg, headers=headers)
+ res = DeployHandler._requests_session.post(
+ DeployHandler._url_path, json=msg, headers=headers
+ )
except requests.exceptions.RequestException as ex:
error_msg = "failed to post to deployment-handler {0} {1} msg={2} headers={3}" \
.format(DeployHandler._url_path, str(ex), msg_str, headers_str)