Skip to content

Update the max TP threads count to sys.maxsize #875

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 2 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion azure_functions_worker/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import sys

# Capabilities
RAW_HTTP_BODY_BYTES = "RawHttpBodyBytes"
TYPED_DATA_COLLECTION = "TypedDataCollection"
Expand Down Expand Up @@ -36,7 +38,7 @@
# Setting Defaults
PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT = 1
PYTHON_THREADPOOL_THREAD_COUNT_MIN = 1
PYTHON_THREADPOOL_THREAD_COUNT_MAX = 32
PYTHON_THREADPOOL_THREAD_COUNT_MAX = sys.maxsize
PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT = False
PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT_39 = True
PYTHON_ENABLE_WORKER_EXTENSIONS_DEFAULT = False
Expand Down
4 changes: 3 additions & 1 deletion azure_functions_worker/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,9 @@ def tp_max_workers_validator(value: str) -> bool:
if int_value < PYTHON_THREADPOOL_THREAD_COUNT_MIN or (
int_value > PYTHON_THREADPOOL_THREAD_COUNT_MAX):
logger.warning(f'{PYTHON_THREADPOOL_THREAD_COUNT} must be set '
'to a value between 1 and 32. '
f'to a value between '
f'{PYTHON_THREADPOOL_THREAD_COUNT_MIN} and '
f'{PYTHON_THREADPOOL_THREAD_COUNT_MAX}. '
'Reverting to default value for max_workers')
return False

Expand Down
47 changes: 30 additions & 17 deletions tests/unittests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from azure_functions_worker import protos
from azure_functions_worker import testutils
from azure_functions_worker.constants import PYTHON_THREADPOOL_THREAD_COUNT, \
PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT
PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT, \
PYTHON_THREADPOOL_THREAD_COUNT_MAX, \
PYTHON_THREADPOOL_THREAD_COUNT_MIN

SysVersionInfo = col.namedtuple("VersionInfo", ["major", "minor", "micro",
"releaselevel", "serial"])
Expand All @@ -35,6 +37,7 @@ def setUp(self):
script_root=DISPATCHER_FUNCTIONS_DIR)
self._default_workers: Optional[
int] = PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT
self._allowed_max_workers: int = 100000
self._pre_env = dict(os.environ)
self.mock_version_info = patch(
'azure_functions_worker.dispatcher.sys.version_info',
Expand Down Expand Up @@ -87,10 +90,12 @@ async def test_dispatcher_sync_threadpool_set_worker(self):
"""Test if the sync threadpool maximum worker can be set
"""
# Configure thread pool max worker
os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT: '5'})
os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT:
f'{self._allowed_max_workers}'})
async with self._ctrl as host:
await self._check_if_function_is_ok(host)
await self._assert_workers_threadpool(self._ctrl, host, 5)
await self._assert_workers_threadpool(self._ctrl, host,
self._allowed_max_workers)

async def test_dispatcher_sync_threadpool_invalid_worker_count(self):
"""Test when sync threadpool maximum worker is set to an invalid value,
Expand Down Expand Up @@ -124,15 +129,20 @@ async def test_dispatcher_sync_threadpool_below_min_setting(self):
self._default_workers)
mock_logger.warning.assert_any_call(
f'{PYTHON_THREADPOOL_THREAD_COUNT} must be set to a value '
'between 1 and 32. Reverting to default value for max_workers')
f'between {PYTHON_THREADPOOL_THREAD_COUNT_MIN} and '
f'{PYTHON_THREADPOOL_THREAD_COUNT_MAX}. Reverting to default '
f'value for max_workers')

@unittest.skip("We no more check any max limit. This is up to the customer,"
" how ever high int they want to set")
async def test_dispatcher_sync_threadpool_exceed_max_setting(self):
"""Test if the sync threadpool will pick up default value when the
setting is above maximum
"""
with patch('azure_functions_worker.dispatcher.logger') as mock_logger:
# Configure thread pool max worker to an invalid value
os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT: '33'})
os.environ.update({PYTHON_THREADPOOL_THREAD_COUNT:
f'{self._over_max_workers}'})
async with self._ctrl as host:
await self._check_if_function_is_ok(host)

Expand All @@ -142,8 +152,9 @@ async def test_dispatcher_sync_threadpool_exceed_max_setting(self):

mock_logger.warning.assert_any_call(
f'{PYTHON_THREADPOOL_THREAD_COUNT} must be set to a value '
'between 1 and 32. '
'Reverting to default value for max_workers')
f'between {PYTHON_THREADPOOL_THREAD_COUNT_MIN} and '
f'{PYTHON_THREADPOOL_THREAD_COUNT_MAX}. Reverting to default '
f'value for max_workers')

async def test_dispatcher_sync_threadpool_in_placeholder(self):
"""Test if the sync threadpool will pick up app setting in placeholder
Expand All @@ -154,10 +165,10 @@ async def test_dispatcher_sync_threadpool_in_placeholder(self):

# Reload environment variable on specialization
await host.reload_environment(environment={
PYTHON_THREADPOOL_THREAD_COUNT: '3'
PYTHON_THREADPOOL_THREAD_COUNT: f'{self._allowed_max_workers}'
})
# Ensure the dispatcher sync threadpool should fallback to 1
await self._assert_workers_threadpool(self._ctrl, host, 3)
await self._assert_workers_threadpool(self._ctrl, host,
self._allowed_max_workers)

async def test_dispatcher_sync_threadpool_in_placeholder_invalid(self):
"""Test if the sync threadpool will use the default setting when the
Expand All @@ -178,6 +189,8 @@ async def test_dispatcher_sync_threadpool_in_placeholder_invalid(self):
mock_logger.warning.assert_any_call(
f'{PYTHON_THREADPOOL_THREAD_COUNT} must be an integer')

@unittest.skip("We no more check any max limit. This is up to the customer,"
" how ever high int they want to set")
async def test_dispatcher_sync_threadpool_in_placeholder_above_max(self):
"""Test if the sync threadpool will use the default setting when the
app setting is above maximum
Expand All @@ -188,15 +201,15 @@ async def test_dispatcher_sync_threadpool_in_placeholder_above_max(self):

# Reload environment variable on specialization
await host.reload_environment(environment={
PYTHON_THREADPOOL_THREAD_COUNT: '33'
PYTHON_THREADPOOL_THREAD_COUNT: f'{self._over_max_workers}'
})
await self._assert_workers_threadpool(self._ctrl, host,
self._default_workers)

mock_logger.warning.assert_any_call(
f'{PYTHON_THREADPOOL_THREAD_COUNT} must be set to a '
f'value '
'between 1 and 32. '
'between 1 and 1024. '
'Reverting to default value for max_workers')

async def test_dispatcher_sync_threadpool_in_placeholder_below_min(self):
Expand All @@ -216,10 +229,10 @@ async def test_dispatcher_sync_threadpool_in_placeholder_below_min(self):
self._default_workers)

mock_logger.warning.assert_any_call(
f'{PYTHON_THREADPOOL_THREAD_COUNT} must be set to a '
f'value '
'between 1 and 32. '
'Reverting to default value for max_workers')
f'{PYTHON_THREADPOOL_THREAD_COUNT} must be set to a value '
f'between {PYTHON_THREADPOOL_THREAD_COUNT_MIN} and '
f'{PYTHON_THREADPOOL_THREAD_COUNT_MAX}. Reverting to '
f'default value for max_workers')

async def test_sync_invocation_request_log(self):
with patch('azure_functions_worker.dispatcher.logger') as mock_logger:
Expand Down Expand Up @@ -346,7 +359,7 @@ async def _assert_workers_threadpool(self, ctrl, host,
# Check if the dispatcher still function
await self._check_if_function_is_ok(host)

async def _check_if_function_is_ok(self, host) -> Tuple[str, str]:
async def _check_if_function_is_ok(self, host) -> Tuple[str, str, str]:
# Ensure the function can be properly loaded
function_name = "show_context"
func_id, load_r = await host.load_function(function_name)
Expand Down