setdiscovery: randomly pick between heads and sample when taking full sample
Before this changeset, the discovery protocol was too heads-centric. Heads of the
undiscovered set were always sent for discovery and any room remaining in the
sample were filled with exponential samples (and random ones if any room
remained).
This behaved extremely poorly when the number of heads exceeded the sample size,
because we keep just asking about the existence of heads, then their direct parent
and so on. As a result, the 'O(log(len(repo)))' discovery turns into a
'O(len(repo))' one. As a solution we take a random sample of the heads plus
exponential samples. This way we ensure some exponential sampling is achieved,
bringing back some logarithmic convergence of the discovery again.
This patch only applies this principle in one place. More places will be updated
in future patches.
One test is impacted because the random sample happen to be different. By
chance, it helps a bit in this case.
--- a/mercurial/setdiscovery.py Tue Jan 06 17:02:32 2015 -0800
+++ b/mercurial/setdiscovery.py Wed Jan 07 12:09:51 2015 -0800
@@ -113,11 +113,11 @@
# update from roots
_updatesample(dag.inverse(), nodes, sample, always)
assert sample
- sample = _limitsample(sample, desiredlen)
- if len(sample) < desiredlen:
- more = desiredlen - len(sample)
- sample.update(random.sample(list(nodes - sample - always), more))
sample.update(always)
+ sample = _limitsample(sample, size)
+ if len(sample) < size:
+ more = size - len(sample)
+ sample.update(random.sample(list(nodes - sample), more))
return sample
def _limitsample(sample, desiredlen):
--- a/tests/test-setdiscovery.t Tue Jan 06 17:02:32 2015 -0800
+++ b/tests/test-setdiscovery.t Wed Jan 07 12:09:51 2015 -0800
@@ -326,7 +326,7 @@
query 6; still undecided: 540, sample size is: 200
sampling from both directions
searching: 7 queries
- query 7; still undecided: 44, sample size is: 44
+ query 7; still undecided: 37, sample size is: 37
7 total queries
common heads: 3ee37d65064a