comparison contrib/perf.py @ 30451:94ca0e13d1fc

perf: add command for measuring revlog chunk operations Upcoming commits will teach revlogs to leverage the new compression engine API so that new compression formats can more easily be leveraged in revlogs. We want to be sure this refactoring doesn't regress performance. So this commit introduces "perfrevchunks" to explicitly test performance of reading, decompressing, and recompressing revlog chunks. Here is output when run on the mozilla-unified repo: $ hg perfrevlogchunks -c ! read ! wall 0.346603 comb 0.350000 user 0.340000 sys 0.010000 (best of 28) ! read w/ reused fd ! wall 0.337707 comb 0.340000 user 0.320000 sys 0.020000 (best of 30) ! read batch ! wall 0.013206 comb 0.020000 user 0.000000 sys 0.020000 (best of 221) ! read batch w/ reused fd ! wall 0.013259 comb 0.030000 user 0.010000 sys 0.020000 (best of 222) ! chunk ! wall 1.909939 comb 1.910000 user 1.900000 sys 0.010000 (best of 6) ! chunk batch ! wall 1.750677 comb 1.760000 user 1.740000 sys 0.020000 (best of 6) ! compress ! wall 5.668004 comb 5.670000 user 5.670000 sys 0.000000 (best of 3) $ hg perfrevlogchunks -m ! read ! wall 0.365834 comb 0.370000 user 0.350000 sys 0.020000 (best of 26) ! read w/ reused fd ! wall 0.350160 comb 0.350000 user 0.320000 sys 0.030000 (best of 28) ! read batch ! wall 0.024777 comb 0.020000 user 0.000000 sys 0.020000 (best of 119) ! read batch w/ reused fd ! wall 0.024895 comb 0.030000 user 0.000000 sys 0.030000 (best of 118) ! chunk ! wall 2.514061 comb 2.520000 user 2.480000 sys 0.040000 (best of 4) ! chunk batch ! wall 2.380788 comb 2.380000 user 2.360000 sys 0.020000 (best of 5) ! compress ! wall 9.815297 comb 9.820000 user 9.820000 sys 0.000000 (best of 3) We already see some interesting data, such as how much slower non-batched chunk reading is and that zlib compression appears to be >2x slower than decompression. I didn't have the data when I wrote this commit message, but I ran this on Mozilla's NFS-based Mercurial server and the time for reading with a reused file descriptor was faster. So I think it is worth testing both with and without file descriptor reuse so we can make informed decisions about recycling file descriptors.
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 17 Nov 2016 20:17:51 -0800
parents 605e3b126d46
children be5b2098a817
comparison
equal deleted inserted replaced
30450:0acf3fd718f1 30451:94ca0e13d1fc
857 r.revision(r.node(x)) 857 r.revision(r.node(x))
858 858
859 timer(d) 859 timer(d)
860 fm.end() 860 fm.end()
861 861
862 @command('perfrevlogchunks', revlogopts + formatteropts +
863 [('s', 'startrev', 0, 'revision to start at')],
864 '-c|-m|FILE')
865 def perfrevlogchunks(ui, repo, file_=None, startrev=0, **opts):
866 """Benchmark operations on revlog chunks.
867
868 Logically, each revlog is a collection of fulltext revisions. However,
869 stored within each revlog are "chunks" of possibly compressed data. This
870 data needs to be read and decompressed or compressed and written.
871
872 This command measures the time it takes to read+decompress and recompress
873 chunks in a revlog. It effectively isolates I/O and compression performance.
874 For measurements of higher-level operations like resolving revisions,
875 see ``perfrevlog`` and ``perfrevlogrevision``.
876 """
877 rl = cmdutil.openrevlog(repo, 'perfrevlogchunks', file_, opts)
878 revs = list(rl.revs(startrev, len(rl) - 1))
879
880 def rlfh(rl):
881 if rl._inline:
882 return getsvfs(repo)(rl.indexfile)
883 else:
884 return getsvfs(repo)(rl.datafile)
885
886 def doread():
887 rl.clearcaches()
888 for rev in revs:
889 rl._chunkraw(rev, rev)
890
891 def doreadcachedfh():
892 rl.clearcaches()
893 fh = rlfh(rl)
894 for rev in revs:
895 rl._chunkraw(rev, rev, df=fh)
896
897 def doreadbatch():
898 rl.clearcaches()
899 rl._chunkraw(revs[0], revs[-1])
900
901 def doreadbatchcachedfh():
902 rl.clearcaches()
903 fh = rlfh(rl)
904 rl._chunkraw(revs[0], revs[-1], df=fh)
905
906 def dochunk():
907 rl.clearcaches()
908 fh = rlfh(rl)
909 for rev in revs:
910 rl._chunk(rev, df=fh)
911
912 chunks = [None]
913
914 def dochunkbatch():
915 rl.clearcaches()
916 fh = rlfh(rl)
917 # Save chunks as a side-effect.
918 chunks[0] = rl._chunks(revs, df=fh)
919
920 def docompress():
921 rl.clearcaches()
922 for chunk in chunks[0]:
923 rl.compress(chunk)
924
925 benches = [
926 (lambda: doread(), 'read'),
927 (lambda: doreadcachedfh(), 'read w/ reused fd'),
928 (lambda: doreadbatch(), 'read batch'),
929 (lambda: doreadbatchcachedfh(), 'read batch w/ reused fd'),
930 (lambda: dochunk(), 'chunk'),
931 (lambda: dochunkbatch(), 'chunk batch'),
932 (lambda: docompress(), 'compress'),
933 ]
934
935 for fn, title in benches:
936 timer, fm = gettimer(ui, opts)
937 timer(fn, title=title)
938 fm.end()
939
862 @command('perfrevlogrevision', revlogopts + formatteropts + 940 @command('perfrevlogrevision', revlogopts + formatteropts +
863 [('', 'cache', False, 'use caches instead of clearing')], 941 [('', 'cache', False, 'use caches instead of clearing')],
864 '-c|-m|FILE REV') 942 '-c|-m|FILE REV')
865 def perfrevlogrevision(ui, repo, file_, rev=None, cache=None, **opts): 943 def perfrevlogrevision(ui, repo, file_, rev=None, cache=None, **opts):
866 """Benchmark obtaining a revlog revision. 944 """Benchmark obtaining a revlog revision.