user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [RFC] nntp: improve fairness during XOVER and similar commands
Date: Wed,  7 Mar 2018 09:52:22 +0000	[thread overview]
Message-ID: <20180307095222.18699-1-e@80x24.org> (raw)

For other commands generating long responses, we generally want
to yield to another client after emitting 100 .  However,
XOVER-based responses already query 200 lines worth of responses
at a time, so we were sending 20000 lines before yielding to
other clients.  This may help avoid timeouts for some clients.
---
 lib/PublicInbox/NNTP.pm | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index 56d8e01..1e56463 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -590,9 +590,10 @@ sub long_response ($$$$) {
 
 		my $err;
 		do {
-			eval { $cb->(\$beg) };
+			eval { $cb->(\$beg, \$lim) };
 		} until (($err = $@) || $self->{closed} ||
-			 ++$beg > $end || !--$lim || $self->{write_buf_size});
+			 ++$beg > $end || --$lim < 0 ||
+			 $self->{write_buf_size});
 
 		if ($err || $self->{closed}) {
 			$self->{long_res} = undef;
@@ -609,7 +610,7 @@ sub long_response ($$$$) {
 				update_idle_time($self);
 				$self->watch_read(1);
 			}
-		} elsif (!$lim || $self->{write_buf_size}) {
+		} elsif ($lim < 0 || $self->{write_buf_size}) {
 			# no recursion, schedule another call ASAP
 			# but only after all pending writes are done
 			update_idle_time($self);
@@ -715,11 +716,12 @@ sub hdr_searchmsg ($$$$) {
 		more($self, $xhdr ? r221 : r225);
 		my $off = 0;
 		long_response($self, $beg, $end, sub {
-			my ($i) = @_;
+			my ($i, $lim) = @_;
 			my $res = $srch->query_xover($beg, $end, $off);
 			my $msgs = $res->{msgs};
 			my $nr = scalar @$msgs or return;
 			$off += $nr;
+			$$lim -= $nr;
 			my $tmp = '';
 			foreach my $s (@$msgs) {
 				$tmp .= $s->num . ' ' . $s->$field . "\r\n";
@@ -853,11 +855,12 @@ sub cmd_xover ($;$) {
 	my $srch = $self->{ng}->search;
 	my $off = 0;
 	long_response($self, $beg, $end, sub {
-		my ($i) = @_;
+		my ($i, $lim) = @_;
 		my $res = $srch->query_xover($beg, $end, $off);
 		my $msgs = $res->{msgs};
 		my $nr = scalar @$msgs or return;
 		$off += $nr;
+		$$lim -= $nr;
 
 		# OVERVIEW.FMT
 		more($self, join("\r\n", map {
-- 
EW


                 reply	other threads:[~2018-03-07  9:52 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=20180307095222.18699-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).