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

Move invocation logging into a thread pool executor #1049

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion azure_functions_worker/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ async def _handle__invocation_request(self, request):
f'sync threadpool max workers: '
f'{self.get_sync_tp_workers_set()}'
)

logger.info(', '.join(function_invocation_logs))

args = {}
Expand Down Expand Up @@ -826,6 +827,13 @@ def gen(resp_queue):

class AsyncLoggingHandler(logging.Handler):

def __init__(self, *args, **kwargs):
self._logging_tp: concurrent.futures.ThreadPoolExecutor = \
concurrent.futures.ThreadPoolExecutor(
max_workers=1,
thread_name_prefix="logging")
super().__init__(*args, **kwargs)

def emit(self, record: LogRecord) -> None:
# Since we disable console log after gRPC channel is initiated,
# we should redirect all the messages into dispatcher.
Expand All @@ -836,7 +844,10 @@ def emit(self, record: LogRecord) -> None:
# buffered in this handler, not calling the emit yet.
msg = self.format(record)
try:
Dispatcher.current.on_logging(record, msg)
self._logging_tp.submit(
Dispatcher.current.on_logging,
record,
msg)
except RuntimeError as runtime_error:
# This will cause 'Dispatcher not found' failure.
# Logging such of an issue will cause infinite loop of gRPC logging
Expand Down
Loading