* [PATCH 3/4] mbox: reduce small packets for gzipped mboxes
2016-06-25 0:45 5% [PATCH 0/4] http + mbox: tiny optimizations Eric Wong
@ 2016-06-25 0:45 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2016-06-25 0:45 UTC (permalink / raw)
To: meta
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
^ permalink raw reply related [relevance 7%]
* [PATCH 0/4] http + mbox: tiny optimizations
@ 2016-06-25 0:45 5% Eric Wong
2016-06-25 0:45 7% ` [PATCH 3/4] mbox: reduce small packets for gzipped mboxes Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2016-06-25 0:45 UTC (permalink / raw)
To: meta
For the gigantic $INBOX/all.mbox.gz response, this seems to slightly
improve speeds from roughly 290K/s to roughly 330K/s when fetching
out of a ~750MB aggressively-packed inbox.
Eric Wong (4):
http: always yield on getline/body
evcleanup: micro-optimize asap function
mbox: reduce small packets for gzipped mboxes
http: cork chunked responses for small savings
lib/PublicInbox/EvCleanup.pm | 42 +++++++++++++++++++++++++++++++++---------
lib/PublicInbox/HTTP.pm | 14 ++++++--------
lib/PublicInbox/Mbox.pm | 23 ++++++++++-------------
3 files changed, 49 insertions(+), 30 deletions(-)
^ permalink raw reply [relevance 5%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-06-25 0:45 5% [PATCH 0/4] http + mbox: tiny optimizations Eric Wong
2016-06-25 0:45 7% ` [PATCH 3/4] mbox: reduce small packets for gzipped mboxes Eric Wong
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).