Conversation
Collaborator
|
Core |
Member
Author
|
It turns out the culprit is Tested with: import logging
import timeit
# Create many loggers
for i in range(300):
logging.getLogger("azure.{}".format(i))
ITERATION_COUNT = 5000
start = timeit.default_timer()
# Call getLogger many times
for i in range(ITERATION_COUNT):
logging.getLogger('azure')
print("getLogger takes", timeit.default_timer() - start)
# Call setLevel many times
cli_logger = logging.getLogger('azure')
start = timeit.default_timer()
for i in range(ITERATION_COUNT):
cli_logger.setLevel(logging.DEBUG)
print("setLevel takes", timeit.default_timer() - start)> ~\AppData\Local\Programs\Python\Python38\python.exe test.py
getLogger takes 0.004355399999999995
setLevel takes 0.18627549999999998 # Very slow
> ~\AppData\Local\Programs\Python\Python36\python.exe test.py
getLogger takes 0.0050362
setLevel takes 0.0028270000000000005python/cpython#2752 added def setLevel(self, level):
...
self.manager._clear_cache()
def _clear_cache(self):
...
for logger in self.loggerDict.values():
if isinstance(logger, Logger):
logger._cache.clear()Since To analyze the performance impact, we can focus on def location():
for item in target:
operation()
|
Collaborator
|
A very good example for getting to the bottom and driving to the end!! I love it. |
fengzhou-msft
approved these changes
Jan 25, 2021
kairu-ms
approved these changes
Jan 25, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
#16301 introduced function
_configure_knack.During tests,
AzClican be created multiple times in the same process, causing_configure_knackto be executed multiple times, resulting in duplicated'azure'entries incli_logger_names:This causes huge delay on CLI Automation Full Test / Automation Test Python38.
https://dev.azure.com/azure-sdk/public/_pipeline/analytics/duration?definitionId=1623&contextType=build
https://dev.azure.com/azure-sdk/public/_build/results?buildId=697879&view=results
Tested with Python 3.7 and it also suffers from the slowness.
Changes
This PR utilizes Python's module cache to make sure
cli_logger_namesis only changed once to