Patchwork D12398: discovery: also audit the number of queries done

login
register
mail settings
Submitter phabricator
Date March 22, 2022, 7:06 a.m.
Message ID <differential-rev-PHID-DREV-u64xdvopl6sflg4lhnzv-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50743/
State New
Headers show

Comments

phabricator - March 22, 2022, 7:06 a.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  In addition to the number of roundtrip, we now also track the number of queries
  we perform, this is useful to assert the tradeoff between number of roundtrip and
  the number of queries.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12398

AFFECTED FILES
  mercurial/debugcommands.py
  mercurial/setdiscovery.py
  mercurial/treediscovery.py
  tests/test-setdiscovery.t

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-setdiscovery.t b/tests/test-setdiscovery.t
--- a/tests/test-setdiscovery.t
+++ b/tests/test-setdiscovery.t
@@ -45,6 +45,7 @@ 
   unpruned common: 01241442b3c2 66f7d451a68b b5714e113bc0
   elapsed time:  * seconds (glob)
   round-trips:                   2
+  queries:                       6
   heads summary:
     total common heads:          2
       also local heads:          2
@@ -77,6 +78,7 @@ 
   all local changesets known remotely
   elapsed time:  * seconds (glob)
   round-trips:                   1
+  queries:                       2
   heads summary:
     total common heads:          2
       also local heads:          2
@@ -109,6 +111,7 @@ 
   all local changesets known remotely
   elapsed time:  * seconds (glob)
   round-trips:                   1
+  queries:                       1
   heads summary:
     total common heads:          1
       also local heads:          1
@@ -140,6 +143,7 @@ 
   unpruned common: 01241442b3c2 b5714e113bc0
   elapsed time:  * seconds (glob)
   round-trips:                   1
+  queries:                       0
   heads summary:
     total common heads:          2
       also local heads:          1
@@ -172,6 +176,7 @@ 
   all remote heads known locally
   elapsed time:  * seconds (glob)
   round-trips:                   1
+  queries:                       3
   heads summary:
     total common heads:          2
       also local heads:          1
@@ -204,6 +209,7 @@ 
   all remote heads known locally
   elapsed time:  * seconds (glob)
   round-trips:                   1
+  queries:                       1
   heads summary:
     total common heads:          2
       also local heads:          1
@@ -242,6 +248,7 @@ 
   unpruned common: bebd167eb94d
   elapsed time:  * seconds (glob)
   round-trips:                   2
+  queries:                       3
   heads summary:
     total common heads:          1
       also local heads:          1
@@ -277,6 +284,7 @@ 
   2 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   2
+  queries:                      31
   heads summary:
     total common heads:          1
       also local heads:          1
@@ -312,6 +320,7 @@ 
   2 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   2
+  queries:                      32
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -343,6 +352,7 @@ 
   unpruned common: 66f7d451a68b bebd167eb94d
   elapsed time:  * seconds (glob)
   round-trips:                   4
+  queries:                       5
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -378,6 +388,7 @@ 
   2 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   2
+  queries:                       3
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -413,6 +424,7 @@ 
   2 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   2
+  queries:                       3
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -450,6 +462,7 @@ 
   unpruned common: 2dc09a01254d
   elapsed time:  * seconds (glob)
   round-trips:                   4
+  queries:                       5
   heads summary:
     total common heads:          1
       also local heads:          1
@@ -485,6 +498,7 @@ 
   2 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   2
+  queries:                      31
   heads summary:
     total common heads:          1
       also local heads:          1
@@ -520,6 +534,7 @@ 
   2 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   2
+  queries:                      32
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -551,6 +566,7 @@ 
   unpruned common: 2dc09a01254d 66f7d451a68b
   elapsed time:  * seconds (glob)
   round-trips:                   4
+  queries:                       5
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -586,6 +602,7 @@ 
   2 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   2
+  queries:                      30
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -621,6 +638,7 @@ 
   2 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   2
+  queries:                      30
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -659,6 +677,7 @@ 
   unpruned common: 66f7d451a68b
   elapsed time:  * seconds (glob)
   round-trips:                   4
+  queries:                       5
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -694,6 +713,7 @@ 
   2 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   2
+  queries:                      32
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -729,6 +749,7 @@ 
   2 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   2
+  queries:                      32
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -760,6 +781,7 @@ 
   unpruned common: 66f7d451a68b
   elapsed time:  * seconds (glob)
   round-trips:                   4
+  queries:                       5
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -795,6 +817,7 @@ 
   2 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   2
+  queries:                      32
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -830,6 +853,7 @@ 
   2 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   2
+  queries:                      32
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -868,6 +892,7 @@ 
   unpruned common: 66f7d451a68b
   elapsed time:  * seconds (glob)
   round-trips:                   4
+  queries:                       5
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -903,6 +928,7 @@ 
   2 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   2
+  queries:                      52
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -938,6 +964,7 @@ 
   2 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   2
+  queries:                      52
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -969,6 +996,7 @@ 
   unpruned common: 66f7d451a68b
   elapsed time:  * seconds (glob)
   round-trips:                   3
+  queries:                       4
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -1004,6 +1032,7 @@ 
   2 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   2
+  queries:                      32
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -1039,6 +1068,7 @@ 
   2 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   2
+  queries:                      32
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -1077,6 +1107,7 @@ 
   unpruned common: 7ead0cba2838
   elapsed time:  * seconds (glob)
   round-trips:                   4
+  queries:                       5
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -1115,6 +1146,7 @@ 
   3 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   3
+  queries:                      43
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -1153,6 +1185,7 @@ 
   3 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   3
+  queries:                      43
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -1184,6 +1217,7 @@ 
   unpruned common: 7ead0cba2838
   elapsed time:  * seconds (glob)
   round-trips:                   3
+  queries:                       4
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -1222,6 +1256,7 @@ 
   3 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   3
+  queries:                      27
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -1260,6 +1295,7 @@ 
   3 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   3
+  queries:                      27
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -1350,6 +1386,7 @@ 
   6 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   6
+  queries:                    1054
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -1387,6 +1424,7 @@ 
   3 total queries in *.????s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   3
+  queries:                      13
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -1436,6 +1474,7 @@ 
   9 total queries in *s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   9
+  queries:                     993
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -1564,6 +1603,7 @@ 
   searching for changes
   elapsed time:  * seconds (glob)
   round-trips:                   1
+  queries:                       1
   heads summary:
     total common heads:          1
       also local heads:          1
@@ -1610,6 +1650,7 @@ 
   all remote heads known locally
   elapsed time:  * seconds (glob)
   round-trips:                   1
+  queries:                     260
   heads summary:
     total common heads:         25
       also local heads:         25
@@ -1655,6 +1696,7 @@ 
   3 total queries *s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   3
+  queries:                     109
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -1700,6 +1742,7 @@ 
   3 total queries in *s (glob)
   elapsed time:  * seconds (glob)
   round-trips:                   3
+  queries:                     109
   heads summary:
     total common heads:          1
       also local heads:          0
@@ -1757,6 +1800,7 @@ 
     "nb-revs-common": 300,
     "nb-revs-missing": 100,
     "output": "query 1; heads\nsearching for changes\ntaking quick initial sample\nquery 2; still undecided: 375, sample size is: 81\nsampling from both directions\nquery 3; still undecided: 3, sample size is: 3\n3 total queries in *s\n", (glob)
+    "total-queries": 109,
     "total-roundtrips": 3
    }
   ]
diff --git a/mercurial/treediscovery.py b/mercurial/treediscovery.py
--- a/mercurial/treediscovery.py
+++ b/mercurial/treediscovery.py
@@ -39,6 +39,7 @@ 
 
     if audit is not None:
         audit[b'total-roundtrips'] = 1
+        audit[b'total-queries'] = 0
 
     if repo.changelog.tip() == repo.nullid:
         base.add(repo.nullid)
@@ -69,6 +70,8 @@ 
     # head, root, first parent, second parent
     # (a branch always has two parents (or none) by definition)
     with remote.commandexecutor() as e:
+        if audit is not None:
+            audit[b'total-queries'] += len(unknown)
         branches = e.callcommand(b'branches', {b'nodes': unknown}).result()
 
     unknown = collections.deque(branches)
@@ -115,10 +118,13 @@ 
             )
             for p in pycompat.xrange(0, len(r), 10):
                 with remote.commandexecutor() as e:
+                    subset = r[p : p + 10]
+                    if audit is not None:
+                        audit[b'total-queries'] += len(subset)
                     branches = e.callcommand(
                         b'branches',
                         {
-                            b'nodes': r[p : p + 10],
+                            b'nodes': subset,
                         },
                     ).result()
 
@@ -135,6 +141,8 @@ 
         progress.increment()
 
         with remote.commandexecutor() as e:
+            if audit is not None:
+                audit[b'total-queries'] += len(search)
             between = e.callcommand(b'between', {b'pairs': search}).result()
 
         for n, l in zip(search, between):
diff --git a/mercurial/setdiscovery.py b/mercurial/setdiscovery.py
--- a/mercurial/setdiscovery.py
+++ b/mercurial/setdiscovery.py
@@ -298,6 +298,9 @@ 
 
     samplegrowth = float(ui.config(b'devel', b'discovery.grow-sample.rate'))
 
+    if audit is not None:
+        audit[b'total-queries'] = 0
+
     start = util.timer()
 
     roundtrips = 0
@@ -376,6 +379,8 @@ 
         roundtrips += 1
         with remote.commandexecutor() as e:
             fheads = e.callcommand(b'heads', {})
+            if audit is not None:
+                audit[b'total-queries'] += len(sample)
             fknown = e.callcommand(
                 b'known',
                 {
@@ -478,6 +483,8 @@ 
         sample = list(sample)
 
         with remote.commandexecutor() as e:
+            if audit is not None:
+                audit[b'total-queries'] += len(sample)
             yesno = e.callcommand(
                 b'known',
                 {
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -1221,6 +1221,7 @@ 
     # display discovery summary
     fm.plain(b"elapsed time:  %(elapsed)f seconds\n" % data)
     fm.plain(b"round-trips:           %(total-roundtrips)9d\n" % data)
+    fm.plain(b"queries:               %(total-queries)9d\n" % data)
     fm.plain(b"heads summary:\n")
     fm.plain(b"  total common heads:  %(nb-common-heads)9d\n" % data)
     fm.plain(b"    also local heads:  %(nb-common-heads-local)9d\n" % data)