user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 2/1] http: constrain getline/close responses by time
  @ 2016-06-19  7:12  7% ` Eric Wong
  0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2016-06-19  7:12 UTC (permalink / raw)
  To: meta

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;
 			}

^ permalink raw reply related	[relevance 7%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-06-19  6:32     [PATCH] http: avoid recursion when hitting write count limit Eric Wong
2016-06-19  7:12  7% ` [PATCH 2/1] http: constrain getline/close responses by time 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).