Skip to content

[python] fix: Configure python urllib3 connection pool size#17323

Merged
wing328 merged 1 commit intoOpenAPITools:masterfrom
robertschweizer:readd-connection-pool-maxsize
Dec 6, 2023
Merged

[python] fix: Configure python urllib3 connection pool size#17323
wing328 merged 1 commit intoOpenAPITools:masterfrom
robertschweizer:readd-connection-pool-maxsize

Conversation

@robertschweizer
Copy link
Copy Markdown
Contributor

This was removed in #16802, but using a higher value than 1, or at least making this configurable makes complete sense.

Without this, we get a lot of these log messages:

[ WARNING] Connection pool is full, discarding connection:

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (For Windows users, please run the script in Git BASH)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.1.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@cbornet (2017/09) @tomplus (2018/10) @krjakbrjak (2023/02) @fa0311 (2023/10) @multani (2023/10) @wing328

This was removed in OpenAPITools#16802, but using a higher value than 1,
or at least making this configurable makes complete sense.

Without this, we get a lot of these log messages:

[ WARNING] Connection pool is full, discarding connection:
"""
{{/asyncio}}
{{^asyncio}}
self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we fix it with a static value as before? (it was set to 4 before #16802)

I've had several issues in the past while running services in containers where the CPU count is most of the time the one from the host but not the one from set on the container itself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before #16802, the code was

        if maxsize is None:
            if configuration.connection_pool_maxsize is not None:
                maxsize = configuration.connection_pool_maxsize
            else:
                maxsize = 4

So it was set to 4 only if configuration.connection_pool_maxsize was explicitly set to None, instead of letting it default to multiprocessing.cpu_count() * 5. I'm reverting configuration.mustache to the same code it had before #16802.

From how I understand this setting in urllib3, you should not get more connections than you have threads. This is only an upper limit.

TBH, this fix is most convenient for our use-case (I think). But it would actually be cleanest for the OpenAPI generator to not set any custom default, go with urllib3's default, and make it configurable. What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, you are right, I just re-read #16802: so multiprocessing.cpu_count() * 5 was indeed most probably the most default value.

Then:

  • Let's roll back to the previous value multiprocessing.cpu_count() * 5 to restore the previous behavior.
  • It's still changeable once the Configuration object has been created, so it can be adjusted on a per-client basis.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks! Then the current state of the PR is good and we can resolve?

Copy link
Copy Markdown
Contributor

@multani multani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

@wing328 do you want to take a look?

Copy link
Copy Markdown
Contributor

@fa0311 fa0311 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Good To Me.
It was my mistake to remove it. #16802

@wing328 wing328 merged commit 6a43a37 into OpenAPITools:master Dec 6, 2023
@wing328 wing328 added this to the 7.2.0 milestone Dec 6, 2023
@wing328 wing328 changed the title [python]fix: Configure python urllib3 connection pool size [python] fix: Configure python urllib3 connection pool size Aug 31, 2025
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.

4 participants