diff options
author | Eric Wong <e@80x24.org> | 2020-01-05 09:51:16 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2020-01-05 23:32:29 +0000 |
commit | 033f628b52ebacf4a7bf8795084ba5ec498004bf (patch) | |
tree | df9a472915b9f1232b60921e0226d77842fc1055 /xt | |
parent | e3e8cab265fe79e4984d59ee180f2dbc8d4ef6f1 (diff) | |
download | public-inbox-033f628b52ebacf4a7bf8795084ba5ec498004bf.tar.gz |
In rare cases where Message-IDs get reused, we do not want to hold onto the large Email::MIME objects in memory after showing the first message. So discard each message as soon as we're done using it so we can save memory for the next message. The new and expensive xt/mem-msgview.t test shows a nearly 14MB reduction for two ~7MB messages. run_script() also gets upgraded to make it easier to pass large inputs via IO GLOBs.
Diffstat (limited to 'xt')
-rw-r--r-- | xt/mem-msgview.t | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/xt/mem-msgview.t b/xt/mem-msgview.t new file mode 100644 index 00000000..1ea0f559 --- /dev/null +++ b/xt/mem-msgview.t @@ -0,0 +1,80 @@ +#!perl -w +# Copyright (C) 2020 all contributors <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> +use strict; +use IO::Handle; # ->flush +use Fcntl qw(SEEK_SET); +use PublicInbox::TestCommon; +use PublicInbox::Tmpfile; +use PublicInbox::WWW; +use Test::More; +my @mods = qw(DBD::SQLite BSD::Resource); +require_mods(@mods); +use_ok($_) for @mods; +my $lines = $ENV{NR_LINES} // 100000; +my ($tmpdir, $for_destroy) = tmpdir(); +my $inboxname = 'big'; +my $inboxdir = "$tmpdir/big"; +local $ENV{PI_CONFIG} = "$tmpdir/cfg"; +my $mid = 'test@example.com'; + +{ # setup + open my $fh, '>', "$tmpdir/cfg" or die; + print $fh <<EOF or die; +[publicinboxmda] + spamcheck = none +EOF + close $fh or die; + + my $addr = 'n@example.com'; + ok(run_script([qw(-init -V2 --indexlevel=basic), $inboxname, $inboxdir, + "http://example.com/$inboxname", $addr]), + 'inbox initialized'); + + $fh = tmpfile('big.eml', undef, my $append = 1) or die; + printf($fh <<'EOF', $addr, $mid) or die; +From: Dr. X <x@example.com> +To: Nikki <%s> +Date: Tue, 3 May 1988 00:00:00 +0000 +Subject: todo +Message-ID: <%s> + +EOF + for (0..$lines) { print $fh 'x' x 72, "\n" or die } + $fh->flush or die; + sysseek($fh, 0, SEEK_SET) or die; + my $env = { ORIGINAL_RECIPIENT => $addr }; + my $err = ''; + my $opt = { 0 => $fh, 2 => \$err, run_mode => 0 }; + ok(run_script([qw(-mda --no-precheck)], $env, $opt), + '1st message delivered'); + + # resend the message with same mid but different content + print $fh "mindcrime\n" or die; + $fh->flush or die; + sysseek($fh, 0, SEEK_SET) or die; + ok(run_script([qw(-mda --no-precheck)], $env, $opt), + '2nd message delivered'); +} + +my $www = PublicInbox::WWW->new; +my $env = { + PATH_INFO => "/$inboxname/$mid/", + REQUEST_URI => "/$inboxname/$mid/", + SCRIPT_NAME => '', + QUERY_STRING => '', + REQUEST_METHOD => 'GET', + HTTP_HOST => 'example.com', + 'psgi.errors' => \*STDERR, + 'psgi.url_scheme' => 'http', +}; +my $ru_before = BSD::Resource::getrusage(); +my $res = $www->call($env); +my $body = $res->[2]; +while (defined(my $x = $body->getline)) { +} +$body->close; +my $ru_after = BSD::Resource::getrusage(); +my $diff = $ru_after->maxrss - $ru_before->maxrss; +diag "before: ${\$ru_before->maxrss} => ${\$ru_after->maxrss} diff=$diff kB"; +done_testing(); |