Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce no of retries for no connection to 1 #199

Merged
merged 4 commits into from
Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/python_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade setuptools pip
git config --global url."https://".insteadOf git://
pip install -U -r requirements.txt
pip install -U -r dev-requirements.txt

Expand Down
11 changes: 10 additions & 1 deletion adsws/api/discoverer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ def __init__(self, endpoint, service_uri, deploy_path, route):
self.cs = None
try:
self.default_request_timeout = current_app.config.get("DEFAULT_REQUEST_TIMEOUT", 60)
self.pool_connections = current_app.config.get("REQUESTS_POOL_CONNECTIONS", 20)
self.pool_maxsize = current_app.config.get("REQUESTS_POOL_MAXSIZE", 1000)
self.max_retries = current_app.config.get("REQUESTS_MAX_RETRIES", 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REQUESTS_MAX_RETRIES does not exist in the config file but REQUESTS_POOL_RETRIES does, could you pick one and correct the other?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting this. Fixed!

except RuntimeError:
# Unit testing fails: "RuntimeError: Working outside of application context."
self.default_request_timeout = 60
self.pool_connections = 20
self.pool_maxsize = 1000
self.max_retries = 1
if service_uri.startswith('consul://'):
self.cs = ConsulService(
service_uri,
Expand All @@ -40,7 +46,10 @@ def __init__(self, endpoint, service_uri, deploy_path, route):
# requests sessions)
# http://docs.python-requests.org/en/latest/api/?highlight=max_retries#requests.adapters.HTTPAdapter
#
http_adapter = requests.adapters.HTTPAdapter(pool_connections=20, pool_maxsize=1000, max_retries=3, pool_block=False)
http_adapter = requests.adapters.HTTPAdapter(pool_connections=self.pool_connections, \
pool_maxsize=self.pool_maxsize, \
max_retries=self.max_retries, \
pool_block=False)
self.session.mount('http://', http_adapter)

@staticmethod
Expand Down
4 changes: 4 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@
# Flask session config (http://flask.pocoo.org/docs/0.12/config/)
PERMANENT_SESSION_LIFETIME = 3600*24*365.25 # 1 year in seconds
SESSION_REFRESH_EACH_REQUEST = True

REQUESTS_POOL_CONNECTIONS=20
REQUESTS_POOL_MAXSIZE=1000
REQUESTS_POOL_RETRIES=1