From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id BED6D1F461 for ; Sun, 14 Jul 2019 02:56:36 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] nntpdeflate: reduce overhead of idle clients Date: Sun, 14 Jul 2019 02:56:36 +0000 Message-Id: <20190714025636.16879-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We don't need to keep an empty buffer around in the common case when a client is sending us completely inflatable requests and we're able to read them in one go. This only seems to save about 2M with 10K NNTPS clients using COMPRESS, so it's not a huge win, but better than nothing. --- lib/PublicInbox/NNTPdeflate.pm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/PublicInbox/NNTPdeflate.pm b/lib/PublicInbox/NNTPdeflate.pm index f2de0f38..c143488f 100644 --- a/lib/PublicInbox/NNTPdeflate.pm +++ b/lib/PublicInbox/NNTPdeflate.pm @@ -56,7 +56,7 @@ sub enable { unlock_hash(%$self); $self->res('206 Compression active'); bless $self, $class; - $self->{zin} = [ $in, '' ]; + $self->{zin} = $in; } # overrides PublicInbox::NNTP::compressed @@ -67,13 +67,16 @@ sub do_read ($$$$) { my ($self, $rbuf, $len, $off) = @_; my $zin = $self->{zin} or return; # closed - my $deflated = \($zin->[1]); - my $r = PublicInbox::DS::do_read($self, $deflated, $len) or return; + my $doff; + my $dbuf = delete($self->{dbuf}) // ''; + $doff = length($dbuf); + my $r = PublicInbox::DS::do_read($self, \$dbuf, $len, $doff) or return; # assert(length($$rbuf) == $off) as far as NNTP.pm is concerned - # -ConsumeInput is true, so $deflated is automatically emptied - my $err = $zin->[0]->inflate($deflated, $rbuf); + # -ConsumeInput is true, so $dbuf is automatically emptied + my $err = $zin->inflate($dbuf, $rbuf); if ($err == Z_OK) { + $self->{dbuf} = $dbuf if $dbuf ne ''; $r = length($$rbuf) and return $r; # nothing ready, yet, get more, later $self->requeue; -- EW