Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-105623 Fix performance degradation in logging RotatingFileHandler#105887

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
serhiy-storchaka merged 7 commits intopython:mainfromzhatt:gh-105623
Jun 27, 2024

Conversation

zhatt
Copy link
Contributor

@zhattzhatt commentedJun 17, 2023
edited by bedevere-bot
Loading

The check for whether the log file is a real file is expensive on NFS filesystems. This commit reorders the rollover condition checking to not do the file type check if the expected file size is less than the rotation threshold.

arhadthedev and bdraco reacted with thumbs up emoji
…ndlerThe check for whether the log file is a real file is expensive on NFSfilesystems.  This commit reorders the rollover condition checking tonot do the file type check if the expected file size is less than therotation threshold.
@ghost
Copy link

ghost commentedJun 17, 2023
edited by ghost
Loading

All commit authors signed the Contributor License Agreement.
CLA signed

@arhadthedevarhadthedev added the performancePerformance or resource usage labelJun 17, 2023
…G06od.rstCo-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
@vsajipvsajip added the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelJun 19, 2023
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@vsajip for commit84ad7d8 🤖

If you want to schedule another build, you need to add the🔨 test-with-buildbots label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelJun 19, 2023
@arhadthedev
Copy link
Member

From buildbots:

Objects/object.c:2197: _Py_ForgetReference: Assertion failed: invalid object chainEnable tracemalloc to get the memory block allocation tracebackobject address  : 0x7ff344737770object refcount : 0object type     : 0x560543494660object type name: tupleobject repr     : <refcnt 0 at 0x7ff344737770>

This PR is not the cause (Python-only change cannot break reference counting). However, we need to fix the crash before merging the PR.

Comment on lines -190 to -198
# See bpo-45401: Never rollover anything other than regular files
if os.path.exists(self.baseFilename) and not os.path.isfile(self.baseFilename):
return False
Copy link
Contributor

Choose a reason for hiding this comment

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

Even with a local file-system this is a substantive chunk of the run time

Screenshot 2023-07-12 at 6 22 51 PM

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@bdraco I'm not familiar with the report generated by py-spy. Are you seeing that the os.path.exists() and os.path.isfile() are expensive or the self.format()? The self.format() is probably a different bug that needs fixed since rollover is formatting the message once to get its length and then emit later formats it again.

Copy link
Contributor

@bdracobdracoJul 13, 2023
edited
Loading

Choose a reason for hiding this comment

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

I'd expect the format and emit to be expensive here (relatively ... the logger is quite busy). What is unexpected is the cost ofos.path.exists andos.path.isfile which is solved by this PR.

Sorry for the lack of clarity. This looks like a good fix and I wanted to point out the problem is not limited to NFS.

Copy link
Member

Choose a reason for hiding this comment

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

Under normal usage,self.baseFilename doesn't change. Perhaps we just cache the result of the existence/is-file test when we open the file? Wouldn't that be a better approach?

methane reacted with thumbs up emoji
Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM. In the current paradigm it is the right solution.

I wonder whether it would be better to perform this check indoRollover(), before renaming files. But this is a different and not so easy issue.

bdraco reacted with thumbs up emoji
@fantabolous
Copy link

fantabolous commentedJun 27, 2024
edited
Loading

Thanks, in my rather logging-heavy Windows NTFS project, shouldRollover went from 25-35% of cpu to <2% after monkey patching this in. (According to yappi.)

@serhiy-storchakaserhiy-storchakaenabled auto-merge (squash)June 27, 2024 16:36
@serhiy-storchakaserhiy-storchaka merged commite9b4ec6 intopython:mainJun 27, 2024
33 checks passed
@serhiy-storchakaserhiy-storchaka added needs backport to 3.12only security fixes needs backport to 3.13bugs and security fixes labelsJun 28, 2024
@miss-islington-app
Copy link

Thanks@zhatt for the PR, and@serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks@zhatt for the PR, and@serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestJun 28, 2024
…ndler (pythonGH-105887)The check for whether the log file is a real file is expensive on NFSfilesystems.  This commit reorders the rollover condition checking tonot do the file type check if the expected file size is less than therotation threshold.(cherry picked from commite9b4ec6)Co-authored-by: Craig Robson <craig@zhatt.com>Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestJun 28, 2024
…ndler (pythonGH-105887)The check for whether the log file is a real file is expensive on NFSfilesystems.  This commit reorders the rollover condition checking tonot do the file type check if the expected file size is less than therotation threshold.(cherry picked from commite9b4ec6)Co-authored-by: Craig Robson <craig@zhatt.com>Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
@bedevere-app
Copy link

GH-121116 is a backport of this pull request to the3.12 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.12only security fixes labelJun 28, 2024
@bedevere-app
Copy link

GH-121117 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelJun 28, 2024
@serhiy-storchaka
Copy link
Member

Thank you for your contribution@zhatt, and thank you for reminder@fantabolous. I forgot about this PR.

serhiy-storchaka pushed a commit that referenced this pull requestJun 28, 2024
…andler (GH-105887) (GH-121116)The check for whether the log file is a real file is expensive on NFSfilesystems.  This commit reorders the rollover condition checking tonot do the file type check if the expected file size is less than therotation threshold.(cherry picked from commite9b4ec6)Co-authored-by: Craig Robson <craig@zhatt.com>Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
serhiy-storchaka pushed a commit that referenced this pull requestJun 28, 2024
…andler (GH-105887) (GH-121117)The check for whether the log file is a real file is expensive on NFSfilesystems.  This commit reorders the rollover condition checking tonot do the file type check if the expected file size is less than therotation threshold.(cherry picked from commite9b4ec6)Co-authored-by: Craig Robson <craig@zhatt.com>Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
mrahtz pushed a commit to mrahtz/cpython that referenced this pull requestJun 30, 2024
…ndler (pythonGH-105887)The check for whether the log file is a real file is expensive on NFSfilesystems.  This commit reorders the rollover condition checking tonot do the file type check if the expected file size is less than therotation threshold.Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull requestJul 11, 2024
…ndler (pythonGH-105887)The check for whether the log file is a real file is expensive on NFSfilesystems.  This commit reorders the rollover condition checking tonot do the file type check if the expected file size is less than therotation threshold.Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
estyxx pushed a commit to estyxx/cpython that referenced this pull requestJul 17, 2024
…ndler (pythonGH-105887)The check for whether the log file is a real file is expensive on NFSfilesystems.  This commit reorders the rollover condition checking tonot do the file type check if the expected file size is less than therotation threshold.Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@bdracobdracobdraco left review comments

@arhadthedevarhadthedevarhadthedev left review comments

@serhiy-storchakaserhiy-storchakaserhiy-storchaka approved these changes

@vsajipvsajipAwaiting requested review from vsajipvsajip is a code owner

Assignees
No one assigned
Labels
performancePerformance or resource usage
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

7 participants
@zhatt@bedevere-bot@arhadthedev@fantabolous@serhiy-storchaka@vsajip@bdraco

[8]ページ先頭

©2009-2025 Movatter.jp