-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close collected files after reading them to free buffers
In 2013, the memory consumption caused by bugtool was analysed and some counter measures were implemented. One was that RRD data was no longer fetched directly from xAPI, the RRD data along with all other data was kept in string buffers and only written to disk after all data was collected. This caused memory pressure, paging and seemingly even more severe issues like slowness or even out-of-memory situations. Two of the counter-measures were: - `dump_xapi_rrds()` was disabled by default as it's data was large, and kept in memory too. Also, the `xcp-rrdd` process jumped to using 142MiB of memory (and kept using that memory)" - The data collection algorithm was refactored: Reading files and keeping the data in memory until all data was red was replaced by passind the files directly to the ZipFile and TarFile libraries and the string buffers ware now freed immediately after that. This reduced the memory consumption dramatically, but during this time, it was not discovered that the file descriptors of all regular files which were captured into the status report archive were never closed. Running unit tests using PYTHONDEVMODE=yes in .pre-commit-config.yaml allowed Python3 (Python2.7 does not have such check) to warn about these unclosed file descriptors and point to the location of open(). Fixes: - Use context managers to fix the locations which are easy to fix. - Extend the unit tests to cover both fixed locations. - Configure GitHub CI to create source annotations for PYTHONWARNINGS which are shown in code review of PRs. Remarks: In the course of a year, my development machine accumulated 24000 files in /var/xapi/blobs (spread evenly over all subdirectories), so Python apparently does some garbage collection, but it's certainly not good to never close so many open file-like objects in Python. Closing them in time has the potential to reduce the memory usage of the xen-bugtool / xenserver-status-report process further. There are more locations where Python 3.10 reports unclosed file objects but it seems we may have to use enable tracemalloc as recommended by the issued PYTHONWARNINGS to find their source. Signed-off-by: Bernhard Kaindl <[email protected]>
- Loading branch information
1 parent
1aae840
commit 0df1ed1
Showing
8 changed files
with
80 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"problemMatcher": [ | ||
{ | ||
"owner": "python-libs-PYTHONWARNINGS", | ||
"severity": "warning", | ||
"pattern": [ | ||
{ | ||
"regexp": "^.*/python-libs/(.+):([0-9]*):(.*):(.*)$", | ||
"file": 1, | ||
"line": 2, | ||
"code": 3, | ||
"message": 4 | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,9 +89,17 @@ jobs: | |
path: ~/.cache/pre-commit | ||
key: pre-commit|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} | ||
|
||
# https://docs.python.org/3/library/devmode.html#resourcewarning-example | ||
# If pytest runs with PYTHONDEVMODE=yes, it enables resource checks like | ||
# unclosed file warnings. Configure GitHub to show all such warnings as | ||
# annotations at the source location they occur in the PR code review: | ||
|
||
- run: echo "::add-matcher::.github/workflows/PYTHONWARNINGS-problemMatcher.json" | ||
|
||
- uses: pre-commit/[email protected] | ||
name: Run pre-commit checks | ||
env: | ||
PYTHONDEVMODE: yes # Enable Python3 checks. See the comment above. | ||
# Skip the no-commit-to-branch check inside of GitHub CI (for CI on merge to master) | ||
SKIP: no-commit-to-branch | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
root:x:0: |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
root:x:0:0:root:/root:/bin/bash |
2 changes: 2 additions & 0 deletions
2
tests/integration/dom0-template/etc/xensource/bugtool/mock/stuff.xml
This file contains 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
This file contains 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
This file contains 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
This file contains 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
0df1ed1
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.
https://github.com/marketplace/actions/pytest-coverage-comment