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

[OpenStack] Reuse connections to same host/port #1886

Merged
merged 2 commits into from
Jul 31, 2023
Merged

Conversation

llamasoft
Copy link
Contributor

@llamasoft llamasoft commented Mar 28, 2023

Fixes #1885 1885.
If the connection host/port/secure hasn't changed then the current connection can be reused.
This greatly reduces overhead when doing bulk actions such as storage object downloads.

In testing with bulk downloading storage objects, this resulted in an overall 2x throughput increase.

Enables OpenStack connection reuse

Description

The underlying common.base.Connection object reuses connections (via LibcloudConnection -> Requests Session -> urllib3 connection pool) but the OpenStack's driver discards this every time it makes a new request. This results in a large amount of time spent opening connections and verifying SSL certificates. The proposed change only creates a new connection if any of the host/port/secure settings have changed.

In theory, for HTTP-based providers there is never a need to explicitly create a new connection because the underlying Requests/urllib3 libraries will create new connections as needed. However, the underlying LibcloudConnection class treats host an immutable, so the session it creates will only ever be used for a single host/port. For this reason, we only need to re-connect() when the host/port changes.

Status

Done, ready for review.

Checklist (tick everything that applies)

  • Code linting (required, can be done after the PR checks)
  • Documentation
  • Tests
  • ICLA (required for bigger changes)

If the connection host/port/secure hasn't changed then the current connection can be reused.
This greatly reduces overhead when doing bulk actions such as storage object downloads.
@Kami
Copy link
Member

Kami commented Jul 31, 2023

Thanks for the contribution - that's a very good catch.

I would imagine that this "regression" is likely related to the time when we switched from home grown library for handling HTTP(s) requests to a wrapper around the requests library.

@Kami
Copy link
Member

Kami commented Jul 31, 2023

asfgit pushed a commit that referenced this pull request Jul 31, 2023
@asfgit asfgit merged commit 587242c into apache:trunk Jul 31, 2023
20 of 21 checks passed
@Kami
Copy link
Member

Kami commented Jul 31, 2023

I've added a basic unit test in ebecb9a.

This test is not the most ideal since it only exercises the logic of _set_up_connection_info() method, but it doesn't actually verify it end to end to make sure the underlying HTTP connection is actually re-used. That would require an integration test / similar. It's still better to have this unit test than having no test though.

Change has now been merged into trunk. Thanks

@Kami Kami added this to the v3.8.0 milestone Aug 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenStack driver creates new connection on every request
3 participants