Reduce requests connection pool size

Requests defaults to keeping 10 connections to the API alive. This
seems excessive, reduce it to 2.

Change-Id: Iac67fd4d855388d2671da3b7258b31d1eead77a9
This commit is contained in:
Russell Haering 2014-06-16 15:46:01 -07:00
parent 263f97c0e0
commit 1893e02c10
2 changed files with 9 additions and 0 deletions

View File

@ -33,7 +33,15 @@ class APIClient(object):
def __init__(self, api_url, driver_name):
self.api_url = api_url.rstrip('/')
self.driver_name = driver_name
# Only keep alive a maximum of 2 connections to the API. More will be
# opened if they are needed, but they will be closed immediately after
# use.
adapter = requests.adapters.HTTPAdapter(pool_connections=2,
pool_maxsize=2)
self.session = requests.Session()
self.session.mount(self.api_url, adapter)
self.encoder = encoding.RESTJSONEncoder()
self.log = log.getLogger(__name__)

View File

@ -53,6 +53,7 @@ class TestHeartbeater(test_base.BaseTestCase):
def setUp(self):
super(TestHeartbeater, self).setUp()
self.mock_agent = mock.Mock()
self.mock_agent.api_url = 'https://fake_api.example.org:8081/'
self.heartbeater = agent.IronicPythonAgentHeartbeater(self.mock_agent)
self.heartbeater.api = mock.Mock()
self.heartbeater.hardware = mock.create_autospec(