hgwebdir: avoid systematic full garbage collection
Forcing a systematic full garbage collection upon each request
can serioulsy harm performance. This is reported as
https://bz.mercurial-scm.org/show_bug.cgi?id=6075
With this change we're performing the full collection according
to a new setting, `experimental.web.full-garbage-collection-rate`.
The default value is 1, which doesn't change the behavior and will
allow us to test on real use cases. If the value is 0, no full garbage
collection occurs.
Regardless of the value of the setting, a partial garbage collection
still occurs upon each request (not attempting to collect objects from
the oldest generation). This should be enough to take care of
reference cycles that have been created by the last request
(assessment of this requires changing the setting, not to be 1).
In my experience chasing memory leaks in Mercurial servers,
the full collection never reclaimed any memory, but this is with
Python 3 and biased towards small repositories.
On the other hand, as explained in the Python developer docs [1],
frequent full collections are very harmful in terms of performance if
lots of objects survive the collection, and hence stay in the
oldest generation. Note that `gc.collect()` is indeed trying to
collect the oldest generation [2]. This happens usually in two cases:
- unwanted lingering objects (i.e., an actual memory leak that
the GC cannot do anything about). Sadly, we have lots of those
these days.
- desireable long-term objects, typically in caches (not inner caches
carried by repositories, which should be collected with them). This
is a subject of interest for the Heptapod project.
In short, the flat rate that this change still permits is
probably a bad idea in most cases, and the default value can
be tweaked later on (or even be set to 0) according to experiments
in the wild.
The test is inspired from test-hgwebdir-paths.py
[1] https://devguide.python.org/garbage_collector/#collecting-the-oldest-generation
[2] https://docs.python.org/3/library/gc.html#gc.collect
Differential Revision: https://phab.mercurial-scm.org/D11204
==========================================================
Test file dedicated to checking side-data related behavior
==========================================================
Check data can be written/read from sidedata
============================================
$ cat << EOF >> $HGRCPATH
> [extensions]
> testsidedata=$TESTDIR/testlib/ext-sidedata.py
> EOF
$ hg init test-sidedata --config experimental.revlogv2=enable-unstable-format-and-corrupt-my-data
$ cd test-sidedata
$ echo aaa > a
$ hg add a
$ hg commit -m a --traceback
$ echo aaa > b
$ hg add b
$ hg commit -m b
$ echo xxx >> a
$ hg commit -m aa
$ hg debugsidedata -c 0
2 sidedata entries
entry-0001 size 4
entry-0002 size 32
$ hg debugsidedata -c 1 -v
2 sidedata entries
entry-0001 size 4
'\x00\x00\x006'
entry-0002 size 32
'\x98\t\xf9\xc4v\xf0\xc5P\x90\xf7wRf\xe8\xe27e\xfc\xc1\x93\xa4\x96\xd0\x1d\x97\xaaG\x1d\xd7t\xfa\xde'
$ hg debugsidedata -m 2
2 sidedata entries
entry-0001 size 4
entry-0002 size 32
$ hg debugsidedata a 1
2 sidedata entries
entry-0001 size 4
entry-0002 size 32
Check upgrade behavior
======================
Right now, sidedata has not upgrade support
Check that we can upgrade to sidedata
-------------------------------------
$ hg init up-no-side-data --config experimental.revlogv2=no
$ hg debugformat -v -R up-no-side-data
format-variant repo config default
fncache: yes yes yes
dirstate-v2: no no no
dotencode: yes yes yes
generaldelta: yes yes yes
share-safe: no no no
sparserevlog: yes yes yes
persistent-nodemap: no no no (no-rust !)
persistent-nodemap: yes yes no (rust !)
copies-sdc: no no no
revlog-v2: no no no
changelog-v2: no no no
plain-cl-delta: yes yes yes
compression: zlib zlib zlib (no-zstd !)
compression: zstd zstd zstd (zstd !)
compression-level: default default default
$ hg debugformat -v -R up-no-side-data --config experimental.revlogv2=enable-unstable-format-and-corrupt-my-data
format-variant repo config default
fncache: yes yes yes
dirstate-v2: no no no
dotencode: yes yes yes
generaldelta: yes yes yes
share-safe: no no no
sparserevlog: yes yes yes
persistent-nodemap: no no no (no-rust !)
persistent-nodemap: yes yes no (rust !)
copies-sdc: no no no
revlog-v2: no yes no
changelog-v2: no no no
plain-cl-delta: yes yes yes
compression: zlib zlib zlib (no-zstd !)
compression: zstd zstd zstd (zstd !)
compression-level: default default default
$ hg debugupgraderepo -R up-no-side-data --config experimental.revlogv2=enable-unstable-format-and-corrupt-my-data > /dev/null
Check that we can downgrade from sidedata
-----------------------------------------
$ hg init up-side-data --config experimental.revlogv2=enable-unstable-format-and-corrupt-my-data
$ hg debugformat -v -R up-side-data
format-variant repo config default
fncache: yes yes yes
dirstate-v2: no no no
dotencode: yes yes yes
generaldelta: yes yes yes
share-safe: no no no
sparserevlog: yes yes yes
persistent-nodemap: no no no (no-rust !)
persistent-nodemap: yes yes no (rust !)
copies-sdc: no no no
revlog-v2: yes no no
changelog-v2: no no no
plain-cl-delta: yes yes yes
compression: zlib zlib zlib (no-zstd !)
compression: zstd zstd zstd (zstd !)
compression-level: default default default
$ hg debugformat -v -R up-side-data --config experimental.revlogv2=no
format-variant repo config default
fncache: yes yes yes
dirstate-v2: no no no
dotencode: yes yes yes
generaldelta: yes yes yes
share-safe: no no no
sparserevlog: yes yes yes
persistent-nodemap: no no no (no-rust !)
persistent-nodemap: yes yes no (rust !)
copies-sdc: no no no
revlog-v2: yes no no
changelog-v2: no no no
plain-cl-delta: yes yes yes
compression: zlib zlib zlib (no-zstd !)
compression: zstd zstd zstd (zstd !)
compression-level: default default default
$ hg debugupgraderepo -R up-side-data --config experimental.revlogv2=no > /dev/null