Mercurial > hg
annotate tests/test-custom-filters.t @ 47802:de2e04fe4897
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
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Tue, 20 Jul 2021 17:20:19 +0200 |
parents | ee9981bc8b44 |
children | 55c6ebd11cb9 |
rev | line source |
---|---|
12124
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
1 $ hg init |
6066
f3a8b5360100
Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff
changeset
|
2 |
12124
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
3 $ cat > .hg/hgrc <<EOF |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
4 > [extensions] |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
5 > prefixfilter = prefix.py |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
6 > [encode] |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
7 > *.txt = stripprefix: Copyright 2046, The Masters |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
8 > [decode] |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
9 > *.txt = insertprefix: Copyright 2046, The Masters |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
10 > EOF |
6066
f3a8b5360100
Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff
changeset
|
11 |
12124
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
12 $ cat > prefix.py <<EOF |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
12316
diff
changeset
|
13 > from mercurial import error |
12124
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
14 > def stripprefix(s, cmd, filename, **kwargs): |
38071
6e713711331b
py3: add b'' prefixes in tests/test-custom-filters.t
Pulkit Goyal <7895pulkit@gmail.com>
parents:
26587
diff
changeset
|
15 > header = b'%s\n' % cmd |
12124
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
16 > if s[:len(header)] != header: |
38071
6e713711331b
py3: add b'' prefixes in tests/test-custom-filters.t
Pulkit Goyal <7895pulkit@gmail.com>
parents:
26587
diff
changeset
|
17 > raise error.Abort(b'missing header "%s" in %s' % (cmd, filename)) |
12124
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
18 > return s[len(header):] |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
19 > def insertprefix(s, cmd): |
38071
6e713711331b
py3: add b'' prefixes in tests/test-custom-filters.t
Pulkit Goyal <7895pulkit@gmail.com>
parents:
26587
diff
changeset
|
20 > return b'%s\n%s' % (cmd, s) |
12124
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
21 > def reposetup(ui, repo): |
38071
6e713711331b
py3: add b'' prefixes in tests/test-custom-filters.t
Pulkit Goyal <7895pulkit@gmail.com>
parents:
26587
diff
changeset
|
22 > repo.adddatafilter(b'stripprefix:', stripprefix) |
6e713711331b
py3: add b'' prefixes in tests/test-custom-filters.t
Pulkit Goyal <7895pulkit@gmail.com>
parents:
26587
diff
changeset
|
23 > repo.adddatafilter(b'insertprefix:', insertprefix) |
12124
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
24 > EOF |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
25 |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
26 $ cat > .hgignore <<EOF |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
27 > .hgignore |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
28 > prefix.py |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
29 > prefix.pyc |
40609
ee9981bc8b44
py3: add __pycache__ to .hgignore
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
38071
diff
changeset
|
30 > __pycache__/ |
12124
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
31 > EOF |
6066
f3a8b5360100
Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff
changeset
|
32 |
12124
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
33 $ cat > stuff.txt <<EOF |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
34 > Copyright 2046, The Masters |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
35 > Some stuff to ponder very carefully. |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
36 > EOF |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
37 $ hg add stuff.txt |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
38 $ hg ci -m stuff |
6066
f3a8b5360100
Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff
changeset
|
39 |
12124
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
40 Repository data: |
6066
f3a8b5360100
Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff
changeset
|
41 |
12124
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
42 $ hg cat stuff.txt |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
43 Some stuff to ponder very carefully. |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
44 |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
45 Fresh checkout: |
6066
f3a8b5360100
Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff
changeset
|
46 |
12124
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
47 $ rm stuff.txt |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
48 $ hg up -C |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
49 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
50 $ cat stuff.txt |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
51 Copyright 2046, The Masters |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
52 Some stuff to ponder very carefully. |
12125
e5ccb9ea8266
test-custom-filter: heredoc is not required for single line operations
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12124
diff
changeset
|
53 $ echo "Very very carefully." >> stuff.txt |
12124
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
54 $ hg stat |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
55 M stuff.txt |
6066
f3a8b5360100
Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff
changeset
|
56 |
12125
e5ccb9ea8266
test-custom-filter: heredoc is not required for single line operations
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12124
diff
changeset
|
57 $ echo "Unauthorized material subject to destruction." > morestuff.txt |
12124
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
58 |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
59 Problem encoding: |
6066
f3a8b5360100
Strip filter name from command before passing to filter function.
Jesse Glick <jesse.glick@sun.com>
parents:
diff
changeset
|
60 |
12124
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
61 $ hg add morestuff.txt |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
62 $ hg ci -m morestuff |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
63 abort: missing header "Copyright 2046, The Masters" in morestuff.txt |
12316
4134686b83e1
tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents:
12125
diff
changeset
|
64 [255] |
12124
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
65 $ hg stat |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
66 M stuff.txt |
7edda6c7985d
tests: unify test-custom-filters
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8742
diff
changeset
|
67 A morestuff.txt |