From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] http: yield body->getline running time
Date: Mon, 30 May 2016 04:54:07 +0000 [thread overview]
Message-ID: <20160530045407.22267-1-e@80x24.org> (raw)
We cannot let a client monopolize the single-threaded server
even if it can drain the socket buffer faster than we can
emit data.
While we're at it, acknowledge the this behavior (which happens
naturally) in httpd/async.
The same idea is present in NNTP for the long_response code.
This is the HTTP followup to:
commit 0d0fde0bff97 ("nntp: introduce long response API for streaming")
commit 79d8bfedcdd2 ("nntp: avoid signals for long responses")
---
lib/PublicInbox/HTTP.pm | 5 ++++-
lib/PublicInbox/HTTPD/Async.pm | 4 +++-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index fcbd758..6df1c3f 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -265,10 +265,13 @@ sub getline_response {
my $pull = $self->{pull} = sub {
local $/ = \8192;
my $forward = $self->{forward};
+ # limit our own running time for fairness with other
+ # clients and to avoid buffering too much:
+ my $n = 100;
while ($forward && defined(my $buf = $forward->getline)) {
$write->($buf);
last if $self->{closed};
- if ($self->{write_buf_size}) {
+ if ((--$n) <= 0 || $self->{write_buf_size}) {
$self->write($self->{pull});
return;
}
diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm
index add07ce..fadf2d3 100644
--- a/lib/PublicInbox/HTTPD/Async.pm
+++ b/lib/PublicInbox/HTTPD/Async.pm
@@ -45,7 +45,9 @@ sub async_pass {
$self->watch_read(0);
$io->write($restart_read); # D::S::write
}
- return; # stay in watch_read
+ # stay in watch_read, but let other clients
+ # get some work done, too.
+ return;
} elsif (!defined $r) {
return if $!{EAGAIN} || $!{EINTR};
}
reply other threads:[~2016-05-30 4:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20160530045407.22267-1-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).