Skip to content

Commit b6b35f4

Browse files
Neckbusterniketsingh007harshavamsi
authored
feat: Added pool_maxsize for RequestsHttpConnection (opensearch-project#216)
Signed-off-by: Niket Singh <singhnik82@gmail.com> Signed-off-by: Niket Singh <singhnik82@gmail.com> Co-authored-by: Niket Singh <niket.singh@dailyrounds.org> Co-authored-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>
1 parent d6e994a commit b6b35f4

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
44
## [Unreleased]
55
### Added
66
- Added Point in time API rest API([#191](https://github.com/opensearch-project/opensearch-py/pull/191))
7+
- Added pool_maxsize for RequestsHttpConnection ([#216](https://github.com/opensearch-project/opensearch-py/pull/216))
78
- Github workflow for changelog verification ([#218](https://github.com/opensearch-project/opensearch-py/pull/218))
89
- Added overload decorators to helpers-actions.pyi-"bulk" ([#239](https://github.com/opensearch-project/opensearch-py/pull/239))
910
- Document Keberos authenticaion ([214](https://github.com/opensearch-project/opensearch-py/pull/214))

USER_GUIDE.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
- [Getting started with the OpenSearch Python client](#getting-started-with-the-opensearch-python-client)
1+
- [User guide of OpenSearch Python Client](#user-guide-of-opensearch-python-client)
22
- [Setup](#setup)
3-
- [Sample code](#sample-code)
3+
- [Example](#example)
44
- [Creating a client](#creating-a-client)
55
- [Creating an index](#creating-an-index)
66
- [Adding a document to an index](#adding-a-document-to-an-index)
@@ -9,8 +9,8 @@
99
- [Searching for a document](#searching-for-a-document)
1010
- [Deleting a document](#deleting-a-document)
1111
- [Deleting an index](#deleting-an-index)
12-
- [Making API calls](#making-api-calls)
13-
- [Point in time API](#point-in-time-api-calls)
12+
- [Making API Calls](#making-api-calls)
13+
- [Point in Time API](#point-in-time-api)
1414
- [Using plugins](#using-plugins)
1515
- [Alerting plugin](#alerting-plugin)
1616
- [**Searching for monitors**](#searching-for-monitors)
@@ -390,7 +390,9 @@ Refer the AWS documentation regarding usage of IAM credentials to sign requests
390390

391391
Opensearch-py client library also provides an in-house IAM based authentication feature, `AWSV4SignerAuth` that will help users to connect to their opensearch clusters by making use of IAM roles.
392392

393-
##### Pre-requisites to use `AWSV4SignerAuth`
393+
`AWSV4SignerAuth` uses RequestHttpConnection as transport class for communication with opensearch clusters. Opensearch-py client library provides `pool_maxsize` option to modify default connection-pool size.
394+
395+
#### Pre-requisites to use `AWSV4SignerAuth`
394396
- Python version 3.6 or above,
395397
- Install [botocore](https://pypi.org/project/botocore/) using pip
396398

@@ -413,7 +415,8 @@ client = OpenSearch(
413415
http_auth = auth,
414416
use_ssl = True,
415417
verify_certs = True,
416-
connection_class = RequestsHttpConnection
418+
connection_class = RequestsHttpConnection,
419+
pool_maxsize = 20
417420
)
418421

419422
q = 'miller'

opensearchpy/connection/http_requests.py

+11
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class RequestsHttpConnection(Connection):
6666
:arg http_compress: Use gzip compression
6767
:arg opaque_id: Send this value in the 'X-Opaque-Id' HTTP header
6868
For tracing all requests made by this transport.
69+
:arg pool_maxsize: Maximum connection pool size used by pool-manager
70+
For custom connection-pooling on current session
6971
"""
7072

7173
def __init__(
@@ -82,6 +84,7 @@ def __init__(
8284
headers=None,
8385
http_compress=None,
8486
opaque_id=None,
87+
pool_maxsize=None,
8588
**kwargs
8689
):
8790
if not REQUESTS_AVAILABLE:
@@ -94,6 +97,14 @@ def __init__(
9497
for key in list(self.session.headers):
9598
self.session.headers.pop(key)
9699

100+
# Mount http-adapter with custom connection-pool size. Default=10
101+
if pool_maxsize and isinstance(pool_maxsize, int):
102+
pool_adapter = requests.adapters.HTTPAdapter(
103+
pool_maxsize=pool_maxsize
104+
)
105+
self.session.mount("http://", pool_adapter)
106+
self.session.mount("https://", pool_adapter)
107+
97108
super(RequestsHttpConnection, self).__init__(
98109
host=host,
99110
port=port,

0 commit comments

Comments
 (0)