Skip to content

Setting special limits for Python 3.[6|7] #890

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

Merged
merged 3 commits into from
Sep 14, 2021

Conversation

vrdmr
Copy link
Member

@vrdmr vrdmr commented Sep 14, 2021

Description

For Python 3.6 and 3.7, setting max workers to large values is problematic as the implementation of ThreadPoolExecutor for both that versions do not reuse threads until max_workers number is hit, and that is a danger to the functioning of the app. This PR limits the number of max_workers to 32 for 3.6 and 3.7 and allows it to be sys.maxint for Python 3.8+.

Reference doc - ThreadPoolExecutor

Changed in version 3.8: Default value of max_workers is changed to min(32, os.cpu_count() + 4). This default value preserves at least 5 workers for I/O bound tasks. It utilizes at most 32 CPU cores for CPU bound tasks which release the GIL. And it avoids using very large resources implicitly on many-core machines.

ThreadPoolExecutor now reuses idle worker threads before starting max_workers worker threads too.

Fixes #873


PR information

  • The title of the PR is clear and informative.
  • There are a small number of commits, each of which has an informative message. This means that previously merged commits do not appear in the history of the PR. For information on cleaning up the commits in your pull request, see this page.
  • If applicable, the PR references the bug/issue that it fixes in the description.
  • New Unit tests were added for the changes made and CI is passing.

Quality of Code and Contribution Guidelines

Updated unittests and cleared some old logging statements.
Also, updated CODEOWNERS file
Copy link

@AnatoliB AnatoliB left a comment

Choose a reason for hiding this comment

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

LGTM

@vrdmr vrdmr merged commit f5271ce into dev Sep 14, 2021
@vrdmr vrdmr deleted the vameru/tp-worker-limits-for-36-and-37 branch September 14, 2021 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow specifying PYTHON_THREADPOOL_THREAD_COUNT larger than 32
2 participants