Skip to content

Commit 7796462

Browse files
committed
swift: Allow to configure the requests pool size
By default, python-requests share a pool for the whole process and this one have only 10 parallels connections. This change use the keystoneauth1 adapter. So, we have a pool dedicated for swift and we can configure it. And we also get all tcp keepalive workaround for free. This allows keep the default for 'retries'. Closes: gnocchixyz#509
1 parent 9db907a commit 7796462

File tree

2 files changed

+47
-27
lines changed

2 files changed

+47
-27
lines changed

gnocchi/common/swift.py

+42-27
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,61 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414
import daiquiri
15+
import keystoneauth1.session
1516
from six.moves.urllib.parse import quote
1617

18+
from gnocchi import storage
19+
20+
LOG = daiquiri.getLogger(__name__)
21+
22+
1723
try:
1824
from swiftclient import client as swclient
1925
from swiftclient import utils as swift_utils
26+
27+
class CustomSwiftConnecion(swclient.Connection):
28+
def __init__(self, conf):
29+
self.conf = conf
30+
31+
os_options = {
32+
'endpoint_type': conf.swift_endpoint_type,
33+
'service_type': conf.swift_service_type,
34+
'user_domain_name': conf.swift_user_domain_name,
35+
'project_domain_name': conf.swift_project_domain_name,
36+
}
37+
if conf.swift_region:
38+
os_options['region_name'] = conf.swift_region
39+
40+
super(CustomSwiftConnecion, self).__init__(
41+
preauthurl=conf.swift_url,
42+
auth_version=conf.swift_auth_version,
43+
authurl=conf.swift_authurl,
44+
preauthtoken=conf.swift_preauthtoken,
45+
user=conf.swift_user,
46+
key=conf.swift_key,
47+
tenant_name=conf.swift_project_name,
48+
timeout=conf.swift_timeout,
49+
insecure=conf.swift_auth_insecure,
50+
os_options=os_options,
51+
cacert=conf.swift_cacert)
52+
53+
def http_connection(self, url=None):
54+
url, conn = super(CustomSwiftConnecion, self).http_connection(url)
55+
adapter = keystoneauth1.session.TCPKeepAliveAdapter(
56+
pool_maxsize=self.conf.swift_max_parallel_requests)
57+
conn.request_session.mount("http://", adapter)
58+
conn.request_session.mount("https://", adapter)
59+
return url, conn
60+
2061
except ImportError:
2162
swclient = None
2263
swift_utils = None
2364

24-
from gnocchi import storage
25-
26-
LOG = daiquiri.getLogger(__name__)
27-
2865

2966
def get_connection(conf):
3067
if swclient is None:
3168
raise RuntimeError("python-swiftclient unavailable")
32-
33-
os_options = {
34-
'endpoint_type': conf.swift_endpoint_type,
35-
'service_type': conf.swift_service_type,
36-
'user_domain_name': conf.swift_user_domain_name,
37-
'project_domain_name': conf.swift_project_domain_name,
38-
}
39-
if conf.swift_region:
40-
os_options['region_name'] = conf.swift_region
41-
42-
return swclient.Connection(
43-
preauthurl=conf.swift_url,
44-
auth_version=conf.swift_auth_version,
45-
authurl=conf.swift_authurl,
46-
preauthtoken=conf.swift_preauthtoken,
47-
user=conf.swift_user,
48-
key=conf.swift_key,
49-
tenant_name=conf.swift_project_name,
50-
timeout=conf.swift_timeout,
51-
insecure=conf.swift_auth_insecure,
52-
os_options=os_options,
53-
cacert=conf.swift_cacert,
54-
retries=0)
69+
return CustomSwiftConnecion(conf)
5570

5671

5772
POST_HEADERS = {'Accept': 'application/json', 'Content-Type': 'text/plain'}

gnocchi/storage/swift.py

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
cfg.StrOpt('swift_url',
3939
help='Swift URL. '
4040
'If unset, it is obtained from the auth service.'),
41+
cfg.IntOpt('swift_max_parallel_requests',
42+
default=50,
43+
# NOTE(sileht): python-requests default in 10, it's far too low
44+
# for any workload.
45+
help='Maximun of Swift parallel requests.'),
4146
cfg.StrOpt('swift_authurl',
4247
default="http://localhost:8080/auth/v1.0",
4348
help='Swift auth URL.'),

0 commit comments

Comments
 (0)