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