@@ -35,6 +35,8 @@ def __init__(self, url, token, debug=None, timeout=10000, enable_gzip=False, org
35
35
:key bool verify_ssl: Set this to false to skip verifying SSL certificate when calling API from https server.
36
36
:key str ssl_ca_cert: Set this to customize the certificate file to verify the peer.
37
37
:key str proxy: Set this to configure the http proxy to be used (ex. http://localhost:3128)
38
+ :key int connection_pool_maxsize: Number of connections to save that can be reused by urllib3.
39
+ Defaults to "multiprocessing.cpu_count() * 5".
38
40
:key urllib3.util.retry.Retry retries: Set the default retry strategy that is used for all HTTP requests
39
41
except batching writes. As a default there is no one retry strategy.
40
42
@@ -56,6 +58,7 @@ def __init__(self, url, token, debug=None, timeout=10000, enable_gzip=False, org
56
58
conf .verify_ssl = kwargs .get ('verify_ssl' , True )
57
59
conf .ssl_ca_cert = kwargs .get ('ssl_ca_cert' , None )
58
60
conf .proxy = kwargs .get ('proxy' , None )
61
+ conf .connection_pool_maxsize = kwargs .get ('connection_pool_maxsize' , conf .connection_pool_maxsize )
59
62
60
63
auth_token = self .token
61
64
auth_header_name = "Authorization"
@@ -97,6 +100,7 @@ def from_config_file(cls, config_file: str = "config.ini", debug=None, enable_gz
97
100
- timeout,
98
101
- verify_ssl
99
102
- ssl_ca_cert
103
+ - connection_pool_maxsize
100
104
101
105
config.ini example::
102
106
@@ -105,6 +109,7 @@ def from_config_file(cls, config_file: str = "config.ini", debug=None, enable_gz
105
109
org=my-org
106
110
token=my-token
107
111
timeout=6000
112
+ connection_pool_maxsize=25
108
113
109
114
[tags]
110
115
id = 132-987-655
@@ -118,6 +123,7 @@ def from_config_file(cls, config_file: str = "config.ini", debug=None, enable_gz
118
123
token = "my-token"
119
124
org = "my-org"
120
125
timeout = 6000
126
+ connection_pool_maxsize = 25
121
127
122
128
[tags]
123
129
id = "132-987-655"
@@ -152,18 +158,19 @@ def config_value(key: str):
152
158
if config .has_option ('influx2' , 'ssl_ca_cert' ):
153
159
ssl_ca_cert = config_value ('ssl_ca_cert' )
154
160
161
+ connection_pool_maxsize = None
162
+ if config .has_option ('influx2' , 'connection_pool_maxsize' ):
163
+ connection_pool_maxsize = config_value ('connection_pool_maxsize' )
164
+
155
165
default_tags = None
156
166
157
167
if config .has_section ('tags' ):
158
168
tags = {k : v .strip ('"' ) for k , v in config .items ('tags' )}
159
169
default_tags = dict (tags )
160
170
161
- if timeout :
162
- return cls (url , token , debug = debug , timeout = int (timeout ), org = org , default_tags = default_tags ,
163
- enable_gzip = enable_gzip , verify_ssl = _to_bool (verify_ssl ), ssl_ca_cert = ssl_ca_cert )
164
-
165
- return cls (url , token , debug = debug , org = org , default_tags = default_tags , enable_gzip = enable_gzip ,
166
- verify_ssl = _to_bool (verify_ssl ), ssl_ca_cert = ssl_ca_cert )
171
+ return cls (url , token , debug = debug , timeout = _to_int (timeout ), org = org , default_tags = default_tags ,
172
+ enable_gzip = enable_gzip , verify_ssl = _to_bool (verify_ssl ), ssl_ca_cert = ssl_ca_cert ,
173
+ connection_pool_maxsize = _to_int (connection_pool_maxsize ))
167
174
168
175
@classmethod
169
176
def from_env_properties (cls , debug = None , enable_gzip = False ):
@@ -177,22 +184,25 @@ def from_env_properties(cls, debug=None, enable_gzip=False):
177
184
- INFLUXDB_V2_TIMEOUT
178
185
- INFLUXDB_V2_VERIFY_SSL
179
186
- INFLUXDB_V2_SSL_CA_CERT
187
+ - INFLUXDB_V2_CONNECTION_POOL_MAXSIZE
180
188
"""
181
189
url = os .getenv ('INFLUXDB_V2_URL' , "http://localhost:8086" )
182
190
token = os .getenv ('INFLUXDB_V2_TOKEN' , "my-token" )
183
191
timeout = os .getenv ('INFLUXDB_V2_TIMEOUT' , "10000" )
184
192
org = os .getenv ('INFLUXDB_V2_ORG' , "my-org" )
185
193
verify_ssl = os .getenv ('INFLUXDB_V2_VERIFY_SSL' , "True" )
186
194
ssl_ca_cert = os .getenv ('INFLUXDB_V2_SSL_CA_CERT' , None )
195
+ connection_pool_maxsize = os .getenv ('INFLUXDB_V2_CONNECTION_POOL_MAXSIZE' , None )
187
196
188
197
default_tags = dict ()
189
198
190
199
for key , value in os .environ .items ():
191
200
if key .startswith ("INFLUXDB_V2_TAG_" ):
192
201
default_tags [key [16 :].lower ()] = value
193
202
194
- return cls (url , token , debug = debug , timeout = int (timeout ), org = org , default_tags = default_tags ,
195
- enable_gzip = enable_gzip , verify_ssl = _to_bool (verify_ssl ), ssl_ca_cert = ssl_ca_cert )
203
+ return cls (url , token , debug = debug , timeout = _to_int (timeout ), org = org , default_tags = default_tags ,
204
+ enable_gzip = enable_gzip , verify_ssl = _to_bool (verify_ssl ), ssl_ca_cert = ssl_ca_cert ,
205
+ connection_pool_maxsize = _to_int (connection_pool_maxsize ))
196
206
197
207
def write_api (self , write_options = WriteOptions (), point_settings = PointSettings ()) -> WriteApi :
198
208
"""
@@ -337,5 +347,9 @@ def update_request_body(self, path: str, body):
337
347
return _body
338
348
339
349
340
- def _to_bool (verify_ssl ):
341
- return str (verify_ssl ).lower () in ("yes" , "true" )
350
+ def _to_bool (bool_value ):
351
+ return str (bool_value ).lower () in ("yes" , "true" )
352
+
353
+
354
+ def _to_int (int_value ):
355
+ return int (int_value ) if int_value is not None else None
0 commit comments