From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/4] mbox: reduce small packets for gzipped mboxes
Date: Sat, 25 Jun 2016 00:45:32 +0000 [thread overview]
Message-ID: <20160625004533.5061-4-e@80x24.org> (raw)
In-Reply-To: <20160625004533.5061-1-e@80x24.org>
We want to avoid sending 10 or 20-byte gzip headers as
separate TCP packets to reduce syscalls and avoid wasting
bandwidth.
---
lib/PublicInbox/Mbox.pm | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index 63ec605..1c97f95 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -110,7 +110,7 @@ use warnings;
sub new {
my ($class, $ctx, $cb) = @_;
- my $buf;
+ my $buf = '';
bless {
buf => \$buf,
gz => IO::Compress::Gzip->new(\$buf, Time => 0),
@@ -121,19 +121,11 @@ sub new {
}, $class;
}
-sub _flush_buf {
- my ($self) = @_;
- my $ret = $self->{buf};
- $ret = $$ret;
- ${$self->{buf}} = undef;
- $ret;
-}
-
# called by Plack::Util::foreach or similar
sub getline {
my ($self) = @_;
+ my $ctx = $self->{ctx} or return;
my $res;
- my $ctx = $self->{ctx};
my $ibx = $ctx->{-inbox};
my $gz = $self->{gz};
do {
@@ -141,8 +133,12 @@ sub getline {
my $msg = eval { $ibx->msg_by_mid($smsg->mid) } or next;
$msg = Email::Simple->new($msg);
$gz->write(PublicInbox::Mbox::msg_str($ctx, $msg));
- my $ret = _flush_buf($self);
- return $ret if $ret;
+ my $bref = $self->{buf};
+ if (length($$bref) >= 8192) {
+ my $ret = $$bref; # copy :<
+ ${$self->{buf}} = '';
+ return $ret;
+ }
}
$res = $self->{cb}->($self->{opts});
$self->{msgs} = $res->{msgs};
@@ -150,7 +146,8 @@ sub getline {
$self->{opts}->{offset} += $res;
} while ($res);
$gz->close;
- _flush_buf($self);
+ delete $self->{ctx};
+ ${delete $self->{buf}};
}
sub close {} # noop
next prev parent reply other threads:[~2016-06-25 0:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-25 0:45 [PATCH 0/4] http + mbox: tiny optimizations Eric Wong
2016-06-25 0:45 ` [PATCH 1/4] http: always yield on getline/body Eric Wong
2016-06-25 0:45 ` [PATCH 2/4] evcleanup: micro-optimize asap function Eric Wong
2016-06-25 0:45 ` Eric Wong [this message]
2016-06-25 0:45 ` [PATCH 4/4] http: cork chunked responses for small savings Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160625004533.5061-4-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).