Mercurial > public > mercurial-scm > hg
comparison mercurial/bundle2.py @ 35116:da91e7309daf
bundle2: don't use seekable bundle2 parts by default (issue5691)
The last commit removed the last use of the bundle2 part seek() API
in the generic bundle2 part iteration code. This means we can now
switch to using unseekable bundle2 parts by default and have the
special consumers that actually need the behavior request it.
This commit changes unbundle20.iterparts() to expose non-seekable
unbundlepart instances by default. If seekable parts are needed,
callers can pass "seekable=True." The bundlerepo class needs
seekable parts, so it does this.
The interrupt handler is also changed to use a regular unbundlepart.
So, by default, all consumers except bundlerepo will see unseekable
parts.
Because the behavior of the iterparts() benchmark changed, we add
a variation to test seekable parts vs unseekable parts. And because
parts no longer have seek() unless "seekable=True," we update the
"part seek" benchmark.
Speaking of benchmarks, this change has the following impact to
`hg perfbundleread` on an uncompressed bundle of the Firefox repo
(6,070,036,163 bytes):
! read(8k)
! wall 0.722709 comb 0.720000 user 0.150000 sys 0.570000 (best of 14)
! read(16k)
! wall 0.602208 comb 0.590000 user 0.080000 sys 0.510000 (best of 17)
! read(32k)
! wall 0.554018 comb 0.560000 user 0.050000 sys 0.510000 (best of 18)
! read(128k)
! wall 0.520086 comb 0.530000 user 0.020000 sys 0.510000 (best of 20)
! bundle2 forwardchunks()
! wall 2.996329 comb 3.000000 user 2.300000 sys 0.700000 (best of 4)
! bundle2 iterparts()
! wall 8.070791 comb 8.060000 user 7.180000 sys 0.880000 (best of 3)
! wall 6.983756 comb 6.980000 user 6.220000 sys 0.760000 (best of 3)
! bundle2 iterparts() seekable
! wall 8.132131 comb 8.110000 user 7.160000 sys 0.950000 (best of 3)
! bundle2 part seek()
! wall 10.370142 comb 10.350000 user 7.430000 sys 2.920000 (best of 3)
! wall 10.860942 comb 10.840000 user 7.790000 sys 3.050000 (best of 3)
! bundle2 part read(8k)
! wall 8.599892 comb 8.580000 user 7.720000 sys 0.860000 (best of 3)
! wall 7.258035 comb 7.260000 user 6.470000 sys 0.790000 (best of 3)
! bundle2 part read(16k)
! wall 8.265361 comb 8.250000 user 7.360000 sys 0.890000 (best of 3)
! wall 7.099891 comb 7.080000 user 6.310000 sys 0.770000 (best of 3)
! bundle2 part read(32k)
! wall 8.290308 comb 8.280000 user 7.330000 sys 0.950000 (best of 3)
! wall 6.964685 comb 6.950000 user 6.130000 sys 0.820000 (best of 3)
! bundle2 part read(128k)
! wall 8.204900 comb 8.150000 user 7.210000 sys 0.940000 (best of 3)
! wall 6.852867 comb 6.850000 user 6.060000 sys 0.790000 (best of 3)
The significant speedup is due to not incurring the overhead to track
payload offset data. Of course, this overhead is proportional to
bundle2 part size. So a multiple gigabyte changegroup part is on the
extreme side of the spectrum for real-world impact.
In addition to the CPU efficiency wins, not tracking offset data
also means not using memory to hold that data. Using a bundle based on
the example BSD repository in issue 5691, this change has a drastic
impact to memory usage during `hg unbundle` (`hg clone` would behave
similarly). Before, memory usage incrementally increased for the
duration of bundle processing. In other words, as we advanced through
the changegroup and bundle2 part, we kept allocating more memory to
hold offset data. After this change, we still increase memory during
changegroup application. But the rate of increase is significantly
slower. (A bulk of the remaining gradual increase appears to be the
storing of revlog sizes in the transaction object to facilitate
rollback.)
The RSS at the end of filelog application is as follows:
Before: ~752 MB
After: ~567 MB
So, we were storing ~185 MB of offset data that we never even used.
Talk about wasteful!
.. api::
bundle2 parts are no longer seekable by default.
.. perf::
bundle2 read I/O throughput significantly increased.
.. perf::
Significant memory use reductions when reading from bundle2 bundles.
On the BSD repository, peak RSS during changegroup application
decreased by ~185 MB from ~752 MB to ~567 MB.
Differential Revision: https://phab.mercurial-scm.org/D1390
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 13 Nov 2017 21:10:37 -0800 |
parents | 2b72bc88043f |
children | 589eed45a452 |
comparison
equal
deleted
inserted
replaced
35115:2b72bc88043f | 35116:da91e7309daf |
---|---|
843 elif size < 0: | 843 elif size < 0: |
844 raise error.BundleValueError('negative chunk size: %i') | 844 raise error.BundleValueError('negative chunk size: %i') |
845 yield self._readexact(size) | 845 yield self._readexact(size) |
846 | 846 |
847 | 847 |
848 def iterparts(self): | 848 def iterparts(self, seekable=False): |
849 """yield all parts contained in the stream""" | 849 """yield all parts contained in the stream""" |
850 cls = seekableunbundlepart if seekable else unbundlepart | |
850 # make sure param have been loaded | 851 # make sure param have been loaded |
851 self.params | 852 self.params |
852 # From there, payload need to be decompressed | 853 # From there, payload need to be decompressed |
853 self._fp = self._compengine.decompressorreader(self._fp) | 854 self._fp = self._compengine.decompressorreader(self._fp) |
854 indebug(self.ui, 'start extraction of bundle2 parts') | 855 indebug(self.ui, 'start extraction of bundle2 parts') |
855 headerblock = self._readpartheader() | 856 headerblock = self._readpartheader() |
856 while headerblock is not None: | 857 while headerblock is not None: |
857 part = seekableunbundlepart(self.ui, headerblock, self._fp) | 858 part = cls(self.ui, headerblock, self._fp) |
858 yield part | 859 yield part |
859 # Ensure part is fully consumed so we can start reading the next | 860 # Ensure part is fully consumed so we can start reading the next |
860 # part. | 861 # part. |
861 part.consume() | 862 part.consume() |
862 | 863 |
1152 indebug(self.ui, 'bundle2 stream interruption, looking for a part.') | 1153 indebug(self.ui, 'bundle2 stream interruption, looking for a part.') |
1153 headerblock = self._readpartheader() | 1154 headerblock = self._readpartheader() |
1154 if headerblock is None: | 1155 if headerblock is None: |
1155 indebug(self.ui, 'no part found during interruption.') | 1156 indebug(self.ui, 'no part found during interruption.') |
1156 return | 1157 return |
1157 part = seekableunbundlepart(self.ui, headerblock, self._fp) | 1158 part = unbundlepart(self.ui, headerblock, self._fp) |
1158 op = interruptoperation(self.ui) | 1159 op = interruptoperation(self.ui) |
1159 hardabort = False | 1160 hardabort = False |
1160 try: | 1161 try: |
1161 _processpart(op, part) | 1162 _processpart(op, part) |
1162 except (SystemExit, KeyboardInterrupt): | 1163 except (SystemExit, KeyboardInterrupt): |