Mercurial > hg
view tests/test-install.t @ 47010:76ae43d5b1db stable
repoview: fix memory leak of filtered repo classes
The leak occurs in long-running server processes with
extensions, and is measured at 110kB per request.
Before this change, the contents of the `_filteredrepotypes`
cache are not properly garbage collected, despite it begin
a `WeakKeyDictionary`.
Extensions have a tendency to generate a new repository class
for each `localrepo` instantiation. Server processes based
on `hgwebdir_mod` will instantiate a new `localrepo` for each
HTTP request that involves a repository.
As a result, with a testing process that repeatedly opens a
repository with several extensions activated
(`topic` notably among them), we see a steady increase in
resident memory of 110kB per repository instantiation before this
change. This is also true, if we call `gc.collect()` at each
instantiation, like `hgwebdir_mod` does, or not.
The cause of the leak is that the *values* aren't weak references.
This change uses `weakref.ref` for the values, and this makes
in our measurements the resident size increase drop to 5kB per
repository instantiation, with no explicit call of `gc.collect()`
at all.
There is currently no reason to believe that this remaining leak
of 5kB is related to or even due to Mercurial core.
We've also seen evidence that `ui.ui` instances weren't properly
garbage collected before the change (with the change, they are).
This could explain why the figures are relatively high.
In theory, the collection of weak references could lead to
much more misses in the cache, so we measured the impact on
the original case that was motivation for introducing that cache
in 7e89bd0cfb86 (see also issue5043): `hg convert` of the
mozilla-central repository. The bad news here is that there is a
major memory leak there, both with and without the present changeset.
There were no more cache misses, and we could see no
more memory leak with this change: the resident size after importing
roughly 100000 changesets was at 12.4GB before, and 12.5GB after.
The small increase is mentioned for completeness only, and we
believe that it should be ignored, at least as long as the main
leak isn't fixed. At less than 1% of the main leak, even finding out
whether it is merely noise would be wasteful.
Original context where this was spotted and first mitigated:
https://foss.heptapod.net/heptapod/heptapod/-/issues/466
The leak reduction was also obtained in Heptapod inner HTTP server,
which amounts to the same as `hgwebdir_mod` for these questions.
The measurements done with Python 3.9, similar figures seen with 3.8.
More work on our side would be needed to give measurements with 2.7,
because of testing server process does not support it.
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Fri, 23 Apr 2021 18:30:53 +0200 |
parents | ad107ed7a4aa |
children | fa50f208de73 |
line wrap: on
line source
hg debuginstall $ hg debuginstall checking encoding (ascii)... checking Python executable (*) (glob) checking Python implementation (*) (glob) checking Python version (2.*) (glob) (no-py3 !) checking Python version (3.*) (glob) (py3 !) checking Python lib (.*[Ll]ib.*)... (re) checking Python security support (*) (glob) TLS 1.2 not supported by Python install; network connections lack modern security (?) SNI not supported by Python install; may have connectivity issues with some servers (?) checking Rust extensions \((installed|missing)\) (re) checking Mercurial version (*) (glob) checking Mercurial custom build (*) (glob) checking module policy (*) (glob) checking installed modules (*mercurial)... (glob) checking registered compression engines (*zlib*) (glob) checking available compression engines (*zlib*) (glob) checking available compression engines for wire protocol (*zlib*) (glob) checking "re2" regexp engine \((available|missing)\) (re) checking templates (*mercurial?templates)... (glob) checking default template (*mercurial?templates?map-cmdline.default) (glob) checking commit editor... (*) (glob) checking username (test) no problems detected hg debuginstall JSON $ hg debuginstall -Tjson | sed 's|\\\\|\\|g' [ { "compengines": ["bz2", "bz2truncated", "none", "zlib"*], (glob) "compenginesavail": ["bz2", "bz2truncated", "none", "zlib"*], (glob) "compenginesserver": [*"zlib"*], (glob) "defaulttemplate": "*mercurial?templates?map-cmdline.default", (glob) "defaulttemplateerror": null, "defaulttemplatenotfound": "default", "editor": "*", (glob) "editornotfound": false, "encoding": "ascii", "encodingerror": null, "extensionserror": null, (no-pure !) "hgmodulepolicy": "*", (glob) "hgmodules": "*mercurial", (glob) "hgver": "*", (glob) "hgverextra": "*", (glob) "problems": 0, "pythonexe": "*", (glob) "pythonimplementation": "*", (glob) "pythonlib": "*", (glob) "pythonsecurity": [*], (glob) "pythonver": "*.*.*", (glob) "re2": (true|false), (re) "templatedirs": "*mercurial?templates", (glob) "username": "test", "usernameerror": null, "vinotfound": false } ] hg debuginstall with no username $ HGUSER= hg debuginstall checking encoding (ascii)... checking Python executable (*) (glob) checking Python implementation (*) (glob) checking Python version (2.*) (glob) (no-py3 !) checking Python version (3.*) (glob) (py3 !) checking Python lib (.*[Ll]ib.*)... (re) checking Python security support (*) (glob) TLS 1.2 not supported by Python install; network connections lack modern security (?) SNI not supported by Python install; may have connectivity issues with some servers (?) checking Rust extensions \((installed|missing)\) (re) checking Mercurial version (*) (glob) checking Mercurial custom build (*) (glob) checking module policy (*) (glob) checking installed modules (*mercurial)... (glob) checking registered compression engines (*zlib*) (glob) checking available compression engines (*zlib*) (glob) checking available compression engines for wire protocol (*zlib*) (glob) checking "re2" regexp engine \((available|missing)\) (re) checking templates (*mercurial?templates)... (glob) checking default template (*mercurial?templates?map-cmdline.default) (glob) checking commit editor... (*) (glob) checking username... no username supplied (specify a username in your configuration file) 1 problems detected, please check your install! [1] hg debuginstall with invalid encoding $ HGENCODING=invalidenc hg debuginstall | grep encoding checking encoding (invalidenc)... unknown encoding: invalidenc exception message in JSON $ HGENCODING=invalidenc HGUSER= hg debuginstall -Tjson | grep error "defaulttemplateerror": null, "encodingerror": "unknown encoding: invalidenc", "extensionserror": null, (no-pure !) "usernameerror": "no username supplied", path variables are expanded (~ is the same as $TESTTMP) $ mkdir tools $ touch tools/testeditor.exe #if execbit $ chmod 755 tools/testeditor.exe #endif $ HGEDITOR="~/tools/testeditor.exe" hg debuginstall checking encoding (ascii)... checking Python executable (*) (glob) checking Python implementation (*) (glob) checking Python version (2.*) (glob) (no-py3 !) checking Python version (3.*) (glob) (py3 !) checking Python lib (.*[Ll]ib.*)... (re) checking Python security support (*) (glob) TLS 1.2 not supported by Python install; network connections lack modern security (?) SNI not supported by Python install; may have connectivity issues with some servers (?) checking Rust extensions \((installed|missing)\) (re) checking Mercurial version (*) (glob) checking Mercurial custom build (*) (glob) checking module policy (*) (glob) checking installed modules (*mercurial)... (glob) checking registered compression engines (*zlib*) (glob) checking available compression engines (*zlib*) (glob) checking available compression engines for wire protocol (*zlib*) (glob) checking "re2" regexp engine \((available|missing)\) (re) checking templates (*mercurial?templates)... (glob) checking default template (*mercurial?templates?map-cmdline.default) (glob) checking commit editor... ($TESTTMP/tools/testeditor.exe) checking username (test) no problems detected print out the binary post-shlexsplit in the error message when commit editor is not found (this is intentionally using backslashes to mimic a windows usecase). $ HGEDITOR="c:\foo\bar\baz.exe -y -z" hg debuginstall checking encoding (ascii)... checking Python executable (*) (glob) checking Python implementation (*) (glob) checking Python version (2.*) (glob) (no-py3 !) checking Python version (3.*) (glob) (py3 !) checking Python lib (.*[Ll]ib.*)... (re) checking Python security support (*) (glob) TLS 1.2 not supported by Python install; network connections lack modern security (?) SNI not supported by Python install; may have connectivity issues with some servers (?) checking Rust extensions \((installed|missing)\) (re) checking Mercurial version (*) (glob) checking Mercurial custom build (*) (glob) checking module policy (*) (glob) checking installed modules (*mercurial)... (glob) checking registered compression engines (*zlib*) (glob) checking available compression engines (*zlib*) (glob) checking available compression engines for wire protocol (*zlib*) (glob) checking "re2" regexp engine \((available|missing)\) (re) checking templates (*mercurial?templates)... (glob) checking default template (*mercurial?templates?map-cmdline.default) (glob) checking commit editor... (c:\foo\bar\baz.exe) (windows !) Can't find editor 'c:\foo\bar\baz.exe' in PATH (windows !) checking commit editor... (c:foobarbaz.exe) (no-windows !) Can't find editor 'c:foobarbaz.exe' in PATH (no-windows !) (specify a commit editor in your configuration file) checking username (test) 1 problems detected, please check your install! [1] debuginstall extension support $ hg debuginstall --config extensions.fsmonitor= --config fsmonitor.watchman_exe=false | grep atchman fsmonitor checking for watchman binary... (false) watchman binary missing or broken: warning: Watchman unavailable: watchman exited with code 1 Verify the json works too: $ hg debuginstall --config extensions.fsmonitor= --config fsmonitor.watchman_exe=false -Tjson | grep atchman "fsmonitor-watchman": "false", "fsmonitor-watchman-error": "warning: Watchman unavailable: watchman exited with code 1", Verify that Mercurial is installable with pip. Note that this MUST be the last test in this file, because we do some nasty things to the shell environment in order to make the virtualenv work reliably. On Python 3, we use the venv module, which is part of the standard library. But some Linux distros strip out this module's functionality involving pip, so we have to look for the ensurepip module, which these distros strip out completely. On Python 2, we use the 3rd party virtualenv module, if available. $ cd $TESTTMP $ unset PYTHONPATH #if py3 ensurepip network-io $ "$PYTHON" -m venv installenv >> pip.log Hack: Debian does something a bit different in ensurepip.bootstrap. This makes it so that pip thinks the 'wheel' wheel is installed so it can build wheels; when it goes to try, however, it shells out to run `python3 -u <setup.py>`, that *doesn't* get the 'wheel' wheel, and it fails with an invalid command 'bdist_wheel'. To fix this, we just delete the wheel from where Debian put it in our virtual env. Then pip doesn't think it's installed and doesn't try to build. $ rm installenv/share/python-wheels/wheel-*.whl >/dev/null 2>&1 || true Note: we use this weird path to run pip and hg to avoid platform differences, since it's bin on most platforms but Scripts on Windows. $ ./installenv/*/pip install $TESTDIR/.. >> pip.log Failed building wheel for mercurial (?) WARNING: You are using pip version *; however, version * is available. (glob) (?) You should consider upgrading via the '$TESTTMP/installenv/bin/python* -m pip install --upgrade pip' command. (glob) (?) $ ./installenv/*/hg debuginstall || cat pip.log checking encoding (ascii)... checking Python executable (*) (glob) checking Python implementation (*) (glob) checking Python version (3.*) (glob) checking Python lib (*)... (glob) checking Python security support (*) (glob) checking Rust extensions \((installed|missing)\) (re) checking Mercurial version (*) (glob) checking Mercurial custom build (*) (glob) checking module policy (*) (glob) checking installed modules (*/mercurial)... (glob) checking registered compression engines (*) (glob) checking available compression engines (*) (glob) checking available compression engines for wire protocol (*) (glob) checking "re2" regexp engine \((available|missing)\) (re) checking templates ($TESTTMP/installenv/*/site-packages/mercurial/templates)... (glob) checking default template ($TESTTMP/installenv/*/site-packages/mercurial/templates/map-cmdline.default) (glob) checking commit editor... (*) (glob) checking username (test) no problems detected #endif #if virtualenv no-py3 network-io Note: --no-site-packages is the default for all versions enabled by hghave $ "$PYTHON" -m virtualenv installenv >> pip.log DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. (?) DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support (?) Note: we use this weird path to run pip and hg to avoid platform differences, since it's bin on most platforms but Scripts on Windows. $ ./installenv/*/pip install $TESTDIR/.. >> pip.log DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. (?) DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support (?) DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality. (?) $ ./installenv/*/hg debuginstall || cat pip.log checking encoding (ascii)... checking Python executable (*) (glob) checking Python implementation (*) (glob) checking Python version (2.*) (glob) checking Python lib (*)... (glob) checking Python security support (*) (glob) TLS 1.2 not supported by Python install; network connections lack modern security (?) SNI not supported by Python install; may have connectivity issues with some servers (?) checking Rust extensions \((installed|missing)\) (re) checking Mercurial version (*) (glob) checking Mercurial custom build (*) (glob) checking module policy (*) (glob) checking installed modules (*/mercurial)... (glob) checking registered compression engines (*) (glob) checking available compression engines (*) (glob) checking available compression engines for wire protocol (*) (glob) checking "re2" regexp engine \((available|missing)\) (re) checking templates ($TESTTMP/installenv/*/site-packages/mercurial/templates)... (glob) checking default template ($TESTTMP/installenv/*/site-packages/mercurial/templates/map-cmdline.default) (glob) checking commit editor... (*) (glob) checking username (test) no problems detected #endif