From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/1] http: constrain getline/close responses by time
Date: Sun, 19 Jun 2016 07:12:49 +0000 [thread overview]
Message-ID: <20160619071249.GA17405@dcvr.yhbt.net> (raw)
In-Reply-To: <20160619063241.27195-1-e@80x24.org>
This allows us to yield control to other clients gracefully if
getline takes too long to generate a chunk. This is more
expensive but should not cost a syscall on modern 64-bit systems.
---
lib/PublicInbox/HTTP.pm | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index e0ed2d1..800b240 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -16,6 +16,7 @@ use Fcntl qw(:seek);
use Plack::HTTPParser qw(parse_http_request); # XS or pure Perl
use HTTP::Status qw(status_message);
use HTTP::Date qw(time2str);
+use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC);
use Scalar::Util qw(weaken);
use IO::File;
use constant {
@@ -25,6 +26,8 @@ use constant {
CHUNK_MAX_HDR => 256,
};
+sub now () { clock_gettime(CLOCK_MONOTONIC) }
+
# FIXME: duplicated code with NNTP.pm, layering violation
my $WEAKEN = {}; # string(inbox) -> inbox
my $weakt;
@@ -267,14 +270,14 @@ sub getline_response {
my $forward = $self->{forward};
# limit our own running time for fairness with other
# clients and to avoid buffering too much:
- my $n = 100;
+ my $end = now() + 0.1;
while ($forward && defined(my $buf = $forward->getline)) {
$write->($buf);
last if $self->{closed};
if ($self->{write_buf_size}) {
$self->write($self->{pull});
return;
- } elsif ((--$n) <= 0) {
+ } elsif (now() > $end) {
PublicInbox::EvCleanup::asap($self->{pull});
return;
}
prev parent reply other threads:[~2016-06-19 7:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-19 6:32 [PATCH] http: avoid recursion when hitting write count limit Eric Wong
2016-06-19 7:12 ` Eric Wong [this message]
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=20160619071249.GA17405@dcvr.yhbt.net \
--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).