diff options
author | Eric Wong <e@80x24.org> | 2019-11-29 12:25:05 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2019-12-12 03:51:14 +0000 |
commit | 46baf956987dca495ed44b1050e64939fae5c8ab (patch) | |
tree | 5ec1167e3db591de27a108f314ce8fdda8ad921b /xt/git_async_cmp.t | |
parent | 73fe3421f1ecbdc83600d5acfc643c33dbb9a0f2 (diff) | |
download | public-inbox-46baf956987dca495ed44b1050e64939fae5c8ab.tar.gz |
This is a transitionary interface which does NOT require an event loop. It can be plugged into in current synchronous code without major surgery. It allows HTTP/1.1 pipelining-like functionality by taking advantage of predictable and well-specified POSIX pipe semantics by stuffing multiple git cat-file requests into the --batch pipe With xt/git_async_cmp.t and GIANT_GIT_DIR=git.git, the async interface is 10-25% faster than the synchronous interface since it can keep the "git cat-file" process busier. This is expected to improve performance on systems with slower storage (but multiple cores).
Diffstat (limited to 'xt/git_async_cmp.t')
-rw-r--r-- | xt/git_async_cmp.t | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/xt/git_async_cmp.t b/xt/git_async_cmp.t new file mode 100644 index 00000000..f8ffe3d9 --- /dev/null +++ b/xt/git_async_cmp.t @@ -0,0 +1,61 @@ +#!perl -w +# Copyright (C) 2019 all contributors <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> +use strict; +use Test::More; +use Benchmark qw(:all); +use Digest::SHA; +use PublicInbox::TestCommon; +my $git_dir = $ENV{GIANT_GIT_DIR}; +plan 'skip_all' => "GIANT_GIT_DIR not defined for $0" unless defined($git_dir); +use_ok 'PublicInbox::Git'; +my $git = PublicInbox::Git->new($git_dir); +my @cat = qw(cat-file --buffer --batch-check --batch-all-objects); +if (require_git(2.19, 1)) { + push @cat, '--unordered'; +} else { + warn "git <2.19, cat-file lacks --unordered, locality suffers\n"; +} +my @dig; +my $nr = $ENV{NR} || 1; +my $async = timeit($nr, sub { + my $dig = Digest::SHA->new(1); + my $cb = sub { + my ($bref) = @_; + $dig->add($$bref); + }; + my $cat = $git->popen(@cat); + $git->cat_async_begin; + + foreach (<$cat>) { + my ($oid, undef, undef) = split(/ /); + $git->cat_async($oid, $cb); + } + close $cat or die "cat: $?"; + $git->cat_async_wait; + push @dig, ['async', $dig->hexdigest ]; +}); + +my $sync = timeit($nr, sub { + my $dig = Digest::SHA->new(1); + my $cat = $git->popen(@cat); + foreach (<$cat>) { + my ($oid, undef, undef) = split(/ /); + my $bref = $git->cat_file($oid); + $dig->add($$bref); + } + close $cat or die "cat: $?"; + push @dig, ['sync', $dig->hexdigest ]; +}); + +ok(scalar(@dig) >= 2, 'got some digests'); +my $ref = shift @dig; +my $exp = $ref->[1]; +isnt($exp, Digest::SHA->new(1)->hexdigest, 'not empty'); +foreach (@dig) { + is($_->[1], $exp, "digest matches $_->[0] <=> $ref->[0]"); +} +diag "sync=".timestr($sync); +diag "async=".timestr($async); +done_testing; +1; |