aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--etc_upload/config.json6
-rw-r--r--policyhandler/deploy_handler.py19
-rw-r--r--policyhandler/policy_rest.py17
3 files changed, 38 insertions, 4 deletions
diff --git a/etc_upload/config.json b/etc_upload/config.json
index f394b00..920a9be 100644
--- a/etc_upload/config.json
+++ b/etc_upload/config.json
@@ -2,7 +2,8 @@
"policy_handler" : {
"system" : "policy_handler",
"thread_pool_size" : 4,
- "scope_prefixes" : ["DCAE_alex.Config_"],
+ "pool_connections" : 20,
+ "scope_prefixes" : ["DCAE_alex.Config_", "DCAE.Config_"],
"policy_retry_count" : 5,
"policy_retry_sleep" : 5,
"policy_engine" : {
@@ -18,6 +19,7 @@
},
"target_entity" : "policy_engine"
},
- "deploy_handler" : "policy_deploy_handler"
+ "deploy_handler_" : "policy_deploy_handler",
+ "deploy_handler" : "alex_dh"
}
}
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)
diff --git a/policyhandler/policy_rest.py b/policyhandler/policy_rest.py
index d49164c..bf8a31d 100644
--- a/policyhandler/policy_rest.py
+++ b/policyhandler/policy_rest.py
@@ -136,6 +136,8 @@ class PolicyRest(object):
""" policy-engine """
_logger = logging.getLogger("policy_handler.policy_rest")
_lazy_inited = False
+
+ _requests_session = None
_url = None
_headers = None
_target_entity = None
@@ -151,7 +153,20 @@ class PolicyRest(object):
if PolicyRest._lazy_inited:
return
PolicyRest._lazy_inited = True
+
config = Config.config[Config.FIELD_POLICY_ENGINE]
+
+ pool_size = config.get("pool_connections", 20)
+ PolicyRest._requests_session = requests.Session()
+ PolicyRest._requests_session.mount(
+ 'https://',
+ requests.adapters.HTTPAdapter(pool_connections=pool_size, pool_maxsize=pool_size)
+ )
+ PolicyRest._requests_session.mount(
+ 'http://',
+ requests.adapters.HTTPAdapter(pool_connections=pool_size, pool_maxsize=pool_size)
+ )
+
PolicyRest._url = config["url"] + config["path_api"]
PolicyRest._headers = config["headers"]
PolicyRest._target_entity = config.get("target_entity", Config.FIELD_POLICY_ENGINE)
@@ -186,7 +201,7 @@ class PolicyRest(object):
PolicyRest._logger.info(log_line)
res = None
try:
- res = requests.post(full_path, json=json_body, headers=headers)
+ res = PolicyRest._requests_session.post(full_path, json=json_body, headers=headers)
except requests.exceptions.RequestException as ex:
error_code = AuditHttpCode.SERVICE_UNAVAILABLE_ERROR.value
error_msg = "failed to post to PDP {0} {1} msg={2} headers={3}" \