-
Notifications
You must be signed in to change notification settings - Fork 3k
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
{Core} Config knack only once #16634
Conversation
Core |
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.0028270000000000005 python/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()
|
A very good example for getting to the bottom and driving to the end!! I love it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kneels down
Description
#16301 introduced function
_configure_knack
.During tests,
AzCli
can be created multiple times in the same process, causing_configure_knack
to 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_names
is only changed once to