Mercurial > hg
view tests/test-chg.t @ 44363:f7459da77f23
nodemap: introduce an option to use mmap to read the nodemap mapping
The performance and memory benefit is much greater if we don't have to copy all
the data in memory for each information. So we introduce an option (on by
default) to read the data using mmap.
This changeset is the last one definition the API for index support nodemap
data. (they have to be able to use the mmaping).
Below are some benchmark comparing the best we currently have in 5.3 with the
final step of this series (using the persistent nodemap implementation in
Rust). The benchmark run `hg perfindex` with various revset and the following
variants:
Before:
* do not use the persistent nodemap
* use the CPython implementation of the index for nodemap
* use mmapping of the changelog index
After:
* use the MixedIndex Rust code, with the NodeTree object for nodemap access
(still in review)
* use the persistent nodemap data from disk
* access the persistent nodemap data through mmap
* use mmapping of the changelog index
The persistent nodemap greatly speed up most operation on very large
repositories. Some of the previously very fast lookup end up a bit slower because
the persistent nodemap has to be setup. However the absolute slowdown is very
small and won't matters in the big picture.
Here are some numbers (in seconds) for the reference copy of mozilla-try:
Revset Before After abs-change speedup
-10000: 0.004622 0.005532 0.000910 × 0.83
-10: 0.000050 0.000132 0.000082 × 0.37
tip 0.000052 0.000085 0.000033 × 0.61
0 + (-10000:) 0.028222 0.005337 -0.022885 × 5.29
0 0.023521 0.000084 -0.023437 × 280.01
(-10000:) + 0 0.235539 0.005308 -0.230231 × 44.37
(-10:) + :9 0.232883 0.000180 -0.232703 ×1293.79
(-10000:) + (:99) 0.238735 0.005358 -0.233377 × 44.55
:99 + (-10000:) 0.317942 0.005593 -0.312349 × 56.84
:9 + (-10:) 0.313372 0.000179 -0.313193 ×1750.68
:9 0.316450 0.000143 -0.316307 ×2212.93
On smaller repositories, the cost of nodemap related operation is not as big, so
the win is much more modest. Yet it helps shaving a handful of millisecond here
and there.
Here are some numbers (in seconds) for the reference copy of mercurial:
Revset Before After abs-change speedup
-10: 0.000065 0.000097 0.000032 × 0.67
tip 0.000063 0.000078 0.000015 × 0.80
0 0.000561 0.000079 -0.000482 × 7.10
-10000: 0.004609 0.003648 -0.000961 × 1.26
0 + (-10000:) 0.005023 0.003715 -0.001307 × 1.35
(-10:) + :9 0.002187 0.000108 -0.002079 ×20.25
(-10000:) + 0 0.006252 0.003716 -0.002536 × 1.68
(-10000:) + (:99) 0.006367 0.003707 -0.002660 × 1.71
:9 + (-10:) 0.003846 0.000110 -0.003736 ×34.96
:9 0.003854 0.000099 -0.003755 ×38.92
:99 + (-10000:) 0.007644 0.003778 -0.003866 × 2.02
Differential Revision: https://phab.mercurial-scm.org/D7894
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 11 Feb 2020 11:18:52 +0100 |
parents | a69c08cdb2a8 |
children | 62bdb288c449 |
line wrap: on
line source
#require chg $ mkdir log $ cp $HGRCPATH $HGRCPATH.unconfigured $ cat <<'EOF' >> $HGRCPATH > [cmdserver] > log = $TESTTMP/log/server.log > max-log-files = 1 > max-log-size = 10 kB > EOF $ cp $HGRCPATH $HGRCPATH.orig $ filterlog () { > sed -e 's!^[0-9/]* [0-9:]* ([0-9]*)>!YYYY/MM/DD HH:MM:SS (PID)>!' \ > -e 's!\(setprocname\|received fds\|setenv\): .*!\1: ...!' \ > -e 's!\(confighash\|mtimehash\) = [0-9a-f]*!\1 = ...!g' \ > -e 's!\(in \)[0-9.]*s\b!\1 ...s!g' \ > -e 's!\(pid\)=[0-9]*!\1=...!g' \ > -e 's!\(/server-\)[0-9a-f]*!\1...!g' > } init repo $ chg init foo $ cd foo ill-formed config $ chg status $ echo '=brokenconfig' >> $HGRCPATH $ chg status hg: parse error at * (glob) [255] $ cp $HGRCPATH.orig $HGRCPATH long socket path $ sockpath=$TESTTMP/this/path/should/be/longer/than/one-hundred-and-seven/characters/where/107/is/the/typical/size/limit/of/unix-domain-socket $ mkdir -p $sockpath $ bakchgsockname=$CHGSOCKNAME $ CHGSOCKNAME=$sockpath/server $ export CHGSOCKNAME $ chg root $TESTTMP/foo $ rm -rf $sockpath $ CHGSOCKNAME=$bakchgsockname $ export CHGSOCKNAME $ cd .. editor ------ $ cat >> pushbuffer.py <<EOF > def reposetup(ui, repo): > repo.ui.pushbuffer(subproc=True) > EOF $ chg init editor $ cd editor by default, system() should be redirected to the client: $ touch foo $ CHGDEBUG= HGEDITOR=cat chg ci -Am channeled --edit 2>&1 \ > | egrep "HG:|run 'cat" chg: debug: * run 'cat "*"' at '$TESTTMP/editor' (glob) HG: Enter commit message. Lines beginning with 'HG:' are removed. HG: Leave message empty to abort commit. HG: -- HG: user: test HG: branch 'default' HG: added foo but no redirection should be made if output is captured: $ touch bar $ CHGDEBUG= HGEDITOR=cat chg ci -Am bufferred --edit \ > --config extensions.pushbuffer="$TESTTMP/pushbuffer.py" 2>&1 \ > | egrep "HG:|run 'cat" [1] check that commit commands succeeded: $ hg log -T '{rev}:{desc}\n' 1:bufferred 0:channeled $ cd .. pager ----- $ cat >> fakepager.py <<EOF > import sys > for line in sys.stdin: > sys.stdout.write('paged! %r\n' % line) > EOF enable pager extension globally, but spawns the master server with no tty: $ chg init pager $ cd pager $ cat >> $HGRCPATH <<EOF > [extensions] > pager = > [pager] > pager = "$PYTHON" $TESTTMP/fakepager.py > EOF $ chg version > /dev/null $ touch foo $ chg ci -qAm foo pager should be enabled if the attached client has a tty: $ chg log -l1 -q --config ui.formatted=True paged! '0:1f7b0de80e11\n' $ chg log -l1 -q --config ui.formatted=False 0:1f7b0de80e11 chg waits for pager if runcommand raises $ cat > $TESTTMP/crash.py <<EOF > from mercurial import registrar > cmdtable = {} > command = registrar.command(cmdtable) > @command(b'crash') > def pagercrash(ui, repo, *pats, **opts): > ui.write(b'going to crash\n') > raise Exception('.') > EOF $ cat > $TESTTMP/fakepager.py <<EOF > from __future__ import absolute_import > import sys > import time > for line in iter(sys.stdin.readline, ''): > if 'crash' in line: # only interested in lines containing 'crash' > # if chg exits when pager is sleeping (incorrectly), the output > # will be captured by the next test case > time.sleep(1) > sys.stdout.write('crash-pager: %s' % line) > EOF $ cat >> .hg/hgrc <<EOF > [extensions] > crash = $TESTTMP/crash.py > EOF $ chg crash --pager=on --config ui.formatted=True 2>/dev/null crash-pager: going to crash [255] $ cd .. server lifecycle ---------------- chg server should be restarted on code change, and old server will shut down automatically. In this test, we use the following time parameters: - "sleep 1" to make mtime different - "sleep 2" to notice mtime change (polling interval is 1 sec) set up repository with an extension: $ chg init extreload $ cd extreload $ touch dummyext.py $ cat <<EOF >> .hg/hgrc > [extensions] > dummyext = dummyext.py > EOF isolate socket directory for stable result: $ OLDCHGSOCKNAME=$CHGSOCKNAME $ mkdir chgsock $ CHGSOCKNAME=`pwd`/chgsock/server warm up server: $ CHGDEBUG= chg log 2>&1 | egrep 'instruction|start' chg: debug: * start cmdserver at $TESTTMP/extreload/chgsock/server.* (glob) new server should be started if extension modified: $ sleep 1 $ touch dummyext.py $ CHGDEBUG= chg log 2>&1 | egrep 'instruction|start' chg: debug: * instruction: unlink $TESTTMP/extreload/chgsock/server-* (glob) chg: debug: * instruction: reconnect (glob) chg: debug: * start cmdserver at $TESTTMP/extreload/chgsock/server.* (glob) old server will shut down, while new server should still be reachable: $ sleep 2 $ CHGDEBUG= chg log 2>&1 | (egrep 'instruction|start' || true) socket file should never be unlinked by old server: (simulates unowned socket by updating mtime, which makes sure server exits at polling cycle) $ ls chgsock/server-* chgsock/server-* (glob) $ touch chgsock/server-* $ sleep 2 $ ls chgsock/server-* chgsock/server-* (glob) since no server is reachable from socket file, new server should be started: (this test makes sure that old server shut down automatically) $ CHGDEBUG= chg log 2>&1 | egrep 'instruction|start' chg: debug: * start cmdserver at $TESTTMP/extreload/chgsock/server.* (glob) shut down servers and restore environment: $ rm -R chgsock $ sleep 2 $ CHGSOCKNAME=$OLDCHGSOCKNAME $ cd .. check that server events are recorded: $ ls log server.log server.log.1 print only the last 10 lines, since we aren't sure how many records are preserved (since setprocname isn't available on py3, the 10th-most-recent line is different when using py3): $ cat log/server.log.1 log/server.log | tail -10 | filterlog YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ... (py3 !) YYYY/MM/DD HH:MM:SS (PID)> forked worker process (pid=...) YYYY/MM/DD HH:MM:SS (PID)> setprocname: ... (no-py3 !) YYYY/MM/DD HH:MM:SS (PID)> received fds: ... YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/extreload' YYYY/MM/DD HH:MM:SS (PID)> setumask 18 YYYY/MM/DD HH:MM:SS (PID)> setenv: ... YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ... YYYY/MM/DD HH:MM:SS (PID)> validate: [] YYYY/MM/DD HH:MM:SS (PID)> worker process exited (pid=...) YYYY/MM/DD HH:MM:SS (PID)> $TESTTMP/extreload/chgsock/server-... is not owned, exiting. global data mutated by schems ----------------------------- $ hg init schemes $ cd schemes initial state $ cat > .hg/hgrc <<'EOF' > [extensions] > schemes = > [schemes] > foo = https://foo.example.org/ > EOF $ hg debugexpandscheme foo://expanded https://foo.example.org/expanded $ hg debugexpandscheme bar://unexpanded bar://unexpanded add bar $ cat > .hg/hgrc <<'EOF' > [extensions] > schemes = > [schemes] > foo = https://foo.example.org/ > bar = https://bar.example.org/ > EOF $ hg debugexpandscheme foo://expanded https://foo.example.org/expanded $ hg debugexpandscheme bar://expanded https://bar.example.org/expanded remove foo $ cat > .hg/hgrc <<'EOF' > [extensions] > schemes = > [schemes] > bar = https://bar.example.org/ > EOF $ hg debugexpandscheme foo://unexpanded foo://unexpanded $ hg debugexpandscheme bar://expanded https://bar.example.org/expanded $ cd .. repository cache ---------------- $ rm log/server.log* $ cp $HGRCPATH.unconfigured $HGRCPATH $ cat <<'EOF' >> $HGRCPATH > [cmdserver] > log = $TESTTMP/log/server.log > max-repo-cache = 1 > track-log = command, repocache > EOF isolate socket directory for stable result: $ OLDCHGSOCKNAME=$CHGSOCKNAME $ mkdir chgsock $ CHGSOCKNAME=`pwd`/chgsock/server create empty repo and cache it: $ hg init cached $ hg id -R cached 000000000000 tip $ sleep 1 modify repo (and cache will be invalidated): $ touch cached/a $ hg ci -R cached -Am 'add a' adding a $ sleep 1 read cached repo: $ hg log -R cached changeset: 0:ac82d8b1f7c4 tag: tip user: test date: Thu Jan 01 00:00:00 1970 +0000 summary: add a $ sleep 1 discard cached from LRU cache: $ hg clone cached cached2 updating to branch default 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg id -R cached2 ac82d8b1f7c4 tip $ sleep 1 read uncached repo: $ hg log -R cached changeset: 0:ac82d8b1f7c4 tag: tip user: test date: Thu Jan 01 00:00:00 1970 +0000 summary: add a $ sleep 1 shut down servers and restore environment: $ rm -R chgsock $ sleep 2 $ CHGSOCKNAME=$OLDCHGSOCKNAME check server log: $ cat log/server.log | filterlog YYYY/MM/DD HH:MM:SS (PID)> worker process exited (pid=...) YYYY/MM/DD HH:MM:SS (PID)> worker process exited (pid=...) YYYY/MM/DD HH:MM:SS (PID)> init cached YYYY/MM/DD HH:MM:SS (PID)> id -R cached YYYY/MM/DD HH:MM:SS (PID)> loaded repo into cache: $TESTTMP/cached (in ...s) YYYY/MM/DD HH:MM:SS (PID)> repo from cache: $TESTTMP/cached YYYY/MM/DD HH:MM:SS (PID)> ci -R cached -Am 'add a' YYYY/MM/DD HH:MM:SS (PID)> loaded repo into cache: $TESTTMP/cached (in ...s) YYYY/MM/DD HH:MM:SS (PID)> repo from cache: $TESTTMP/cached YYYY/MM/DD HH:MM:SS (PID)> log -R cached YYYY/MM/DD HH:MM:SS (PID)> loaded repo into cache: $TESTTMP/cached (in ...s) YYYY/MM/DD HH:MM:SS (PID)> clone cached cached2 YYYY/MM/DD HH:MM:SS (PID)> id -R cached2 YYYY/MM/DD HH:MM:SS (PID)> loaded repo into cache: $TESTTMP/cached2 (in ...s) YYYY/MM/DD HH:MM:SS (PID)> log -R cached YYYY/MM/DD HH:MM:SS (PID)> loaded repo into cache: $TESTTMP/cached (in ...s) Test that chg works (sets to the user's actual LC_CTYPE) even when python "coerces" the locale (py3.7+) $ cat > $TESTTMP/debugenv.py <<EOF > from mercurial import encoding > from mercurial import registrar > cmdtable = {} > command = registrar.command(cmdtable) > @command(b'debugenv', [], b'', norepo=True) > def debugenv(ui): > for k in [b'LC_ALL', b'LC_CTYPE', b'LANG']: > v = encoding.environ.get(k) > if v is not None: > ui.write(b'%s=%s\n' % (k, encoding.environ[k])) > EOF (hg keeps python's modified LC_CTYPE, chg doesn't) $ (unset LC_ALL; unset LANG; LC_CTYPE= "$CHGHG" \ > --config extensions.debugenv=$TESTTMP/debugenv.py debugenv) LC_CTYPE=C.UTF-8 (py37 !) LC_CTYPE= (no-py37 !) $ (unset LC_ALL; unset LANG; LC_CTYPE= chg \ > --config extensions.debugenv=$TESTTMP/debugenv.py debugenv) LC_CTYPE= $ (unset LC_ALL; unset LANG; LC_CTYPE=unsupported_value chg \ > --config extensions.debugenv=$TESTTMP/debugenv.py debugenv) LC_CTYPE=unsupported_value $ (unset LC_ALL; unset LANG; LC_CTYPE= chg \ > --config extensions.debugenv=$TESTTMP/debugenv.py debugenv) LC_CTYPE= $ LANG= LC_ALL= LC_CTYPE= chg \ > --config extensions.debugenv=$TESTTMP/debugenv.py debugenv LC_ALL= LC_CTYPE= LANG=