2 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 use PublicInbox::TestCommon;
7 use PublicInbox::Inbox;
8 use List::Util qw(max);
9 use Benchmark qw(:all :hireswallclock);
10 use PublicInbox::Spawn qw(popen_rd);
12 require_git(2.19); # for --unordered
13 require_mods(qw(BSD::Resource));
14 BSD::Resource->import(qw(getrusage));
15 my $cls = $ENV{TEST_CLASS};
17 diag "TEST_CLASS=$cls";
20 $cls //= 'PublicInbox::Eml';
21 my $inboxdir = $ENV{GIANT_INBOX_DIR};
22 plan skip_all => "GIANT_INBOX_DIR not defined for $0" unless $inboxdir;
23 local $PublicInbox::Eml::mime_nesting_limit = 0x7fffffff;
24 local $PublicInbox::Eml::mime_parts_limit = 0x7fffffff;
25 local $PublicInbox::Eml::header_size_limit = 0x7fffffff;
26 my $ibx = PublicInbox::Inbox->new({ inboxdir => $inboxdir, name => 'x' });
28 my @cat = qw(cat-file --buffer --batch-check --batch-all-objects --unordered);
29 my $fh = $git->popen(@cat);
31 my $max_nest = [ 0, '' ]; # [ bytes, blob oid ]
32 my $max_idx = [ 0, '' ];
33 my $max_parts = [ 0, '' ];
34 my $max_size = [ 0, '' ];
35 my $max_hdr = [ 0, '' ];
37 my $each_part_cb = sub {
39 my ($part, $depth, $idx) = @$p;
40 $max_nest = [ $depth, $info->[1] ] if $depth > $max_nest->[0];
41 my $max = max(split(/\./, $idx));
42 $max_idx = [ $max, $info->[1] ] if $max > $max_idx->[0];
46 my ($bref, $oid, $size);
47 local $SIG{__WARN__} = sub { diag "$inboxdir $oid ", @_ };
49 ($bref, $oid, undef, $size) = @_;
52 my $eml = $cls->new($bref);
53 my $hdr_len = length($eml->header_obj->as_string);
54 $max_hdr = [ $hdr_len, $oid ] if $hdr_len > $max_hdr->[0];
55 $eml->each_part($each_part_cb, $info, 1);
56 $max_parts = $info if $info->[0] > $max_parts->[0];
57 $max_size = [ $size, $oid ] if $size > $max_size->[0];
60 my $t = timeit(1, sub {
63 ($blob, $type) = split / /;
64 next if $type ne 'blob';
66 $git->cat_async($blob, $cat_cb);
70 is($m, $n, 'scanned all messages');
71 diag "$$ $inboxdir took ".timestr($t)." for $n <=> $m messages";
72 diag "$$ max_nest $max_nest->[0] @ $max_nest->[1]";
73 diag "$$ max_idx $max_idx->[0] @ $max_idx->[1]";
74 diag "$$ max_parts $max_parts->[0] @ $max_parts->[1]";
75 diag "$$ max_size $max_size->[0] @ $max_size->[1]";
76 diag "$$ max_hdr $max_hdr->[0] @ $max_hdr->[1]";
77 diag "$$ RSS ".getrusage()->maxrss. ' k';