setdiscovery: randomly pick between heads and sample when taking full sample
authorPierre-Yves David <pierre-yves.david@fb.com>
Wed, 07 Jan 2015 12:09:51 -0800
changeset 23810 b681d3a2bf04
parent 23809 9ca2eb881b53
child 23811 e2b262e2ee73
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.
mercurial/setdiscovery.py
tests/test-setdiscovery.t
--- 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