annotate tests/test-revlog-ancestry.py @ 30764:e75463e3179f

protocol: send application/mercurial-0.2 responses to capable clients With this commit, the HTTP transport now parses the X-HgProto-<N> header to determine what media type and compression engine to use for responses. So far, we only compress responses that are already being compressed with zlib today (stream response types to specific commands). We can expand things to cover additional response types later. The practical side-effect of this commit is that non-zlib compression engines will be used if both ends support them. This means if both ends have zstd support, zstd - not zlib - will be used to compress data! When cloning the mozilla-unified repository between a local HTTP server and client, the benefits of non-zlib compression are quite noticeable: engine server CPU (s) client CPU (s) bundle size zlib (l=6) 174.1 283.2 1,148,547,026 zstd (l=1) 99.2 267.3 1,127,513,841 zstd (l=3) 103.1 266.9 1,018,861,363 zstd (l=7) 128.3 269.7 919,190,278 zstd (l=10) 162.0 - 894,547,179 none 95.3 277.2 4,097,566,064 The default zstd compression level is 3. So if you deploy zstd capable Mercurial to your clients and servers and CPU time on your server is dominated by "getbundle" requests (clients cloning and pulling) - and my experience at Mozilla tells me this is often the case - this commit could drastically reduce your server-side CPU usage *and* save on bandwidth costs! Another benefit of this change is that server operators can install *any* compression engine. While it isn't enabled by default, the "none" compression engine can now be used to disable wire protocol compression completely. Previously, commands like "getbundle" always zlib compressed output, adding considerable overhead to generating responses. If you are on a high speed network and your server is under high load, it might be advantageous to trade bandwidth for CPU. Although, zstd at level 1 doesn't use that much CPU, so I'm not convinced that disabling compression wholesale is worthwhile. And, my data seems to indicate a slow down on the client without compression. I suspect this is due to a lack of buffering resulting in an increase in socket read() calls and/or the fact we're transferring an extra 3 GB of data (parsing HTTP chunked transfer and processing extra TCP packets can add up). This is definitely worth investigating and optimizing. But since the "none" compressor isn't enabled by default, I'm inclined to punt on this issue. This commit introduces tons of tests. Some of these should arguably have been implemented on previous commits. But it was difficult to test without the server functionality in place.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 24 Dec 2016 15:29:32 -0700
parents d83ca854fa21
children 14d2371216ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
1 from __future__ import absolute_import, print_function
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
2 import os
28763
abe605bbf0de py3: use absolute_import in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 27344
diff changeset
3 from mercurial import (
abe605bbf0de py3: use absolute_import in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 27344
diff changeset
4 hg,
abe605bbf0de py3: use absolute_import in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 27344
diff changeset
5 merge,
28842
d466facc5a6e tests: alias ui as uimod in test-revlog-ancestry/test-ui-verbosity
Yuya Nishihara <yuya@tcha.org>
parents: 28764
diff changeset
6 ui as uimod,
28763
abe605bbf0de py3: use absolute_import in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 27344
diff changeset
7 )
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
8
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 28842
diff changeset
9 u = uimod.ui.load()
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
10
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
11 repo = hg.repository(u, 'test1', create=1)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
12 os.chdir('test1')
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
13
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
14 def commit(text, time):
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
15 repo.commit(text=text, date="%d 0" % time)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
16
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
17 def addcommit(name, time):
9031
3b76321aa0de compat: use open() instead of file() everywhere
Alejandro Santos <alejolp@alejolp.com>
parents: 8656
diff changeset
18 f = open(name, 'w')
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
19 f.write('%s\n' % name)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
20 f.close()
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9031
diff changeset
21 repo[None].add([name])
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
22 commit(name, time)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
23
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
24 def update(rev):
27344
43c00ca887d1 merge: have merge.update use a matcher instead of partial fn
Augie Fackler <augie@google.com>
parents: 18081
diff changeset
25 merge.update(repo, rev, False, True)
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
26
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
27 def merge_(rev):
27344
43c00ca887d1 merge: have merge.update use a matcher instead of partial fn
Augie Fackler <augie@google.com>
parents: 18081
diff changeset
28 merge.update(repo, rev, True, False)
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
29
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
30 if __name__ == '__main__':
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
31 addcommit("A", 0)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
32 addcommit("B", 1)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
33
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
34 update(0)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
35 addcommit("C", 2)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
36
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
37 merge_(1)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
38 commit("D", 3)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
39
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
40 update(2)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
41 addcommit("E", 4)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
42 addcommit("F", 5)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
43
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
44 update(3)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
45 addcommit("G", 6)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
46
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
47 merge_(5)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
48 commit("H", 7)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
49
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
50 update(5)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
51 addcommit("I", 8)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
52
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
53 # Ancestors
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
54 print('Ancestors of 5')
16866
91f3ac205816 revlog: ancestors(*revs) becomes ancestors(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 11303
diff changeset
55 for r in repo.changelog.ancestors([5]):
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
56 print(r, end=' ')
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
57
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
58 print('\nAncestors of 6 and 5')
16866
91f3ac205816 revlog: ancestors(*revs) becomes ancestors(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 11303
diff changeset
59 for r in repo.changelog.ancestors([6, 5]):
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
60 print(r, end=' ')
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
61
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
62 print('\nAncestors of 5 and 4')
16866
91f3ac205816 revlog: ancestors(*revs) becomes ancestors(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 11303
diff changeset
63 for r in repo.changelog.ancestors([5, 4]):
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
64 print(r, end=' ')
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
65
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
66 print('\nAncestors of 7, stop at 6')
16868
eb88ed4269c5 revlog: add optional stoprev arg to revlog.ancestors()
Joshua Redstone <joshua.redstone@fb.com>
parents: 16867
diff changeset
67 for r in repo.changelog.ancestors([7], 6):
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
68 print(r, end=' ')
16868
eb88ed4269c5 revlog: add optional stoprev arg to revlog.ancestors()
Joshua Redstone <joshua.redstone@fb.com>
parents: 16867
diff changeset
69
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
70 print('\nAncestors of 7, including revs')
18081
f88c60e740a1 revlog.ancestors: add support for including revs
Siddharth Agarwal <sid0@fb.com>
parents: 16868
diff changeset
71 for r in repo.changelog.ancestors([7], inclusive=True):
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
72 print(r, end=' ')
18081
f88c60e740a1 revlog.ancestors: add support for including revs
Siddharth Agarwal <sid0@fb.com>
parents: 16868
diff changeset
73
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
74 print('\nAncestors of 7, 5 and 3, including revs')
18081
f88c60e740a1 revlog.ancestors: add support for including revs
Siddharth Agarwal <sid0@fb.com>
parents: 16868
diff changeset
75 for r in repo.changelog.ancestors([7, 5, 3], inclusive=True):
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
76 print(r, end=' ')
18081
f88c60e740a1 revlog.ancestors: add support for including revs
Siddharth Agarwal <sid0@fb.com>
parents: 16868
diff changeset
77
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
78 # Descendants
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
79 print('\n\nDescendants of 5')
16867
1093ad1e8903 revlog: descendants(*revs) becomes descendants(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 16866
diff changeset
80 for r in repo.changelog.descendants([5]):
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
81 print(r, end=' ')
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
82
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
83 print('\nDescendants of 5 and 3')
16867
1093ad1e8903 revlog: descendants(*revs) becomes descendants(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 16866
diff changeset
84 for r in repo.changelog.descendants([5, 3]):
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
85 print(r, end=' ')
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
86
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
87 print('\nDescendants of 5 and 4')
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
88 print(*repo.changelog.descendants([5, 4]), sep=' ')