]> Sergey Matveev's repositories - public-inbox.git/blob - xt/perf-msgview.t
No ext_urls
[public-inbox.git] / xt / perf-msgview.t
1 #!perl -w
2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use v5.10.1;
6 use PublicInbox::TestCommon;
7 use Benchmark qw(:all);
8 use PublicInbox::Inbox;
9 use PublicInbox::View;
10 use PublicInbox::WwwStream;
11
12 my $inboxdir = $ENV{GIANT_INBOX_DIR} // $ENV{GIANT_PI_DIR};
13 my $blob = $ENV{TEST_BLOB};
14 my $obfuscate = $ENV{PI_OBFUSCATE} ? 1 : 0;
15 diag "PI_OBFUSCATE=$obfuscate";
16 plan skip_all => "GIANT_INBOX_DIR not defined for $0" unless $inboxdir;
17
18 my @cat = qw(cat-file --buffer --batch-check --batch-all-objects);
19 if (require_git(2.19, 1)) {
20         push @cat, '--unordered';
21 } else {
22         warn
23 "git <2.19, cat-file lacks --unordered, locality suffers\n";
24 }
25 require_mods qw(Plack::Util);
26 my $ibx = PublicInbox::Inbox->new({ inboxdir => $inboxdir, name => 'name',
27                                     obfuscate => $obfuscate});
28 my $git = $ibx->git;
29 my $fh = $blob ? undef : $git->popen(@cat);
30 if ($fh) {
31         my $vec = '';
32         vec($vec, fileno($fh), 1) = 1;
33         select($vec, undef, undef, 60) or
34                 die "timed out waiting for --batch-check";
35 }
36
37 my $ctx = bless {
38         env => { HTTP_HOST => 'example.com', 'psgi.url_scheme' => 'https' },
39         ibx => $ibx,
40         www => Plack::Util::inline_object(style => sub {''}),
41         gz => PublicInbox::GzipFilter::gzip_or_die(),
42 }, 'PublicInbox::WwwStream';
43 my ($eml, $res, $oid, $type);
44 my $n = 0;
45 my $m = 0;
46 ${$ctx->{obuf}} = '';
47 $ctx->{mhref} = '../';
48
49 my $cb = sub {
50         $eml = PublicInbox::Eml->new(shift);
51         $eml->each_part(\&PublicInbox::View::add_text_body, $ctx, 1);
52         $ctx->zflush(grep defined, delete @$ctx{'obuf'}); # compat
53         ++$m;
54         delete $ctx->{zbuf};
55         ${$ctx->{obuf}} = ''; # compat
56         $ctx->{gz} = PublicInbox::GzipFilter::gzip_or_die();
57 };
58
59 my $t = timeit(1, sub {
60         if (defined $blob) {
61                 my $nr = $ENV{NR} // 10000;
62                 for (1..$nr) {
63                         ++$n;
64                         $git->cat_async($blob, $cb);
65                 }
66         } else {
67                 while (<$fh>) {
68                         ($oid, $type) = split / /;
69                         next if $type ne 'blob';
70                         ++$n;
71                         $git->cat_async($oid, $cb);
72                 }
73         }
74         $git->async_wait_all;
75 });
76 diag 'add_text_body took '.timestr($t)." for $n <=> $m messages";
77 is($m, $n, 'rendered all messages');
78 done_testing();